diff options
author | jfrijters <jfrijters> | 2011-03-13 12:09:43 +0300 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-03-13 12:09:43 +0300 |
commit | bb8ddbfcc0cc8daf7c5f8f5c2de96942847867dc (patch) | |
tree | 7247490275b49a3f8d8f02a1953c2c73b1eb50e2 /reflect/Emit | |
parent | 896b5a4b57bc30d8b5b046bb0d41695ac8cd5eb1 (diff) |
Type parameter type names need not assembly qualified if the types live in the current assembly.
Diffstat (limited to 'reflect/Emit')
-rw-r--r-- | reflect/Emit/CustomAttributeBuilder.cs | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/reflect/Emit/CustomAttributeBuilder.cs b/reflect/Emit/CustomAttributeBuilder.cs index 09ee4d83..b1b23dd1 100644 --- a/reflect/Emit/CustomAttributeBuilder.cs +++ b/reflect/Emit/CustomAttributeBuilder.cs @@ -25,6 +25,7 @@ using System; using System.IO; using System.Collections.Generic; using System.Diagnostics; +using System.Text; using IKVM.Reflection.Writer; namespace IKVM.Reflection.Emit @@ -306,23 +307,69 @@ namespace IKVM.Reflection.Emit string name = null; if (type != null) { - bool v1 = !assembly.ManifestModule.__IsMissing && assembly.ManifestModule.MDStreamVersion < 0x20000; - if (type.Assembly == assembly || (v1 && type.Assembly == type.Module.universe.Mscorlib)) + StringBuilder sb = new StringBuilder(); + GetTypeName(sb, type, false); + name = sb.ToString(); + } + WriteString(name); + } + + private void GetTypeName(StringBuilder sb, Type type, bool isTypeParam) + { + bool v1 = !assembly.ManifestModule.__IsMissing && assembly.ManifestModule.MDStreamVersion < 0x20000; + bool includeAssemblyName = type.Assembly != assembly && (!v1 || type.Assembly != type.Module.universe.Mscorlib); + if (isTypeParam && includeAssemblyName) + { + sb.Append('['); + } + GetTypeNameImpl(sb, type); + if (includeAssemblyName) + { + if (v1) + { + sb.Append(','); + } + else { - name = type.FullName; + sb.Append(", "); } - else if (v1) + if (isTypeParam) { - name = type.FullName + "," + type.Assembly.FullName; + sb.Append(type.Assembly.FullName.Replace("]", "\\]")).Append(']'); } else { - name = type.AssemblyQualifiedName; + sb.Append(type.Assembly.FullName); } } - WriteString(name); } + private void GetTypeNameImpl(StringBuilder sb, Type type) + { + if (type.HasElementType) + { + GetTypeNameImpl(sb, type.GetElementType()); + sb.Append(((ElementHolderType)type).GetSuffix()); + } + else if (type.IsGenericTypeInstance) + { + sb.Append(type.GetGenericTypeDefinition().FullName); + sb.Append('['); + string sep = ""; + foreach (Type typeParam in type.GetGenericArguments()) + { + sb.Append(sep); + GetTypeName(sb, typeParam, true); + sep = ","; + } + sb.Append(']'); + } + else + { + sb.Append(type.FullName); + } + } + private void WriteString(string val) { bb.Write(val); |