Browse Source

Fixed loading of assemblies that contain generic types with more than 10 type parameters.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4012 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
f259855abb
  1. 12
      src/Main/Base/Test/GetElementByReflectionNameTests.cs
  2. 3
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CecilReader.cs
  3. 7
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs
  4. 15
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs
  5. 2
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/DomPersistence.cs
  6. 19
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionClass.cs
  7. 15
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionReturnType.cs

12
src/Main/Base/Test/GetElementByReflectionNameTests.cs

@ -6,10 +6,12 @@
// </file> // </file>
using System; using System;
using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using NUnit.Framework;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
namespace ICSharpCode.SharpDevelop.Tests namespace ICSharpCode.SharpDevelop.Tests
{ {
@ -29,11 +31,17 @@ namespace ICSharpCode.SharpDevelop.Tests
public void TestClasses() public void TestClasses()
{ {
TestClass(typeof(object)); TestClass(typeof(object));
TestClass(typeof(Environment.SpecialFolder));
TestClass(typeof(Nullable)); TestClass(typeof(Nullable));
TestClass(typeof(Nullable<>)); TestClass(typeof(Nullable<>));
} }
[Test]
public void TestNestedClass()
{
TestClass(typeof(Environment.SpecialFolder));
TestClass(typeof(Dictionary<,>.ValueCollection));
}
void TestMember(string className, string memberName) void TestMember(string className, string memberName)
{ {
IClass c = mscorlib.GetClassByReflectionName(className, false); IClass c = mscorlib.GetClassByReflectionName(className, false);

3
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CecilReader.cs

@ -162,8 +162,7 @@ namespace ICSharpCode.SharpDevelop.Dom
string name = td.FullName; string name = td.FullName;
if (name.Length == 0 || name[0] == '<') if (name.Length == 0 || name[0] == '<')
continue; continue;
if (name.Length > 2 && name[name.Length - 2] == '`') name = ReflectionClass.SplitTypeParameterCountFromReflectionName(name);
name = name.Substring(0, name.Length - 2);
AddClassToNamespaceListInternal(new CecilClass(this.AssemblyCompilationUnit, null, td, name)); AddClassToNamespaceListInternal(new CecilClass(this.AssemblyCompilationUnit, null, td, name));
} }
} }

7
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/DefaultClass.cs

@ -264,16 +264,17 @@ namespace ICSharpCode.SharpDevelop.Dom
public override string DotNetName { public override string DotNetName {
get { get {
string fullName; string fullName;
int typeParametersCount = this.TypeParameters.Count;
if (this.DeclaringType != null) { if (this.DeclaringType != null) {
fullName = this.DeclaringType.DotNetName + "+" + this.Name; fullName = this.DeclaringType.DotNetName + "+" + this.Name;
typeParametersCount -= this.DeclaringType.TypeParameters.Count;
} else { } else {
fullName = this.FullyQualifiedName; fullName = this.FullyQualifiedName;
} }
IList<ITypeParameter> typeParameters = this.TypeParameters; if (typeParametersCount == 0) {
if (typeParameters == null || typeParameters.Count == 0) {
return fullName; return fullName;
} else { } else {
return fullName + "`" + typeParameters.Count; return fullName + "`" + typeParametersCount;
} }
} }
} }

15
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

@ -867,15 +867,12 @@ namespace ICSharpCode.SharpDevelop.Dom
{ {
if (className == null) if (className == null)
throw new ArgumentNullException("className"); throw new ArgumentNullException("className");
className = className.Replace('+', '.'); int typeParameterCount;
if (className.Length > 2 && className[className.Length - 2] == '`') { className = ReflectionLayer.ReflectionClass.ConvertReflectionNameToFullName(className, out typeParameterCount);
int typeParameterCount = className[className.Length - 1] - '0'; GetClassOptions options = GetClassOptions.Default;
if (typeParameterCount < 0) typeParameterCount = 0; if (!lookInReferences)
className = className.Substring(0, className.Length - 2); options &= ~GetClassOptions.LookInReferences;
return GetClass(className, typeParameterCount, LanguageProperties.CSharp, GetClassOptions.Default); return GetClass(className, typeParameterCount, LanguageProperties.CSharp, options);
} else {
return GetClass(className, 0, LanguageProperties.CSharp, GetClassOptions.Default);
}
} }
/// <summary> /// <summary>

2
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/DomPersistence.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.SharpDevelop.Dom
{ {
public const long FileMagic = 0x11635233ED2F428C; public const long FileMagic = 0x11635233ED2F428C;
public const long IndexFileMagic = 0x11635233ED2F427D; public const long IndexFileMagic = 0x11635233ED2F427D;
public const short FileVersion = 19; public const short FileVersion = 20;
ProjectContentRegistry registry; ProjectContentRegistry registry;
string cacheDirectory; string cacheDirectory;

19
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionClass.cs

@ -8,6 +8,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Text;
namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer
{ {
@ -124,6 +125,24 @@ namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer
} }
} }
public static string ConvertReflectionNameToFullName(string reflectionName, out int typeParameterCount)
{
if (reflectionName.IndexOf('+') > 0) {
typeParameterCount = 0;
StringBuilder newName = new StringBuilder();
foreach (string namepart in reflectionName.Split('+')) {
if (newName.Length > 0)
newName.Append('.');
int partTypeParameterCount;
newName.Append(SplitTypeParameterCountFromReflectionName(namepart, out partTypeParameterCount));
typeParameterCount += partTypeParameterCount;
}
return newName.ToString();
} else {
return SplitTypeParameterCountFromReflectionName(reflectionName, out typeParameterCount);
}
}
public ReflectionClass(ICompilationUnit compilationUnit, Type type, string fullName, IClass declaringType) : base(compilationUnit, declaringType) public ReflectionClass(ICompilationUnit compilationUnit, Type type, string fullName, IClass declaringType) : base(compilationUnit, declaringType)
{ {
FullyQualifiedName = SplitTypeParameterCountFromReflectionName(fullName); FullyQualifiedName = SplitTypeParameterCountFromReflectionName(fullName);

15
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionReturnType.cs

@ -71,20 +71,7 @@ namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer
if (name == null) if (name == null)
throw new ApplicationException("type.FullName returned null. Type: " + type.ToString()); throw new ApplicationException("type.FullName returned null. Type: " + type.ToString());
int typeParameterCount; int typeParameterCount;
if (name.IndexOf('+') > 0) { name = ReflectionClass.ConvertReflectionNameToFullName(name, out typeParameterCount);
typeParameterCount = 0;
StringBuilder newName = new StringBuilder();
foreach (string namepart in name.Split('+')) {
if (newName.Length > 0)
newName.Append('.');
int partTypeParameterCount;
newName.Append(ReflectionClass.SplitTypeParameterCountFromReflectionName(namepart, out partTypeParameterCount));
typeParameterCount += partTypeParameterCount;
}
name = newName.ToString();
} else {
name = ReflectionClass.SplitTypeParameterCountFromReflectionName(name, out typeParameterCount);
}
if (!createLazyReturnType) { if (!createLazyReturnType) {
IClass c = pc.GetClass(name, typeParameterCount); IClass c = pc.GetClass(name, typeParameterCount);
if (c != null) if (c != null)

Loading…
Cancel
Save