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

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

@ -162,8 +162,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -162,8 +162,7 @@ namespace ICSharpCode.SharpDevelop.Dom
string name = td.FullName;
if (name.Length == 0 || name[0] == '<')
continue;
if (name.Length > 2 && name[name.Length - 2] == '`')
name = name.Substring(0, name.Length - 2);
name = ReflectionClass.SplitTypeParameterCountFromReflectionName(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 @@ -264,16 +264,17 @@ namespace ICSharpCode.SharpDevelop.Dom
public override string DotNetName {
get {
string fullName;
int typeParametersCount = this.TypeParameters.Count;
if (this.DeclaringType != null) {
fullName = this.DeclaringType.DotNetName + "+" + this.Name;
typeParametersCount -= this.DeclaringType.TypeParameters.Count;
} else {
fullName = this.FullyQualifiedName;
}
IList<ITypeParameter> typeParameters = this.TypeParameters;
if (typeParameters == null || typeParameters.Count == 0) {
if (typeParametersCount == 0) {
return fullName;
} 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 @@ -867,15 +867,12 @@ namespace ICSharpCode.SharpDevelop.Dom
{
if (className == null)
throw new ArgumentNullException("className");
className = className.Replace('+', '.');
if (className.Length > 2 && className[className.Length - 2] == '`') {
int typeParameterCount = className[className.Length - 1] - '0';
if (typeParameterCount < 0) typeParameterCount = 0;
className = className.Substring(0, className.Length - 2);
return GetClass(className, typeParameterCount, LanguageProperties.CSharp, GetClassOptions.Default);
} else {
return GetClass(className, 0, LanguageProperties.CSharp, GetClassOptions.Default);
}
int typeParameterCount;
className = ReflectionLayer.ReflectionClass.ConvertReflectionNameToFullName(className, out typeParameterCount);
GetClassOptions options = GetClassOptions.Default;
if (!lookInReferences)
options &= ~GetClassOptions.LookInReferences;
return GetClass(className, typeParameterCount, LanguageProperties.CSharp, options);
}
/// <summary>

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

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

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

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer
{
@ -124,6 +125,24 @@ 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)
{
FullyQualifiedName = SplitTypeParameterCountFromReflectionName(fullName);

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

@ -71,20 +71,7 @@ namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer @@ -71,20 +71,7 @@ namespace ICSharpCode.SharpDevelop.Dom.ReflectionLayer
if (name == null)
throw new ApplicationException("type.FullName returned null. Type: " + type.ToString());
int typeParameterCount;
if (name.IndexOf('+') > 0) {
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);
}
name = ReflectionClass.ConvertReflectionNameToFullName(name, out typeParameterCount);
if (!createLazyReturnType) {
IClass c = pc.GetClass(name, typeParameterCount);
if (c != null)

Loading…
Cancel
Save