91
94
/// Loads the assembly definition into a project content.
93
96
/// <returns>IProjectContent that represents the assembly</returns>
94
public IProjectContent LoadAssembly(AssemblyDefinition assemblyDefinition)
98
public IUnresolvedAssembly LoadAssembly(AssemblyDefinition assemblyDefinition)
96
100
if (assemblyDefinition == null)
97
101
throw new ArgumentNullException("assemblyDefinition");
98
ITypeResolveContext oldEarlyBindContext = this.EarlyBindContext;
100
// Read assembly and module attributes
101
IList<IAttribute> assemblyAttributes = new List<IAttribute>();
102
IList<IAttribute> moduleAttributes = new List<IAttribute>();
103
AddAttributes(assemblyDefinition, assemblyAttributes);
104
AddAttributes(assemblyDefinition.MainModule, moduleAttributes);
106
if (this.InterningProvider != null) {
107
assemblyAttributes = this.InterningProvider.InternList(assemblyAttributes);
108
moduleAttributes = this.InterningProvider.InternList(moduleAttributes);
110
assemblyAttributes = new ReadOnlyCollection<IAttribute>(assemblyAttributes);
111
moduleAttributes = new ReadOnlyCollection<IAttribute>(moduleAttributes);
103
this.currentModule = assemblyDefinition.MainModule;
105
// Read assembly and module attributes
106
IList<IUnresolvedAttribute> assemblyAttributes = new List<IUnresolvedAttribute>();
107
IList<IUnresolvedAttribute> moduleAttributes = new List<IUnresolvedAttribute>();
108
AddAttributes(assemblyDefinition, assemblyAttributes);
109
AddAttributes(assemblyDefinition.MainModule, moduleAttributes);
111
if (this.InterningProvider != null) {
112
assemblyAttributes = this.InterningProvider.InternList(assemblyAttributes);
113
moduleAttributes = this.InterningProvider.InternList(moduleAttributes);
116
this.currentAssembly = new CecilUnresolvedAssembly(assemblyDefinition.Name.Name, this.DocumentationProvider);
117
currentAssembly.AssemblyAttributes.AddRange(assemblyAttributes);
118
currentAssembly.ModuleAttributes.AddRange(assemblyAttributes);
120
// Register type forwarders:
121
foreach (ExportedType type in assemblyDefinition.MainModule.ExportedTypes) {
122
if (type.IsForwarder) {
123
int typeParameterCount;
124
string name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
125
var typeRef = new GetClassTypeReference(GetAssemblyReference(type.Scope), type.Namespace, name, typeParameterCount);
126
typeRef = this.InterningProvider.Intern(typeRef);
127
var key = new FullNameAndTypeParameterCount(type.Namespace, name, typeParameterCount);
128
currentAssembly.AddTypeForwarder(key, typeRef);
113
TypeStorage typeStorage = new TypeStorage();
114
CecilProjectContent pc = new CecilProjectContent(typeStorage, assemblyDefinition.Name.FullName, assemblyAttributes, moduleAttributes, this.DocumentationProvider);
116
this.EarlyBindContext = CompositeTypeResolveContext.Combine(pc, this.EarlyBindContext);
117
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>();
118
foreach (ModuleDefinition module in assemblyDefinition.Modules) {
119
foreach (TypeDefinition td in module.Types) {
120
this.CancellationToken.ThrowIfCancellationRequested();
121
if (this.IncludeInternalMembers || (td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
122
string name = td.FullName;
123
if (name.Length == 0 || name[0] == '<')
125
if (name == "System.Void") {
126
var c = new VoidTypeDefinition(pc);
127
AddAttributes(td, c);
128
typeStorage.UpdateType(c);
130
CecilTypeDefinition c = new CecilTypeDefinition(pc, td);
132
typeStorage.UpdateType(c);
132
// Create and register all types:
133
List<TypeDefinition> cecilTypeDefs = new List<TypeDefinition>();
134
List<DefaultUnresolvedTypeDefinition> typeDefs = new List<DefaultUnresolvedTypeDefinition>();
135
foreach (ModuleDefinition module in assemblyDefinition.Modules) {
136
foreach (TypeDefinition td in module.Types) {
137
this.CancellationToken.ThrowIfCancellationRequested();
138
if (this.IncludeInternalMembers || (td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
139
string name = td.Name;
140
if (name.Length == 0 || name[0] == '<')
143
var t = CreateTopLevelTypeDefinition(td);
144
cecilTypeDefs.Add(td);
146
currentAssembly.AddTypeDefinition(t);
137
foreach (CecilTypeDefinition c in types) {
140
if (HasCecilReferences)
141
typeSystemTranslationTable[pc] = assemblyDefinition;
144
this.EarlyBindContext = oldEarlyBindContext;
150
// Initialize the type's members:
151
for (int i = 0; i < typeDefs.Count; i++) {
152
InitTypeDefinition(cecilTypeDefs[i], typeDefs[i]);
155
if (HasCecilReferences)
156
typeSystemTranslationTable[this.currentAssembly] = assemblyDefinition;
158
var result = this.currentAssembly;
159
this.currentAssembly = null;
160
this.currentModule = null;
149
165
/// Loads a type from Cecil.
151
167
/// <param name="typeDefinition">The Cecil TypeDefinition.</param>
152
/// <param name="projectContent">The project content used as parent for the new type.</param>
153
168
/// <returns>ITypeDefinition representing the Cecil type.</returns>
154
public ITypeDefinition LoadType(TypeDefinition typeDefinition, IProjectContent projectContent)
169
[CLSCompliant(false)]
170
public IUnresolvedTypeDefinition LoadType(TypeDefinition typeDefinition)
156
172
if (typeDefinition == null)
157
173
throw new ArgumentNullException("typeDefinition");
158
if (projectContent == null)
159
throw new ArgumentNullException("projectContent");
160
var c = new CecilTypeDefinition(projectContent, typeDefinition);
174
var td = CreateTopLevelTypeDefinition(typeDefinition);
175
InitTypeDefinition(typeDefinition, td);
166
#region IProjectContent implementation
167
sealed class CecilProjectContent : ProxyTypeResolveContext, IProjectContent, ISynchronizedTypeResolveContext, IDocumentationProvider
180
#region IUnresolvedAssembly implementation
182
sealed class CecilUnresolvedAssembly : DefaultUnresolvedAssembly, IDocumentationProvider, IDocumentationProviderContainer
169
readonly string assemblyName;
170
readonly IList<IAttribute> assemblyAttributes;
171
readonly IList<IAttribute> moduleAttributes;
172
readonly IDocumentationProvider documentationProvider;
174
public CecilProjectContent(TypeStorage types, string assemblyName, IList<IAttribute> assemblyAttributes, IList<IAttribute> moduleAttributes, IDocumentationProvider documentationProvider)
185
IDocumentationProvider documentationProvider;
187
public IDocumentationProvider DocumentationProvider {
189
return documentationProvider;
192
documentationProvider = value;
196
public CecilUnresolvedAssembly(string assemblyName, IDocumentationProvider documentationProvider)
177
199
Debug.Assert(assemblyName != null);
178
Debug.Assert(assemblyAttributes != null);
179
Debug.Assert(moduleAttributes != null);
180
this.assemblyName = assemblyName;
181
this.assemblyAttributes = assemblyAttributes;
182
this.moduleAttributes = moduleAttributes;
183
200
this.documentationProvider = documentationProvider;
186
public IList<IAttribute> AssemblyAttributes {
187
get { return assemblyAttributes; }
190
public IList<IAttribute> ModuleAttributes {
191
get { return moduleAttributes; }
194
public override string ToString()
196
return "[CecilProjectContent " + assemblyName + "]";
199
public override ISynchronizedTypeResolveContext Synchronize()
201
// CecilProjectContent is immutable, so we don't need to synchronize
205
void IDisposable.Dispose()
207
// Disposing the synchronization context has no effect
210
IParsedFile IProjectContent.GetFile(string fileName)
215
IEnumerable<IParsedFile> IProjectContent.Files {
217
return EmptyList<IParsedFile>.Instance;
221
void IProjectContent.UpdateProjectContent(IParsedFile oldFile, IParsedFile newFile)
223
throw new NotSupportedException();
226
string IDocumentationProvider.GetDocumentation(IEntity entity)
203
DocumentationComment IDocumentationProvider.GetDocumentation(IEntity entity)
228
205
if (documentationProvider != null)
229
206
return documentationProvider.GetDocumentation(entity);
758
public IAttribute ReadAttribute(CustomAttribute attribute)
710
[CLSCompliant(false)]
711
public IUnresolvedAttribute ReadAttribute(CustomAttribute attribute)
760
713
if (attribute == null)
761
714
throw new ArgumentNullException("attribute");
762
715
MethodReference ctor = attribute.Constructor;
763
ITypeReference[] ctorParameters = null;
716
ITypeReference attributeType = ReadTypeReference(attribute.AttributeType);
717
IList<ITypeReference> ctorParameterTypes = null;
764
718
if (ctor.HasParameters) {
765
ctorParameters = new ITypeReference[ctor.Parameters.Count];
766
for (int i = 0; i < ctorParameters.Length; i++) {
767
ctorParameters[i] = ReadTypeReference(ctor.Parameters[i].ParameterType);
770
DefaultAttribute a = new DefaultAttribute(ReadTypeReference(attribute.AttributeType), ctorParameters);
771
if (attribute.HasConstructorArguments) {
772
foreach (var arg in attribute.ConstructorArguments) {
773
a.PositionalArguments.Add(ReadConstantValue(arg));
776
if (attribute.HasFields || attribute.HasProperties) {
777
foreach (var arg in attribute.Fields) {
778
a.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument)));
780
foreach (var arg in attribute.Properties) {
781
a.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument)));
719
ctorParameterTypes = new ITypeReference[ctor.Parameters.Count];
720
for (int i = 0; i < ctorParameterTypes.Count; i++) {
721
ctorParameterTypes[i] = ReadTypeReference(ctor.Parameters[i].ParameterType);
724
if (this.InterningProvider != null) {
725
attributeType = this.InterningProvider.Intern(attributeType);
726
ctorParameterTypes = this.InterningProvider.InternList(ctorParameterTypes);
728
return new CecilUnresolvedAttribute(attributeType, ctorParameterTypes ?? EmptyList<ITypeReference>.Instance, attribute.GetBlob());
732
#region CecilUnresolvedAttribute
733
static int GetBlobHashCode(byte[] blob)
737
foreach (byte b in blob) {
745
static bool BlobEquals(byte[] a, byte[] b)
747
if (a.Length != b.Length)
749
for (int i = 0; i < a.Length; i++) {
757
sealed class CecilUnresolvedAttribute : IUnresolvedAttribute, ISupportsInterning
759
internal readonly ITypeReference attributeType;
760
internal readonly IList<ITypeReference> ctorParameterTypes;
761
internal readonly byte[] blob;
763
public CecilUnresolvedAttribute(ITypeReference attributeType, IList<ITypeReference> ctorParameterTypes, byte[] blob)
765
Debug.Assert(attributeType != null);
766
Debug.Assert(ctorParameterTypes != null);
767
Debug.Assert(blob != null);
768
this.attributeType = attributeType;
769
this.ctorParameterTypes = ctorParameterTypes;
773
DomRegion IUnresolvedAttribute.Region {
774
get { return DomRegion.Empty; }
777
IAttribute IUnresolvedAttribute.CreateResolvedAttribute(ITypeResolveContext context)
779
if (context.CurrentAssembly == null)
780
throw new InvalidOperationException("Cannot resolve CecilUnresolvedAttribute without a parent assembly");
781
return new CecilResolvedAttribute(context, this);
784
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
786
// We already interned our child elements in ReadAttribute().
789
int ISupportsInterning.GetHashCodeForInterning()
791
return attributeType.GetHashCode() ^ ctorParameterTypes.GetHashCode() ^ GetBlobHashCode(blob);
794
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
796
CecilUnresolvedAttribute o = other as CecilUnresolvedAttribute;
797
return o != null && attributeType == o.attributeType && ctorParameterTypes == o.ctorParameterTypes
798
&& BlobEquals(blob, o.blob);
803
#region CecilResolvedAttribute
804
sealed class CecilResolvedAttribute : IAttribute
806
readonly ITypeResolveContext context;
807
readonly byte[] blob;
808
readonly IList<ITypeReference> ctorParameterTypes;
809
readonly IType attributeType;
812
volatile bool constructorResolved;
814
IList<ResolveResult> positionalArguments;
815
IList<KeyValuePair<IMember, ResolveResult>> namedArguments;
817
public CecilResolvedAttribute(ITypeResolveContext context, CecilUnresolvedAttribute unresolved)
819
this.context = context;
820
this.blob = unresolved.blob;
821
this.ctorParameterTypes = unresolved.ctorParameterTypes;
822
this.attributeType = unresolved.attributeType.Resolve(context);
825
public CecilResolvedAttribute(ITypeResolveContext context, IType attributeType)
827
this.context = context;
828
this.attributeType = attributeType;
829
this.ctorParameterTypes = EmptyList<ITypeReference>.Instance;
832
public DomRegion Region {
833
get { return DomRegion.Empty; }
836
public IType AttributeType {
837
get { return attributeType; }
840
public IMethod Constructor {
842
if (!constructorResolved) {
843
constructor = ResolveConstructor();
844
constructorResolved = true;
850
IMethod ResolveConstructor()
852
var parameterTypes = ctorParameterTypes.Resolve(context);
853
foreach (var ctor in attributeType.GetConstructors(m => m.Parameters.Count == parameterTypes.Count)) {
855
for (int i = 0; i < parameterTypes.Count; i++) {
856
if (!ctor.Parameters[i].Type.Equals(parameterTypes[i])) {
867
public IList<ResolveResult> PositionalArguments {
869
var result = LazyInit.VolatileRead(ref this.positionalArguments);
870
if (result != null) {
874
return positionalArguments;
878
public IList<KeyValuePair<IMember, ResolveResult>> NamedArguments {
880
var result = LazyInit.VolatileRead(ref this.namedArguments);
881
if (result != null) {
885
return namedArguments;
889
public override string ToString()
891
return "[" + attributeType.ToString() + "(...)]";
896
var positionalArguments = new List<ResolveResult>();
897
var namedArguments = new List<KeyValuePair<IMember, ResolveResult>>();
898
DecodeBlob(positionalArguments, namedArguments);
899
Interlocked.CompareExchange(ref this.positionalArguments, positionalArguments, null);
900
Interlocked.CompareExchange(ref this.namedArguments, namedArguments, null);
903
void DecodeBlob(List<ResolveResult> positionalArguments, List<KeyValuePair<IMember, ResolveResult>> namedArguments)
907
BlobReader reader = new BlobReader(blob, context.CurrentAssembly);
908
if (reader.ReadUInt16() != 0x0001) {
909
Debug.WriteLine("Unknown blob prolog");
912
foreach (var ctorParameter in ctorParameterTypes.Resolve(context)) {
913
positionalArguments.Add(reader.ReadFixedArg(ctorParameter));
915
ushort numNamed = reader.ReadUInt16();
916
for (int i = 0; i < numNamed; i++) {
917
var namedArg = reader.ReadNamedArg(attributeType);
918
if (namedArg.Key != null)
919
namedArguments.Add(namedArg);
925
#region class BlobReader
930
readonly IAssembly currentResolvedAssembly;
932
public BlobReader(byte[] buffer, IAssembly currentResolvedAssembly)
935
throw new ArgumentNullException("buffer");
936
this.buffer = buffer;
937
this.currentResolvedAssembly = currentResolvedAssembly;
940
public byte ReadByte()
942
return buffer[position++];
945
public sbyte ReadSByte()
948
return(sbyte) ReadByte();
952
public byte[] ReadBytes(int length)
954
var bytes = new byte[length];
955
Buffer.BlockCopy(buffer, position, bytes, 0, length);
960
public ushort ReadUInt16()
963
ushort value =(ushort)(buffer[position]
964
|(buffer[position + 1] << 8));
970
public short ReadInt16()
973
return(short) ReadUInt16();
977
public uint ReadUInt32()
980
uint value =(uint)(buffer[position]
981
|(buffer[position + 1] << 8)
982
|(buffer[position + 2] << 16)
983
|(buffer[position + 3] << 24));
989
public int ReadInt32()
992
return(int) ReadUInt32();
996
public ulong ReadUInt64()
999
uint low = ReadUInt32();
1000
uint high = ReadUInt32();
1002
return(((ulong) high) << 32) | low;
1006
public long ReadInt64()
1009
return(long) ReadUInt64();
1013
public uint ReadCompressedUInt32()
1016
byte first = ReadByte();
1017
if((first & 0x80) == 0)
1020
if((first & 0x40) == 0)
1021
return((uint)(first & ~0x80) << 8)
1024
return((uint)(first & ~0xc0) << 24)
1025
|(uint) ReadByte() << 16
1026
|(uint) ReadByte() << 8
1031
public float ReadSingle()
1034
if(!BitConverter.IsLittleEndian) {
1035
var bytes = ReadBytes(4);
1036
Array.Reverse(bytes);
1037
return BitConverter.ToSingle(bytes, 0);
1040
float value = BitConverter.ToSingle(buffer, position);
1046
public double ReadDouble()
1049
if(!BitConverter.IsLittleEndian) {
1050
var bytes = ReadBytes(8);
1051
Array.Reverse(bytes);
1052
return BitConverter.ToDouble(bytes, 0);
1055
double value = BitConverter.ToDouble(buffer, position);
1061
public ResolveResult ReadFixedArg(IType argType)
1063
if (argType.Kind == TypeKind.Array) {
1064
if (((ArrayType)argType).Dimensions != 1) {
1065
// Only single-dimensional arrays are supported
1066
return ErrorResolveResult.UnknownError;
1068
IType elementType = ((ArrayType)argType).ElementType;
1069
uint numElem = ReadUInt32();
1070
if (numElem == 0xffffffff) {
1072
return new ConstantResolveResult(argType, null);
1074
ResolveResult[] elements = new ResolveResult[numElem];
1075
for (int i = 0; i < elements.Length; i++) {
1076
elements[i] = ReadElem(elementType);
1078
return new ArrayCreateResolveResult(argType, null, elements);
1081
return ReadElem(argType);
1085
public ResolveResult ReadElem(IType elementType)
1087
ITypeDefinition underlyingType;
1088
if (elementType.Kind == TypeKind.Enum) {
1089
underlyingType = elementType.GetDefinition().EnumUnderlyingType.GetDefinition();
1091
underlyingType = elementType.GetDefinition();
1093
if (underlyingType == null)
1094
return ErrorResolveResult.UnknownError;
1095
KnownTypeCode typeCode = underlyingType.KnownTypeCode;
1096
if (typeCode == KnownTypeCode.Object) {
1098
IType boxedTyped = ReadCustomAttributeFieldOrPropType();
1099
ResolveResult elem = ReadElem(boxedTyped);
1100
if (elem.IsCompileTimeConstant && elem.ConstantValue == null)
1101
return new ConstantResolveResult(elementType, null);
1103
return new ConversionResolveResult(elementType, elem, Conversion.BoxingConversion);
1104
} else if (typeCode == KnownTypeCode.Type) {
1105
return new TypeOfResolveResult(underlyingType, ReadType());
1107
return new ConstantResolveResult(elementType, ReadElemValue(typeCode));
1111
object ReadElemValue(KnownTypeCode typeCode)
1114
case KnownTypeCode.Boolean:
1115
return ReadByte() != 0;
1116
case KnownTypeCode.Char:
1117
return (char)ReadUInt16();
1118
case KnownTypeCode.SByte:
1120
case KnownTypeCode.Byte:
1122
case KnownTypeCode.Int16:
1124
case KnownTypeCode.UInt16:
1125
return ReadUInt16();
1126
case KnownTypeCode.Int32:
1128
case KnownTypeCode.UInt32:
1129
return ReadUInt32();
1130
case KnownTypeCode.Int64:
1132
case KnownTypeCode.UInt64:
1133
return ReadUInt64();
1134
case KnownTypeCode.Single:
1135
return ReadSingle();
1136
case KnownTypeCode.Double:
1137
return ReadDouble();
1138
case KnownTypeCode.String:
1139
return ReadSerString();
1141
throw new NotSupportedException();
1145
public string ReadSerString ()
1147
if (buffer [position] == 0xff) {
1152
int length = (int) ReadCompressedUInt32();
1154
return string.Empty;
1156
string @string = System.Text.Encoding.UTF8.GetString(
1158
buffer [position + length - 1] == 0 ? length - 1 : length);
1164
public KeyValuePair<IMember, ResolveResult> ReadNamedArg(IType attributeType)
1166
EntityType memberType;
1167
switch (ReadByte()) {
1169
memberType = EntityType.Field;
1172
memberType = EntityType.Property;
1175
throw new NotSupportedException();
1177
IType type = ReadCustomAttributeFieldOrPropType();
1178
string name = ReadSerString();
1179
ResolveResult val = ReadFixedArg(type);
1180
IMember member = null;
1181
// Use last matching member, as GetMembers() returns members from base types first.
1182
foreach (IMember m in attributeType.GetMembers(m => m.EntityType == memberType && m.Name == name)) {
1183
if (m.ReturnType.Equals(type))
1186
return new KeyValuePair<IMember, ResolveResult>(member, val);
1189
IType ReadCustomAttributeFieldOrPropType()
1191
ICompilation compilation = currentResolvedAssembly.Compilation;
1192
switch (ReadByte()) {
1194
return compilation.FindType(KnownTypeCode.Boolean);
1196
return compilation.FindType(KnownTypeCode.Char);
1198
return compilation.FindType(KnownTypeCode.SByte);
1200
return compilation.FindType(KnownTypeCode.Byte);
1202
return compilation.FindType(KnownTypeCode.Int16);
1204
return compilation.FindType(KnownTypeCode.UInt16);
1206
return compilation.FindType(KnownTypeCode.Int32);
1208
return compilation.FindType(KnownTypeCode.UInt32);
1210
return compilation.FindType(KnownTypeCode.Int64);
1212
return compilation.FindType(KnownTypeCode.UInt64);
1214
return compilation.FindType(KnownTypeCode.Single);
1216
return compilation.FindType(KnownTypeCode.Double);
1218
return compilation.FindType(KnownTypeCode.String);
1220
return new ArrayType(compilation, ReadCustomAttributeFieldOrPropType());
1222
return compilation.FindType(KnownTypeCode.Type);
1223
case 0x51: // boxed value type
1224
return compilation.FindType(KnownTypeCode.Object);
1228
throw new NotSupportedException();
1234
string typeName = ReadSerString();
1235
ITypeReference typeReference = ReflectionHelper.ParseReflectionName(typeName);
1236
IType typeInCurrentAssembly = typeReference.Resolve(new SimpleTypeResolveContext(currentResolvedAssembly));
1237
if (typeInCurrentAssembly.Kind != TypeKind.Unknown)
1238
return typeInCurrentAssembly;
1240
// look for the type in mscorlib
1241
ITypeDefinition systemObject = currentResolvedAssembly.Compilation.FindType(KnownTypeCode.Object).GetDefinition();
1242
if (systemObject != null) {
1243
return typeReference.Resolve(new SimpleTypeResolveContext(systemObject.ParentAssembly));
1245
// couldn't find corlib - return the unknown IType for the current assembly
1246
return typeInCurrentAssembly;
788
1252
#region Security Attributes
789
static readonly ITypeReference securityActionTypeReference = typeof(SecurityAction).ToTypeReference();
791
void AddSecurityAttributes(Mono.Collections.Generic.Collection<SecurityDeclaration> securityDeclarations, IList<IAttribute> targetCollection)
1253
static readonly ITypeReference securityActionTypeReference = typeof(System.Security.Permissions.SecurityAction).ToTypeReference();
1254
static readonly ITypeReference permissionSetAttributeTypeReference = typeof(System.Security.Permissions.PermissionSetAttribute).ToTypeReference();
1257
/// Reads a security declaration.
1259
[CLSCompliant(false)]
1260
public IList<IUnresolvedAttribute> ReadSecurityDeclaration(SecurityDeclaration secDecl)
1262
if (secDecl == null)
1263
throw new ArgumentNullException("secDecl");
1264
var result = new List<IUnresolvedAttribute>();
1265
AddSecurityAttributes(secDecl, result);
1269
void AddSecurityAttributes(Mono.Collections.Generic.Collection<SecurityDeclaration> securityDeclarations, IList<IUnresolvedAttribute> targetCollection)
793
1271
foreach (var secDecl in securityDeclarations) {
1272
AddSecurityAttributes(secDecl, targetCollection);
1276
void AddSecurityAttributes(SecurityDeclaration secDecl, IList<IUnresolvedAttribute> targetCollection)
1278
byte[] blob = secDecl.GetBlob();
1279
BlobReader reader = new BlobReader(blob, null);
1280
var securityAction = new SimpleConstantValue(securityActionTypeReference, (int)secDecl.Action);
1281
if (reader.ReadByte() == '.') {
1283
uint attributeCount = reader.ReadCompressedUInt32();
1284
UnresolvedSecurityDeclaration unresolvedSecDecl = new UnresolvedSecurityDeclaration(securityAction, blob);
1285
if (this.InterningProvider != null) {
1286
unresolvedSecDecl = this.InterningProvider.Intern(unresolvedSecDecl);
1288
for (uint i = 0; i < attributeCount; i++) {
1289
targetCollection.Add(new UnresolvedSecurityAttribute(unresolvedSecDecl, (int)i));
1292
// for backward compatibility with .NET 1.0: XML-encoded attribute
1293
var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference);
1294
attr.ConstructorParameterTypes.Add(securityActionTypeReference);
1295
attr.PositionalArguments.Add(securityAction);
1296
string xml = System.Text.Encoding.Unicode.GetString(blob);
1297
attr.AddNamedPropertyArgument("XML", KnownTypeReference.String, xml);
1298
targetCollection.Add(attr);
1303
sealed class UnresolvedSecurityDeclaration : ISupportsInterning
1305
IConstantValue securityAction;
1308
public UnresolvedSecurityDeclaration(IConstantValue securityAction, byte[] blob)
1310
Debug.Assert(securityAction != null);
1311
Debug.Assert(blob != null);
1312
this.securityAction = securityAction;
1316
public IList<IAttribute> Resolve(IAssembly currentAssembly)
1318
// TODO: make this a per-assembly cache
1319
// CacheManager cache = currentAssembly.Compilation.CacheManager;
1320
// IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this);
1321
// if (result != null)
1324
ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly);
1325
BlobReader reader = new BlobReader(blob, currentAssembly);
1326
if (reader.ReadByte() != '.') {
1327
// should not use UnresolvedSecurityDeclaration for XML secdecls
1328
throw new InvalidOperationException();
1330
ResolveResult securityActionRR = securityAction.Resolve(context);
1331
uint attributeCount = reader.ReadCompressedUInt32();
1332
IAttribute[] attributes = new IAttribute[attributeCount];
795
foreach (var secAttribute in secDecl.SecurityAttributes) {
796
ITypeReference attributeType = ReadTypeReference(secAttribute.AttributeType);
797
var a = new DefaultAttribute(attributeType, new[] { securityActionTypeReference });
798
a.PositionalArguments.Add(new SimpleConstantValue(securityActionTypeReference, (ushort)secDecl.Action));
1334
ReadSecurityBlob(reader, attributes, context, securityActionRR);
1335
} catch (NotSupportedException ex) {
1336
// ignore invalid blobs
1337
Debug.WriteLine(ex.ToString());
1339
for (int i = 0; i < attributes.Length; i++) {
1340
if (attributes[i] == null)
1341
attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType);
1344
// return (IList<IAttribute>)cache.GetOrAddShared(this, attributes);
1347
void ReadSecurityBlob(BlobReader reader, IAttribute[] attributes, ITypeResolveContext context, ResolveResult securityActionRR)
1349
for (int i = 0; i < attributes.Length; i++) {
1350
string attributeTypeName = reader.ReadSerString();
1351
ITypeReference attributeTypeRef = ReflectionHelper.ParseReflectionName(attributeTypeName);
1352
IType attributeType = attributeTypeRef.Resolve(context);
1354
reader.ReadCompressedUInt32(); // ??
1355
// The specification seems to be incorrect here, so I'm using the logic from Cecil instead.
1356
uint numNamed = reader.ReadCompressedUInt32();
1358
var namedArgs = new List<KeyValuePair<IMember, ResolveResult>>((int)numNamed);
1359
for (uint j = 0; j < numNamed; j++) {
1360
var namedArg = reader.ReadNamedArg(attributeType);
1361
if (namedArg.Key != null)
1362
namedArgs.Add(namedArg);
800
if (secAttribute.HasFields || secAttribute.HasProperties) {
801
foreach (var arg in secAttribute.Fields) {
802
a.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument)));
804
foreach (var arg in secAttribute.Properties) {
805
a.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument)));
1365
attributes[i] = new ResolvedSecurityAttribute {
1366
AttributeType = attributeType,
1367
NamedArguments = namedArgs,
1368
PositionalArguments = new ResolveResult[] { securityActionRR }
1373
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
1375
securityAction = provider.Intern(securityAction);
1378
int ISupportsInterning.GetHashCodeForInterning()
1380
return securityAction.GetHashCode() ^ GetBlobHashCode(blob);
1383
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
1385
UnresolvedSecurityDeclaration o = other as UnresolvedSecurityDeclaration;
1386
return o != null && securityAction == o.securityAction && BlobEquals(blob, o.blob);
1391
sealed class UnresolvedSecurityAttribute : IUnresolvedAttribute
1393
readonly UnresolvedSecurityDeclaration secDecl;
1396
public UnresolvedSecurityAttribute(UnresolvedSecurityDeclaration secDecl, int index)
1398
Debug.Assert(secDecl != null);
1399
this.secDecl = secDecl;
1403
DomRegion IUnresolvedAttribute.Region {
1404
get { return DomRegion.Empty; }
1407
IAttribute IUnresolvedAttribute.CreateResolvedAttribute(ITypeResolveContext context)
1409
return secDecl.Resolve(context.CurrentAssembly)[index];
1413
sealed class ResolvedSecurityAttribute : IAttribute
1415
public IType AttributeType { get; internal set; }
1417
DomRegion IAttribute.Region {
1418
get { return DomRegion.Empty; }
1421
volatile IMethod constructor;
1423
public IMethod Constructor {
1425
IMethod ctor = this.constructor;
1427
foreach (IMethod candidate in this.AttributeType.GetConstructors(m => m.Parameters.Count == 1)) {
1428
if (candidate.Parameters[0].Type.Equals(this.PositionalArguments[0].Type)) {
808
targetCollection.Add(a);
1433
this.constructor = ctor;
810
} catch (Exception) {
811
// occurs when Cecil can't decode an argument
818
#region Read Constant Value
819
public IConstantValue ReadConstantValue(CustomAttributeArgument arg)
821
object value = arg.Value;
822
if (value is CustomAttributeArgument) {
823
// Cecil uses this representation for boxed values
824
arg = (CustomAttributeArgument)value;
827
ITypeReference type = ReadTypeReference(arg.Type);
828
CustomAttributeArgument[] array = value as CustomAttributeArgument[];
830
// TODO: write unit test for this
831
// TODO: are multi-dimensional arrays possible as well?
832
throw new NotImplementedException();
835
TypeReference valueType = value as TypeReference;
836
if (valueType != null)
837
value = ReadTypeReference(valueType);
838
return new SimpleConstantValue(type, value);
1439
public IList<ResolveResult> PositionalArguments { get; internal set; }
1441
public IList<KeyValuePair<IMember, ResolveResult>> NamedArguments { get; internal set; }
842
1446
#region Read Type Definition
843
sealed class CecilTypeDefinition : DefaultTypeDefinition
845
internal TypeDefinition typeDefinition;
847
public CecilTypeDefinition(IProjectContent pc, TypeDefinition typeDefinition)
848
: base(pc, typeDefinition.Namespace, ReflectionHelper.SplitTypeParameterCountFromReflectionName(typeDefinition.Name))
850
this.typeDefinition = typeDefinition;
851
InitTypeParameters();
854
public CecilTypeDefinition(CecilTypeDefinition parentType, string name, TypeDefinition typeDefinition)
855
: base(parentType, name)
857
this.typeDefinition = typeDefinition;
858
InitTypeParameters();
861
void InitTypeParameters()
863
// Type parameters are initialized within the constructor so that the class can be put into the type storage
864
// before the rest of the initialization runs - this allows it to be available for early binding as soon as possible.
1447
DefaultUnresolvedTypeDefinition CreateTopLevelTypeDefinition(TypeDefinition typeDefinition)
1449
string name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(typeDefinition.Name);
1450
var td = new DefaultUnresolvedTypeDefinition(typeDefinition.Namespace, name);
1451
InitTypeParameters(typeDefinition, td);
1455
static void InitTypeParameters(TypeDefinition typeDefinition, DefaultUnresolvedTypeDefinition td)
1457
// Type parameters are initialized within the constructor so that the class can be put into the type storage
1458
// before the rest of the initialization runs - this allows it to be available for early binding as soon as possible.
1459
for (int i = 0; i < typeDefinition.GenericParameters.Count; i++) {
1460
if (typeDefinition.GenericParameters[i].Position != i)
1461
throw new InvalidOperationException("g.Position != i");
1462
td.TypeParameters.Add(new DefaultUnresolvedTypeParameter(
1463
EntityType.TypeDefinition, i, typeDefinition.GenericParameters[i].Name));
1467
void InitTypeDefinition(TypeDefinition typeDefinition, DefaultUnresolvedTypeDefinition td)
1469
InitTypeModifiers(typeDefinition, td);
1471
if (typeDefinition.HasGenericParameters) {
865
1472
for (int i = 0; i < typeDefinition.GenericParameters.Count; i++) {
866
if (typeDefinition.GenericParameters[i].Position != i)
867
throw new InvalidOperationException("g.Position != i");
868
this.TypeParameters.Add(new DefaultTypeParameter(
869
EntityType.TypeDefinition, i, typeDefinition.GenericParameters[i].Name));
873
public void Init(CecilLoader loader)
875
loader.CancellationToken.ThrowIfCancellationRequested();
878
if (typeDefinition.HasGenericParameters) {
879
for (int i = 0; i < typeDefinition.GenericParameters.Count; i++) {
880
loader.AddConstraints(this, (DefaultTypeParameter)this.TypeParameters[i], typeDefinition.GenericParameters[i]);
884
InitNestedTypes(loader); // nested types can be initialized only after generic parameters were created
886
loader.AddAttributes(typeDefinition, this);
888
this.HasExtensionMethods = HasExtensionAttribute(typeDefinition);
891
if (typeDefinition.IsEnum) {
892
foreach (FieldDefinition enumField in typeDefinition.Fields) {
893
if (!enumField.IsStatic) {
894
BaseTypes.Add(loader.ReadTypeReference(enumField.FieldType, entity: this));
899
if (typeDefinition.BaseType != null) {
900
BaseTypes.Add(loader.ReadTypeReference(typeDefinition.BaseType, entity: this));
902
if (typeDefinition.HasInterfaces) {
903
foreach (TypeReference iface in typeDefinition.Interfaces) {
904
BaseTypes.Add(loader.ReadTypeReference(iface, entity: this));
910
if (!loader.HasCecilReferences)
911
this.typeDefinition = null;
912
Freeze(); // freeze after initialization
913
ApplyInterningProvider(loader.InterningProvider);
916
void InitNestedTypes(CecilLoader loader)
918
if (!typeDefinition.HasNestedTypes)
920
foreach (TypeDefinition nestedType in typeDefinition.NestedTypes) {
921
TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
922
if (loader.IncludeInternalMembers
923
|| visibility == TypeAttributes.NestedPublic
924
|| visibility == TypeAttributes.NestedFamily
925
|| visibility == TypeAttributes.NestedFamORAssem)
927
string name = nestedType.Name;
928
int pos = name.LastIndexOf('/');
930
name = name.Substring(pos + 1);
931
if (name.Length == 0 || name[0] == '<')
933
name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(name);
934
NestedTypes.Add(new CecilTypeDefinition(this, name, nestedType));
937
foreach (CecilTypeDefinition nestedType in this.NestedTypes) {
938
nestedType.Init(loader);
944
TypeDefinition td = this.typeDefinition;
946
if (td.IsInterface) {
947
this.Kind = TypeKind.Interface;
948
} else if (td.IsEnum) {
949
this.Kind = TypeKind.Enum;
950
} else if (td.IsValueType) {
951
this.Kind = TypeKind.Struct;
952
} else if (IsDelegate(td)) {
953
this.Kind = TypeKind.Delegate;
954
} else if (IsModule(td)) {
955
this.Kind = TypeKind.Module;
957
this.Kind = TypeKind.Class;
959
this.IsSealed = td.IsSealed;
960
this.IsAbstract = td.IsAbstract;
961
switch (td.Attributes & TypeAttributes.VisibilityMask) {
962
case TypeAttributes.NotPublic:
963
case TypeAttributes.NestedAssembly:
964
this.Accessibility = Accessibility.Internal;
966
case TypeAttributes.Public:
967
case TypeAttributes.NestedPublic:
968
this.Accessibility = Accessibility.Public;
970
case TypeAttributes.NestedPrivate:
971
this.Accessibility = Accessibility.Private;
973
case TypeAttributes.NestedFamily:
974
this.Accessibility = Accessibility.Protected;
976
case TypeAttributes.NestedFamANDAssem:
977
this.Accessibility = Accessibility.ProtectedAndInternal;
979
case TypeAttributes.NestedFamORAssem:
980
this.Accessibility = Accessibility.ProtectedOrInternal;
982
case TypeAttributes.LayoutMask:
983
this.Accessibility = Accessibility;
988
static bool IsDelegate(TypeDefinition type)
990
if (type.BaseType == null)
993
return type.BaseType.FullName == "System.Delegate"
994
|| type.BaseType.FullName == "System.MulticastDelegate";
997
static bool IsModule(TypeDefinition type)
999
if (!type.HasCustomAttributes)
1001
foreach (var att in type.CustomAttributes) {
1002
if (att.AttributeType.FullName == "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute"
1003
|| att.AttributeType.FullName == "System.Runtime.CompilerServices.CompilerGlobalScopeAttribute")
1011
void InitMembers(CecilLoader loader)
1013
this.AddDefaultConstructorIfRequired = (this.Kind == TypeKind.Struct || this.Kind == TypeKind.Enum);
1014
if (typeDefinition.HasMethods) {
1015
foreach (MethodDefinition method in typeDefinition.Methods) {
1016
if (loader.IsVisible(method.Attributes)) {
1017
EntityType type = EntityType.Method;
1018
if (method.IsSpecialName) {
1019
if (method.IsConstructor)
1020
type = EntityType.Constructor;
1021
else if (method.Name.StartsWith("op_", StringComparison.Ordinal))
1022
type = EntityType.Operator;
1026
this.Methods.Add(loader.ReadMethod(method, this, type));
1030
if (typeDefinition.HasFields) {
1031
foreach (FieldDefinition field in typeDefinition.Fields) {
1032
if (loader.IsVisible(field.Attributes) && !field.IsSpecialName) {
1033
this.Fields.Add(loader.ReadField(field, this));
1037
if (typeDefinition.HasProperties) {
1038
string defaultMemberName = null;
1039
var defaultMemberAttribute = typeDefinition.CustomAttributes.FirstOrDefault(
1040
a => a.AttributeType.FullName == typeof(System.Reflection.DefaultMemberAttribute).FullName);
1041
if (defaultMemberAttribute != null && defaultMemberAttribute.ConstructorArguments.Count == 1) {
1042
defaultMemberName = defaultMemberAttribute.ConstructorArguments[0].Value as string;
1044
foreach (PropertyDefinition property in typeDefinition.Properties) {
1045
bool getterVisible = property.GetMethod != null && loader.IsVisible(property.GetMethod.Attributes);
1046
bool setterVisible = property.SetMethod != null && loader.IsVisible(property.SetMethod.Attributes);
1047
if (getterVisible || setterVisible) {
1048
EntityType type = property.Name == defaultMemberName ? EntityType.Indexer : EntityType.Property;
1049
this.Properties.Add(loader.ReadProperty(property, this, type));
1053
if (typeDefinition.HasEvents) {
1054
foreach (EventDefinition ev in typeDefinition.Events) {
1055
if (ev.AddMethod != null && loader.IsVisible(ev.AddMethod.Attributes)) {
1056
this.Events.Add(loader.ReadEvent(ev, this));
1473
AddConstraints((DefaultUnresolvedTypeParameter)td.TypeParameters[i], typeDefinition.GenericParameters[i]);
1477
InitNestedTypes(typeDefinition, td); // nested types can be initialized only after generic parameters were created
1478
AddAttributes(typeDefinition, td);
1479
td.HasExtensionMethods = HasExtensionAttribute(typeDefinition);
1482
if (typeDefinition.IsEnum) {
1483
foreach (FieldDefinition enumField in typeDefinition.Fields) {
1484
if (!enumField.IsStatic) {
1485
td.BaseTypes.Add(ReadTypeReference(enumField.FieldType));
1490
if (typeDefinition.BaseType != null) {
1491
td.BaseTypes.Add(ReadTypeReference(typeDefinition.BaseType));
1493
if (typeDefinition.HasInterfaces) {
1494
foreach (TypeReference iface in typeDefinition.Interfaces) {
1495
td.BaseTypes.Add(ReadTypeReference(iface));
1500
InitMembers(typeDefinition, td);
1501
if (HasCecilReferences)
1502
typeSystemTranslationTable[td] = typeDefinition;
1503
if (this.InterningProvider != null) {
1504
td.ApplyInterningProvider(this.InterningProvider);
1509
void InitNestedTypes(TypeDefinition typeDefinition, DefaultUnresolvedTypeDefinition td)
1511
if (!typeDefinition.HasNestedTypes)
1513
foreach (TypeDefinition nestedTypeDef in typeDefinition.NestedTypes) {
1514
TypeAttributes visibility = nestedTypeDef.Attributes & TypeAttributes.VisibilityMask;
1515
if (this.IncludeInternalMembers
1516
|| visibility == TypeAttributes.NestedPublic
1517
|| visibility == TypeAttributes.NestedFamily
1518
|| visibility == TypeAttributes.NestedFamORAssem)
1520
string name = nestedTypeDef.Name;
1521
int pos = name.LastIndexOf('/');
1523
name = name.Substring(pos + 1);
1524
if (name.Length == 0 || name[0] == '<')
1526
name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(name);
1527
var nestedType = new DefaultUnresolvedTypeDefinition(td, name);
1528
InitTypeParameters(nestedTypeDef, nestedType);
1529
td.NestedTypes.Add(nestedType);
1530
InitTypeDefinition(nestedTypeDef, nestedType);
1535
static void InitTypeModifiers(TypeDefinition typeDefinition, DefaultUnresolvedTypeDefinition td)
1538
if (typeDefinition.IsInterface) {
1539
td.Kind = TypeKind.Interface;
1540
} else if (typeDefinition.IsEnum) {
1541
td.Kind = TypeKind.Enum;
1542
} else if (typeDefinition.IsValueType) {
1543
td.Kind = TypeKind.Struct;
1544
} else if (IsDelegate(typeDefinition)) {
1545
td.Kind = TypeKind.Delegate;
1546
} else if (IsModule(typeDefinition)) {
1547
td.Kind = TypeKind.Module;
1549
td.Kind = TypeKind.Class;
1551
td.IsSealed = typeDefinition.IsSealed;
1552
td.IsAbstract = typeDefinition.IsAbstract;
1553
switch (typeDefinition.Attributes & TypeAttributes.VisibilityMask) {
1554
case TypeAttributes.NotPublic:
1555
case TypeAttributes.NestedAssembly:
1556
td.Accessibility = Accessibility.Internal;
1558
case TypeAttributes.Public:
1559
case TypeAttributes.NestedPublic:
1560
td.Accessibility = Accessibility.Public;
1562
case TypeAttributes.NestedPrivate:
1563
td.Accessibility = Accessibility.Private;
1565
case TypeAttributes.NestedFamily:
1566
td.Accessibility = Accessibility.Protected;
1568
case TypeAttributes.NestedFamANDAssem:
1569
td.Accessibility = Accessibility.ProtectedAndInternal;
1571
case TypeAttributes.NestedFamORAssem:
1572
td.Accessibility = Accessibility.ProtectedOrInternal;
1577
static bool IsDelegate(TypeDefinition type)
1579
if (type.BaseType == null)
1582
return type.BaseType.FullName == "System.Delegate"
1583
|| type.BaseType.FullName == "System.MulticastDelegate";
1586
static bool IsModule(TypeDefinition type)
1588
if (!type.HasCustomAttributes)
1590
foreach (var att in type.CustomAttributes) {
1591
if (att.AttributeType.FullName == "Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute"
1592
|| att.AttributeType.FullName == "System.Runtime.CompilerServices.CompilerGlobalScopeAttribute")
1600
void InitMembers(TypeDefinition typeDefinition, DefaultUnresolvedTypeDefinition td)
1602
td.AddDefaultConstructorIfRequired = (td.Kind == TypeKind.Struct || td.Kind == TypeKind.Enum);
1603
if (typeDefinition.HasMethods) {
1604
foreach (MethodDefinition method in typeDefinition.Methods) {
1605
if (IsVisible(method.Attributes) && !IsAccessor(method.SemanticsAttributes)) {
1606
EntityType type = EntityType.Method;
1607
if (method.IsSpecialName) {
1608
if (method.IsConstructor)
1609
type = EntityType.Constructor;
1610
else if (method.Name.StartsWith("op_", StringComparison.Ordinal))
1611
type = EntityType.Operator;
1613
td.Members.Add(ReadMethod(method, td, type));
1617
if (typeDefinition.HasFields) {
1618
foreach (FieldDefinition field in typeDefinition.Fields) {
1619
if (IsVisible(field.Attributes) && !field.IsSpecialName) {
1620
td.Members.Add(ReadField(field, td));
1624
if (typeDefinition.HasProperties) {
1625
string defaultMemberName = null;
1626
var defaultMemberAttribute = typeDefinition.CustomAttributes.FirstOrDefault(
1627
a => a.AttributeType.FullName == typeof(System.Reflection.DefaultMemberAttribute).FullName);
1628
if (defaultMemberAttribute != null && defaultMemberAttribute.ConstructorArguments.Count == 1) {
1629
defaultMemberName = defaultMemberAttribute.ConstructorArguments[0].Value as string;
1631
foreach (PropertyDefinition property in typeDefinition.Properties) {
1632
bool getterVisible = property.GetMethod != null && IsVisible(property.GetMethod.Attributes);
1633
bool setterVisible = property.SetMethod != null && IsVisible(property.SetMethod.Attributes);
1634
if (getterVisible || setterVisible) {
1635
EntityType type = property.Name == defaultMemberName ? EntityType.Indexer : EntityType.Property;
1636
td.Members.Add(ReadProperty(property, td, type));
1640
if (typeDefinition.HasEvents) {
1641
foreach (EventDefinition ev in typeDefinition.Events) {
1642
if (ev.AddMethod != null && IsVisible(ev.AddMethod.Attributes)) {
1643
td.Members.Add(ReadEvent(ev, td));
1649
static bool IsAccessor(MethodSemanticsAttributes semantics)
1651
return !(semantics == MethodSemanticsAttributes.None || semantics == MethodSemanticsAttributes.Other);
1064
1655
#region Read Method
1065
public IMethod ReadMethod(MethodDefinition method, ITypeDefinition parentType, EntityType methodType = EntityType.Method)
1656
[CLSCompliant(false)]
1657
public IUnresolvedMethod ReadMethod(MethodDefinition method, IUnresolvedTypeDefinition parentType, EntityType methodType = EntityType.Method)
1067
DefaultMethod m = new DefaultMethod(parentType, method.Name);
1661
DefaultUnresolvedMethod m = new DefaultUnresolvedMethod(parentType, method.Name);
1068
1662
m.EntityType = methodType;
1069
1663
if (method.HasGenericParameters) {
1070
1664
for (int i = 0; i < method.GenericParameters.Count; i++) {
1071
1665
if (method.GenericParameters[i].Position != i)
1072
1666
throw new InvalidOperationException("g.Position != i");
1073
m.TypeParameters.Add(new DefaultTypeParameter(
1667
m.TypeParameters.Add(new DefaultUnresolvedTypeParameter(
1074
1668
EntityType.Method, i, method.GenericParameters[i].Name));
1076
1670
for (int i = 0; i < method.GenericParameters.Count; i++) {
1077
AddConstraints(m, (DefaultTypeParameter)m.TypeParameters[i], method.GenericParameters[i]);
1671
AddConstraints((DefaultUnresolvedTypeParameter)m.TypeParameters[i], method.GenericParameters[i]);
1081
if (method.IsConstructor)
1082
m.ReturnType = parentType;
1084
m.ReturnType = ReadTypeReference(method.ReturnType, typeAttributes: method.MethodReturnType, entity: m);
1675
m.ReturnType = ReadTypeReference(method.ReturnType, typeAttributes: method.MethodReturnType);
1086
1677
if (HasAnyAttributes(method))
1087
1678
AddAttributes(method, m.Attributes, m.ReturnTypeAttributes);