public IMethod ResolveMethod(int token, IGenericContext genericContext)
        {
            if (this.tokenResolutions != null && this.tokenResolutions.Count >= token)
            {
                return this.tokenResolutions[token - 1] as IMethod;
            }

            return this.method.Module.ResolveMethod(token, genericContext);
        }
        public IType ResolveType(int token, IGenericContext genericContext)
        {
            if (tokenResolutions != null && tokenResolutions.Count >= token)
            {
                return tokenResolutions[token - 1] as IType;
            }

            return this.method.Module.ResolveType(token, genericContext);
        }
Example #3
0
		internal MethodBody GetMethodBody(IGenericContext context)
		{
			if ((GetMethodImplementationFlags() & MethodImplAttributes.CodeTypeMask) != MethodImplAttributes.IL)
			{
				// method is not IL
				return null;
			}
			int rva = module.MethodDef.records[index].RVA;
			return rva == 0 ? null : new MethodBody(module, rva, context);
		}
		internal static FieldSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
		{
			if (br.ReadByte() != FIELD)
			{
				throw new BadImageFormatException();
			}
			CustomModifiers mods = CustomModifiers.Read(module, br, context);
			Type fieldType = ReadType(module, br, context);
			return new FieldSignature(fieldType, mods);
		}
Example #5
0
		internal ExceptionHandlingClause(ModuleReader module, int flags, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int classTokenOrfilterOffset, IGenericContext context)
		{
			this.flags = flags;
			this.tryOffset = tryOffset;
			this.tryLength = tryLength;
			this.handlerOffset = handlerOffset;
			this.handlerLength = handlerLength;
			this.catchType = flags == (int)ExceptionHandlingClauseOptions.Clause && classTokenOrfilterOffset != 0 ? module.ResolveType(classTokenOrfilterOffset, context) : null;
			this.filterOffset = flags == (int)ExceptionHandlingClauseOptions.Filter ? classTokenOrfilterOffset : 0;
		}
        /// <summary>
        /// </summary>
        /// <param name="methodDef">
        /// </param>
        /// <param name="genericContext">
        /// </param>
        internal MetadataMethodAdapter(MethodSymbol methodDef, IGenericContext genericContext)
            : this(methodDef)
        {
            this.GenericContext = genericContext;

            var peMethodSymbol = methodDef as PEMethodSymbol;
            if (peMethodSymbol != null)
            {
                this.Token = MetadataTokens.GetToken(peMethodSymbol.Handle);
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="token">
        /// </param>
        /// <param name="genericContext">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="KeyNotFoundException">
        /// </exception>
        public IField ResolveField(int token, IGenericContext genericContext)
        {
            var peModuleSymbol = this.moduleDef as PEModuleSymbol;

            var fieldHandle = MetadataTokens.Handle(token);

            var fieldSymbol = peModuleSymbol.GetMetadataDecoder(genericContext).GetSymbolForILToken(fieldHandle) as FieldSymbol;
            if (fieldSymbol != null)
            {
                return new MetadataFieldAdapter(SubstituteFieldSymbolIfNeeded(fieldSymbol, genericContext));
            }

            return null;
        }
        /// <summary>
        /// </summary>
        /// <param name="token">
        /// </param>
        /// <param name="genericContext">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public IMember ResolveMember(int token, IGenericContext genericContext)
        {
            var peModuleSymbol = this.moduleDef as PEModuleSymbol;

            var methodHandle = MetadataTokens.Handle(token);

            var methodSymbol = peModuleSymbol.GetMetadataDecoder(genericContext).GetSymbolForILToken(methodHandle) as MethodSymbol;
            if (methodSymbol != null)
            {
                if (methodSymbol.MethodKind == MethodKind.Constructor)
                {
                    return new MetadataConstructorAdapter(SubstituteMethodSymbolIfNeeded(methodSymbol, genericContext));
                }

                return new MetadataMethodAdapter(SubstituteMethodSymbolIfNeeded(methodSymbol, genericContext));
            }

            throw new NotImplementedException();
        }
Example #9
0
		private static Type ReadGenericInst(ModuleReader module, ByteReader br, IGenericContext context)
		{
			Type type;
			switch (br.ReadByte())
			{
				case ELEMENT_TYPE_CLASS:
					type = ReadTypeDefOrRefEncoded(module, br, context).MarkNotValueType();
					break;
				case ELEMENT_TYPE_VALUETYPE:
					type = ReadTypeDefOrRefEncoded(module, br, context).MarkValueType();
					break;
				default:
					throw new BadImageFormatException();
			}
			if (!type.__IsMissing && !type.IsGenericTypeDefinition)
			{
				throw new BadImageFormatException();
			}
			int genArgCount = br.ReadCompressedInt();
			Type[] args = new Type[genArgCount];
			Type[][] reqmod = null;
			Type[][] optmod = null;
			for (int i = 0; i < genArgCount; i++)
			{
				// LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it
				CustomModifiers mods = ReadCustomModifiers(module, br, context);
				if (mods.required != null || mods.optional != null)
				{
					if (reqmod == null)
					{
						reqmod = new Type[genArgCount][];
						optmod = new Type[genArgCount][];
					}
					reqmod[i] = mods.required;
					optmod[i] = mods.optional;
				}
				args[i] = ReadType(module, br, context);
			}
			return GenericTypeInstance.Make(type, args, reqmod, optmod);
		}
Example #10
0
        public TypeReference ImportType(TypeReference type, IGenericContext context)
        {
            if (Mixin.IsTypeSpecification(type))
                return ImportTypeSpecification(type, context);

            var reference = new TypeReference(
                type.Namespace,
                type.Name,
                module,
                ImportScope(type.Scope),
                type.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(reference);

            if (type.IsNested)
                reference.DeclaringType = ImportType(type.DeclaringType, context);

            if (type.HasGenericParameters)
                ImportGenericParameters(reference, type);

            return reference;
        }
Example #11
0
		public TypeReference ImportType (Type type, IGenericContext context, ImportGenericKind import_kind)
		{
			if (IsTypeSpecification (type) || ImportOpenGenericType (type, import_kind))
				return ImportTypeSpecification (type, context);

			var reference = new TypeReference (
				string.Empty,
				type.Name,
				module,
				ImportScope (type.Assembly),
				type.IsValueType);

			reference.etype = ImportElementType (type);

			if (IsNestedType (type))
				reference.DeclaringType = ImportType (type.DeclaringType, context, import_kind);
			else
				reference.Namespace = type.Namespace;

			if (type.IsGenericType)
				ImportGenericParameters (reference, type.GetGenericArguments ());

			return reference;
		}
        /// <summary>
        /// </summary>
        /// <param name="fullName">
        /// </param>
        /// <param name="genericContext">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="KeyNotFoundException">
        /// </exception>
        public IType ResolveType(string fullName, IGenericContext genericContext)
        {
            var peModuleSymbol = this.moduleDef as PEModuleSymbol;

            var typeSymbol = peModuleSymbol.GetMetadataDecoder(genericContext).GetTypeSymbolForSerializedType(fullName);
            if (typeSymbol.TypeKind == TypeKind.Error)
            {
                // try to find it in CoreLib
                typeSymbol =
                    new MetadataDecoder(peModuleSymbol.ContainingAssembly.CorLibrary.Modules[0] as PEModuleSymbol).GetTypeSymbolForSerializedType(fullName);
            }

            if (typeSymbol != null && typeSymbol.TypeKind != TypeKind.Error)
            {
                if (genericContext == null)
                {
                    return typeSymbol.OriginalDefinition.ToAdapter();
                }

                return typeSymbol.ToAdapter();
            }

            throw new KeyNotFoundException();
        }
 /// <summary>
 /// </summary>
 /// <param name="token">
 /// </param>
 /// <param name="genericContext">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="KeyNotFoundException">
 /// </exception>
 public IType ResolveType(int token, IGenericContext genericContext)
 {
     var peModuleSymbol = this.moduleDef as PEModuleSymbol;
     var typeDefHandle = MetadataTokens.Handle(token);
     var typeSymbol = peModuleSymbol.GetMetadataDecoder(genericContext).GetSymbolForILToken(typeDefHandle) as TypeSymbol;
     return SubstituteTypeSymbolIfNeeded(typeSymbol, genericContext).ToAdapter();
 }
        /// <summary>
        /// </summary>
        /// <param name="token">
        /// </param>
        /// <param name="genericContext">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="KeyNotFoundException">
        /// </exception>
        public object ResolveToken(int token, IGenericContext genericContext)
        {
            var peModuleSymbol = this.moduleDef as PEModuleSymbol;

            var typeDefHandle = MetadataTokens.Handle(token);
            var symbolForIlToken = peModuleSymbol.GetMetadataDecoder(genericContext).GetSymbolForILToken(typeDefHandle);
            var typeSymbol = symbolForIlToken as TypeSymbol;
            if (typeSymbol != null && typeSymbol.TypeKind != TypeKind.Error)
            {
                return SubstituteTypeSymbolIfNeeded(typeSymbol, genericContext).ToAdapter();
            }

            var fieldSymbol = symbolForIlToken as FieldSymbol;
            if (fieldSymbol != null)
            {
                return new MetadataFieldAdapter(SubstituteFieldSymbolIfNeeded(fieldSymbol, genericContext));
            }

            var methodSymbol = symbolForIlToken as MethodSymbol;
            if (methodSymbol != null)
            {
                return new MetadataMethodAdapter(SubstituteMethodSymbolIfNeeded(methodSymbol, genericContext));
            }

            throw new KeyNotFoundException();
        }
        private static MethodSymbol ConstructMethodSymbol(MethodSymbol methodSymbol, AbstractTypeParameterMap methodTypeSubstitution, IGenericContext genericContext)
        {
            var metadataGenericContext = genericContext as MetadataGenericContext;
            if (metadataGenericContext != null)
            {
                var customTypeSubstitution = metadataGenericContext.CustomTypeSubstitution;
                if (customTypeSubstitution != null)
                {
                    return new ConstructedMethodSymbol(methodSymbol, GetTypeArguments(methodSymbol.OriginalDefinition.TypeParameters, customTypeSubstitution, null));
                }
            }

            var metadataMethodAdapter = genericContext.MethodSpecialization as MetadataMethodAdapter;
            if (metadataMethodAdapter != null)
            {
                var methodSymbolContext = metadataMethodAdapter.MethodDef;
                var constructedFrom = methodSymbol.ConstructedFrom;
                return new ConstructedMethodSymbol(constructedFrom.ConstructedFrom, GetTypeArguments(constructedFrom.TypeParameters, methodSymbolContext, methodTypeSubstitution));
            }

            var metadataTypeAdapter = genericContext.TypeSpecialization as MetadataTypeAdapter;
            if (metadataTypeAdapter != null)
            {
                var namedTypeSymbolContext = metadataTypeAdapter.TypeDef as NamedTypeSymbol;
                var constructedFrom = methodSymbol.ConstructedFrom;
                return new ConstructedMethodSymbol(constructedFrom.ConstructedFrom, GetTypeArguments(constructedFrom.TypeParameters, namedTypeSymbolContext, methodTypeSubstitution));
            }

            return null;
        }
        internal static MethodSymbol SubstituteMethodSymbolIfNeeded(MethodSymbol methodSymbol, IGenericContext genericContext)
        {
            if (MetadataGenericContext.IsNullOrEmptyOrNoSpecializations(genericContext))
            {
                return methodSymbol;
            }

            var method = new MetadataMethodAdapter(methodSymbol);
            if (!method.IsGenericMethodDefinition && !method.DeclaringType.IsGenericTypeDefinition)
            {
                return methodSymbol;
            }

            var resolvedMethodSymbol = methodSymbol;
            if (method.DeclaringType.IsGenericTypeDefinition)
            {
                var constructedContainingType = SubstituteTypeSymbolIfNeeded(methodSymbol.ContainingType, genericContext);
                var substitutedNamedTypeSymbol = constructedContainingType as SubstitutedNamedTypeSymbol;
                if (substitutedNamedTypeSymbol != null)
                {
                    resolvedMethodSymbol = new SubstitutedMethodSymbol(
                        substitutedNamedTypeSymbol,
                        methodSymbol.ConstructedFrom.OriginalDefinition);
                }
                else
                {
                    var typeDef = (method.DeclaringType as MetadataTypeAdapter).TypeDef;
                    constructedContainingType = SubstituteTypeSymbolIfNeeded(typeDef, genericContext);
                    resolvedMethodSymbol = (constructedContainingType as ArrayTypeSymbol).GetMembers(methodSymbol.Name)[0] as MethodSymbol;
                }
            }

            if (method.IsGenericMethodDefinition || method.IsGenericMethod)
            {
                return ConstructMethodSymbol(resolvedMethodSymbol, methodSymbol.TypeSubstitution, genericContext);
            }

            return resolvedMethodSymbol;
        }
        private static FieldSymbol SubstituteFieldSymbolIfNeeded(FieldSymbol fieldSymbol, IGenericContext genericContext)
        {
            if (MetadataGenericContext.IsNullOrEmptyOrNoSpecializations(genericContext))
            {
                return fieldSymbol;
            }

            var resolvedFieldSymbol = fieldSymbol;
            var field = new MetadataFieldAdapter(fieldSymbol);
            if (field.DeclaringType.IsGenericTypeDefinition)
            {
                var constructedContainingType = SubstituteTypeSymbolIfNeeded(fieldSymbol.ContainingType, genericContext);
                var substitutedNamedTypeSymbol = constructedContainingType as SubstitutedNamedTypeSymbol;
                resolvedFieldSymbol = new SubstitutedFieldSymbol(substitutedNamedTypeSymbol, fieldSymbol);
                return resolvedFieldSymbol;
            }

            return resolvedFieldSymbol;
        }
Example #18
0
		MethodSpecification ImportMethodSpecification (MethodReference method, IGenericContext context)
		{
			if (!method.IsGenericInstance)
				throw new NotSupportedException ();

			var instance = (GenericInstanceMethod) method;
			var element_method = ImportMethod (instance.ElementMethod, context);
			var imported_instance = new GenericInstanceMethod (element_method);

			var arguments = instance.GenericArguments;
			var imported_arguments = imported_instance.GenericArguments;

			for (int i = 0; i < arguments.Count; i++)
				imported_arguments.Add (ImportType (arguments [i], context));

			return imported_instance;
		}
        internal static TypeSymbol SubstituteTypeSymbolIfNeeded(TypeSymbol typeSymbol, IGenericContext genericContext)
        {
            if (typeSymbol == null || typeSymbol.TypeKind == TypeKind.Error)
            {
                throw new KeyNotFoundException();
            }

            if (MetadataGenericContext.IsNullOrEmptyOrNoSpecializations(genericContext))
            {
                return typeSymbol;
            }

            var typeSubstitution = GetTypeSubstitutionMap(genericContext);
            var resolvedType = typeSubstitution.SubstituteType(typeSymbol);
            return resolvedType;
        }
Example #20
0
 /// <summary>
 /// </summary>
 /// <param name="genericContext">
 /// </param>
 /// <returns>
 /// </returns>
 public IMethodBody GetMethodBody(IGenericContext genericContext = null)
 {
     return new SynthesizedDummyMethodBody();
 }
Example #21
0
 internal TrackingGenericContext(IGenericContext context)
 {
     this.context = context;
 }
Example #22
0
		internal static __StandAloneMethodSig ReadStandAloneMethodSig(ModuleReader module, ByteReader br, IGenericContext context)
		{
			CallingConventions callingConvention = 0;
			System.Runtime.InteropServices.CallingConvention unmanagedCallingConvention = 0;
			bool unmanaged;
			byte flags = br.ReadByte();
			switch (flags & 7)
			{
				case DEFAULT:
					callingConvention = CallingConventions.Standard;
					unmanaged = false;
					break;
				case 0x01:	// C
					unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl;
					unmanaged = true;
					break;
				case 0x02:	// STDCALL
					unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall;
					unmanaged = true;
					break;
				case 0x03:	// THISCALL
					unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.ThisCall;
					unmanaged = true;
					break;
				case 0x04:	// FASTCALL
					unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.FastCall;
					unmanaged = true;
					break;
				case VARARG:
					callingConvention = CallingConventions.VarArgs;
					unmanaged = false;
					break;
				default:
					throw new BadImageFormatException();
			}
			if ((flags & HASTHIS) != 0)
			{
				callingConvention |= CallingConventions.HasThis;
			}
			if ((flags & EXPLICITTHIS) != 0)
			{
				callingConvention |= CallingConventions.ExplicitThis;
			}
			if ((flags & GENERIC) != 0)
			{
				throw new BadImageFormatException();
			}
			int paramCount = br.ReadCompressedInt();
			SkipCustomModifiers(br);
			Type returnType = ReadRetType(module, br, context);
			List<Type> parameterTypes = new List<Type>();
			List<Type> optionalParameterTypes = new List<Type>();
			List<Type> curr = parameterTypes;
			for (int i = 0; i < paramCount; i++)
			{
				if (br.PeekByte() == SENTINEL)
				{
					br.ReadByte();
					curr = optionalParameterTypes;
				}
				SkipCustomModifiers(br);
				curr.Add(ReadParam(module, br, context));
			}
			return new __StandAloneMethodSig(unmanaged, unmanagedCallingConvention, callingConvention, returnType, parameterTypes.ToArray(), optionalParameterTypes.ToArray());
		}
Example #23
0
		public TypeReference ImportType (Type type, IGenericContext context)
		{
			return ImportType (type, context, ImportGenericKind.Open);
		}
        private static AbstractTypeParameterMap GetTypeSubstitutionMap(IGenericContext genericContext)
        {
            if (MetadataGenericContext.IsNullOrEmptyOrNoSpecializations(genericContext))
            {
                throw new ArgumentException("genericContext");
            }

            var metadataGenericContext = genericContext as MetadataGenericContext;
            if (metadataGenericContext != null && metadataGenericContext.CustomTypeSubstitution != null)
            {
                return metadataGenericContext.CustomTypeSubstitution;
            }


            if (genericContext.MethodSpecialization != null)
            {
                var metadataMethodAdapter = (genericContext.MethodSpecialization as MetadataMethodAdapter);
                if (metadataMethodAdapter != null)
                {
                    return metadataMethodAdapter.MethodDef.TypeSubstitution;
                }
            }

            if (genericContext.TypeSpecialization != null)
            {
                var metadataTypeAdapter = (genericContext.TypeSpecialization as MetadataTypeAdapter);
                if (metadataTypeAdapter != null)
                {
                    var namedTypeSymbol = metadataTypeAdapter.TypeDef as NamedTypeSymbol;
                    if (namedTypeSymbol != null)
                    {
                        return namedTypeSymbol.TypeSubstitution;
                    }
                }
            }

            throw new Exception("Context is empty");
        }
Example #25
0
			internal UnboundGenericMethodContext(IGenericContext original)
			{
				this.original = original;
			}
Example #26
0
		public MethodReference ImportMethod (MethodReference method, IGenericContext context)
		{
			if (method.IsGenericInstance)
				return ImportMethodSpecification (method, context);

			var declaring_type = ImportType (method.DeclaringType, context);

			var reference = new MethodReference {
				Name = method.Name,
				HasThis = method.HasThis,
				ExplicitThis = method.ExplicitThis,
				DeclaringType = declaring_type,
			};

			reference.CallingConvention = method.CallingConvention;

			if (method.HasGenericParameters)
				ImportGenericParameters (reference, method);

			reference.ReturnType = ImportType (method.ReturnType, context ?? reference);

			if (!method.HasParameters)
				return reference;

			var reference_parameters = reference.Parameters;

			var parameters = method.Parameters;
			for (int i = 0; i < parameters.Count; i++)
				reference_parameters.Add (
					new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference)));

			return reference;
		}
Example #27
0
 internal override Type ResolveType(int metadataToken, IGenericContext context)
 {
     int index = (metadataToken & 0xFFFFFF) - 1;
     if (index < 0)
     {
         throw TokenOutOfRangeException(metadataToken);
     }
     else if ((metadataToken >> 24) == TypeDefTable.Index && index < TypeDef.RowCount)
     {
         PopulateTypeDef();
         return typeDefs[index];
     }
     else if ((metadataToken >> 24) == TypeRefTable.Index && index < TypeRef.RowCount)
     {
         if (typeRefs == null)
         {
             typeRefs = new Type[TypeRef.records.Length];
         }
         if (typeRefs[index] == null)
         {
             int scope = TypeRef.records[index].ResolutionScope;
             switch (scope >> 24)
             {
                 case AssemblyRefTable.Index:
                     {
                         Assembly assembly = ResolveAssemblyRef((scope & 0xFFFFFF) - 1);
                         TypeName typeName = GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName);
                         typeRefs[index] = assembly.ResolveType(this, typeName);
                         break;
                     }
                 case TypeRefTable.Index:
                     {
                         Type outer = ResolveType(scope, null);
                         TypeName typeName = GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName);
                         typeRefs[index] = outer.ResolveNestedType(this, typeName);
                         break;
                     }
                 case ModuleTable.Index:
                 case ModuleRefTable.Index:
                     {
                         Module module;
                         if (scope >> 24 == ModuleTable.Index)
                         {
                             if (scope == 0 || scope == 1)
                             {
                                 module = this;
                             }
                             else
                             {
                                 throw new NotImplementedException("self reference scope?");
                             }
                         }
                         else
                         {
                             module = ResolveModuleRef(ModuleRef.records[(scope & 0xFFFFFF) - 1]);
                         }
                         TypeName typeName = GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName);
                         typeRefs[index] = module.FindType(typeName) ?? module.universe.GetMissingTypeOrThrow(this, module, null, typeName);
                         break;
                     }
                 default:
                     throw new NotImplementedException("ResolutionScope = " + scope.ToString("X"));
             }
         }
         return typeRefs[index];
     }
     else if ((metadataToken >> 24) == TypeSpecTable.Index && index < TypeSpec.RowCount)
     {
         if (typeSpecs == null)
         {
             typeSpecs = new Type[TypeSpec.records.Length];
         }
         Type type = typeSpecs[index];
         if (type == null)
         {
             TrackingGenericContext tc = context == null ? null : new TrackingGenericContext(context);
             type = Signature.ReadTypeSpec(this, ByteReader.FromBlob(blobHeap, TypeSpec.records[index]), tc);
             if (tc == null || !tc.IsUsed)
             {
                 typeSpecs[index] = type;
             }
         }
         return type;
     }
     else
     {
         throw TokenOutOfRangeException(metadataToken);
     }
 }
Example #28
0
		internal static MethodSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
		{
			CallingConventions callingConvention;
			int genericParamCount;
			Type returnType;
			Type[] parameterTypes;
			byte flags = br.ReadByte();
			switch (flags & 7)
			{
				case DEFAULT:
					callingConvention = CallingConventions.Standard;
					break;
				case VARARG:
					callingConvention = CallingConventions.VarArgs;
					break;
				default:
					throw new BadImageFormatException();
			}
			if ((flags & HASTHIS) != 0)
			{
				callingConvention |= CallingConventions.HasThis;
			}
			if ((flags & EXPLICITTHIS) != 0)
			{
				callingConvention |= CallingConventions.ExplicitThis;
			}
			genericParamCount = 0;
			if ((flags & GENERIC) != 0)
			{
				genericParamCount = br.ReadCompressedInt();
				context = new UnboundGenericMethodContext(context);
			}
			int paramCount = br.ReadCompressedInt();
			Type[][][] modifiers = null;
			Type[] optionalCustomModifiers;
			Type[] requiredCustomModifiers;
			ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
			returnType = ReadRetType(module, br, context);
			parameterTypes = new Type[paramCount];
			PackedCustomModifiers.SetModifiers(ref modifiers, 0, 0, optionalCustomModifiers, paramCount + 1);
			PackedCustomModifiers.SetModifiers(ref modifiers, 0, 1, requiredCustomModifiers, paramCount + 1);
			for (int i = 0; i < parameterTypes.Length; i++)
			{
				if ((callingConvention & CallingConventions.VarArgs) != 0 && br.PeekByte() == SENTINEL)
				{
					Array.Resize(ref parameterTypes, i);
					if (modifiers != null)
					{
						Array.Resize(ref modifiers, i + 1);
					}
					break;
				}
				ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
				PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 0, optionalCustomModifiers, paramCount + 1);
				PackedCustomModifiers.SetModifiers(ref modifiers, i + 1, 1, requiredCustomModifiers, paramCount + 1);
				parameterTypes[i] = ReadParam(module, br, context);
			}
			return new MethodSignature(returnType, parameterTypes, modifiers, callingConvention, genericParamCount);
		}
Example #29
0
 /// <summary>
 /// </summary>
 /// <param name="genericContext">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public IMethod ToSpecialization(IGenericContext genericContext)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// </summary>
        /// <param name="token">
        /// </param>
        /// <param name="genericContext">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="KeyNotFoundException">
        /// </exception>
        public IMethod ResolveMethod(int token, IGenericContext genericContext)
        {
            var peModuleSymbol = this.moduleDef as PEModuleSymbol;

            var methodHandle = MetadataTokens.Handle(token);

            /*
             * FIX for Roslyn code - to be able to load Array method references 
             
             
                        public override ImmutableArray<Symbol> GetMembers(string name)
                        {
                            // TODO: ASD: MY ADDON
                            if (name == ".ctor")
                            {
                                return ImmutableArray.Create<Symbol>(Enumerable.Range(1, 7).Select(n => new ArrayConstructor(this)).ToArray<Symbol>());
                            }

                            if (name == "Set")
                            {
                                return ImmutableArray.Create<Symbol>(Enumerable.Range(1, 7).Select(n => new ArraySetValueMethod(this)).ToArray<Symbol>());
                            }

                            if (name == "Get")
                            {
                                return ImmutableArray.Create<Symbol>(Enumerable.Range(1, 7).Select(n => new ArrayGetValueMethod(this)).ToArray<Symbol>());
                            }

                            if (name == "Address")
                            {
                                return ImmutableArray.Create<Symbol>(Enumerable.Range(1, 7).Select(n => new ArrayAddressMethod(this)).ToArray<Symbol>());
                            }
                            // TODO: END - ASD: MY ADDON
             
                            return ImmutableArray<Symbol>.Empty;
                        }
              
                        // TODO: ASD: MY ADDON
                        private sealed class ArrayConstructor : SynthesizedInstanceMethodSymbol
                        {
                            private readonly ImmutableArray<ParameterSymbol> parameters;
                            private readonly ArrayTypeSymbol arrayTypeSymbol;

                            public ArrayConstructor(ArrayTypeSymbol arrayTypeSymbol)
                            {
                                this.arrayTypeSymbol = arrayTypeSymbol;
                                var intType = arrayTypeSymbol.BaseType.ContainingAssembly.GetSpecialType(SpecialType.System_Int32);
                                this.parameters = ImmutableArray.Create<ParameterSymbol>(
                                    Enumerable.Range(0, arrayTypeSymbol.Rank).Select(n => new SynthesizedParameterSymbol(this, intType, n, RefKind.None)).ToArray<ParameterSymbol>());
                            }

                            public override ImmutableArray<ParameterSymbol> Parameters
                            {
                                get { return parameters; }
                            }

                            //
                            // Consider overriding when implementing a synthesized subclass.
                            //

                            internal override bool GenerateDebugInfo
                            {
                                get { return false; }
                            }

                            public override Accessibility DeclaredAccessibility
                            {
                                get { return ContainingType.IsAbstract ? Accessibility.Protected : Accessibility.Public; }
                            }

                            internal override bool IsMetadataFinal()
                            {
                                return false;
                            }

                            #region Sealed

                            public sealed override Symbol ContainingSymbol
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override NamedTypeSymbol ContainingType
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override string Name
                            {
                                get { return WellKnownMemberNames.InstanceConstructorName; }
                            }

                            internal sealed override bool HasSpecialName
                            {
                                get { return true; }
                            }

                            internal sealed override System.Reflection.MethodImplAttributes ImplementationAttributes
                            {
                                get
                                {
                                    var containingType = this.arrayTypeSymbol.BaseType;
                                    if (containingType.IsComImport)
                                    {
                                        Debug.Assert(containingType.TypeKind == TypeKind.Class);
                                        return System.Reflection.MethodImplAttributes.Runtime | System.Reflection.MethodImplAttributes.InternalCall;
                                    }

                                    if (containingType.TypeKind == TypeKind.Delegate)
                                    {
                                        return System.Reflection.MethodImplAttributes.Runtime;
                                    }

                                    return default(System.Reflection.MethodImplAttributes);
                                }
                            }

                            internal sealed override bool RequiresSecurityObject
                            {
                                get { return false; }
                            }

                            public sealed override DllImportData GetDllImportData()
                            {
                                return null;
                            }

                            internal sealed override MarshalPseudoCustomAttributeData ReturnValueMarshallingInformation
                            {
                                get { return null; }
                            }

                            internal sealed override bool HasDeclarativeSecurity
                            {
                                get { return false; }
                            }

                            internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInformation()
                            {
                                throw ExceptionUtilities.Unreachable;
                            }

                            internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
                            {
                                return ImmutableArray<string>.Empty;
                            }

                            public sealed override bool IsVararg
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<TypeParameterSymbol> TypeParameters
                            {
                                get { return ImmutableArray<TypeParameterSymbol>.Empty; }
                            }

                            internal sealed override LexicalSortKey GetLexicalSortKey()
                            {
                                //For the sake of matching the metadata output of the native compiler, make synthesized constructors appear last in the metadata.
                                //This is not critical, but it makes it easier on tools that are comparing metadata.
                                return LexicalSortKey.Last;
                            }

                            public sealed override ImmutableArray<Location> Locations
                            {
                                get { return ContainingType.Locations; }
                            }

                            public sealed override TypeSymbol ReturnType
                            {
                                get { return this.arrayTypeSymbol.BaseType.ContainingAssembly.GetSpecialType(SpecialType.System_Void); }
                            }

                            public sealed override ImmutableArray<CustomModifier> ReturnTypeCustomModifiers
                            {
                                get { return ImmutableArray<CustomModifier>.Empty; }
                            }

                            public sealed override ImmutableArray<TypeSymbol> TypeArguments
                            {
                                get { return ImmutableArray<TypeSymbol>.Empty; }
                            }

                            public sealed override Symbol AssociatedSymbol
                            {
                                get { return this.arrayTypeSymbol; }
                            }

                            public sealed override int Arity
                            {
                                get { return 0; }
                            }

                            public sealed override bool ReturnsVoid
                            {
                                get { return true; }
                            }

                            public sealed override MethodKind MethodKind
                            {
                                get { return MethodKind.Constructor; }
                            }

                            public sealed override bool IsExtern
                            {
                                get
                                {
                                    // Synthesized constructors of ComImport type are extern
                                    NamedTypeSymbol containingType = this.ContainingType;
                                    return (object)containingType != null && containingType.IsComImport;
                                }
                            }

                            public sealed override bool IsSealed
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAbstract
                            {
                                get { return false; }
                            }

                            public sealed override bool IsOverride
                            {
                                get { return false; }
                            }

                            public sealed override bool IsVirtual
                            {
                                get { return false; }
                            }

                            public sealed override bool IsStatic
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAsync
                            {
                                get { return false; }
                            }

                            public sealed override bool HidesBaseMethodsByName
                            {
                                get { return false; }
                            }

                            internal sealed override bool IsMetadataNewSlot(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            internal sealed override bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            public sealed override bool IsExtensionMethod
                            {
                                get { return false; }
                            }

                            internal sealed override Microsoft.Cci.CallingConvention CallingConvention
                            {
                                get { return Microsoft.Cci.CallingConvention.HasThis; }
                            }

                            internal sealed override bool IsExplicitInterfaceImplementation
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations
                            {
                                get { return ImmutableArray<MethodSymbol>.Empty; }
                            }

                            #endregion
                        }

                        private sealed class ArraySetValueMethod : SynthesizedInstanceMethodSymbol
                        {
                            private readonly ImmutableArray<ParameterSymbol> parameters;
                            private readonly ArrayTypeSymbol arrayTypeSymbol;

                            internal ArraySetValueMethod(ArrayTypeSymbol arrayTypeSymbol)
                            {
                                this.arrayTypeSymbol = arrayTypeSymbol;
                                var intType = arrayTypeSymbol.BaseType.ContainingAssembly.GetSpecialType(SpecialType.System_Int32);
                                this.parameters = ImmutableArray.Create<ParameterSymbol>(
                                    Enumerable.Range(0, arrayTypeSymbol.Rank).Select(n => new SynthesizedParameterSymbol(this, intType, n, RefKind.None))
                                    .ToArray<ParameterSymbol>()
                                    .Append(new SynthesizedParameterSymbol(this, arrayTypeSymbol.ElementType, arrayTypeSymbol.Rank + 1, RefKind.None)));
                            }

                            public override ImmutableArray<ParameterSymbol> Parameters
                            {
                                get { return parameters; }
                            }

                            #region Sealed

                            public sealed override Symbol ContainingSymbol
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override NamedTypeSymbol ContainingType
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override string Name
                            {
                                get
                                {
                                    return "Set";
                                }
                            }

                            internal sealed override bool HasSpecialName
                            {
                                get { return true; }
                            }

                            internal sealed override System.Reflection.MethodImplAttributes ImplementationAttributes
                            {
                                get
                                {
                                    var containingType = this.arrayTypeSymbol.BaseType;
                                    if (containingType.IsComImport)
                                    {
                                        Debug.Assert(containingType.TypeKind == TypeKind.Class);
                                        return System.Reflection.MethodImplAttributes.Runtime | System.Reflection.MethodImplAttributes.InternalCall;
                                    }

                                    if (containingType.TypeKind == TypeKind.Delegate)
                                    {
                                        return System.Reflection.MethodImplAttributes.Runtime;
                                    }

                                    return default(System.Reflection.MethodImplAttributes);
                                }
                            }

                            internal sealed override bool RequiresSecurityObject
                            {
                                get { return false; }
                            }

                            public sealed override DllImportData GetDllImportData()
                            {
                                return null;
                            }

                            internal sealed override MarshalPseudoCustomAttributeData ReturnValueMarshallingInformation
                            {
                                get { return null; }
                            }

                            internal sealed override bool HasDeclarativeSecurity
                            {
                                get { return false; }
                            }

                            internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInformation()
                            {
                                throw ExceptionUtilities.Unreachable;
                            }

                            internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
                            {
                                return ImmutableArray<string>.Empty;
                            }

                            public sealed override bool IsVararg
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<TypeParameterSymbol> TypeParameters
                            {
                                get { return ImmutableArray<TypeParameterSymbol>.Empty; }
                            }

                            internal sealed override LexicalSortKey GetLexicalSortKey()
                            {
                                //For the sake of matching the metadata output of the native compiler, make synthesized constructors appear last in the metadata.
                                //This is not critical, but it makes it easier on tools that are comparing metadata.
                                return LexicalSortKey.Last;
                            }

                            public sealed override ImmutableArray<Location> Locations
                            {
                                get { return ContainingType.Locations; }
                            }

                            public sealed override TypeSymbol ReturnType
                            {
                                get { return this.arrayTypeSymbol.BaseType.ContainingAssembly.GetSpecialType(SpecialType.System_Void); }
                            }

                            public sealed override ImmutableArray<CustomModifier> ReturnTypeCustomModifiers
                            {
                                get { return ImmutableArray<CustomModifier>.Empty; }
                            }

                            public sealed override ImmutableArray<TypeSymbol> TypeArguments
                            {
                                get { return ImmutableArray<TypeSymbol>.Empty; }
                            }

                            public sealed override Symbol AssociatedSymbol
                            {
                                get { return this.arrayTypeSymbol; }
                            }

                            public sealed override int Arity
                            {
                                get { return 0; }
                            }

                            public sealed override bool ReturnsVoid
                            {
                                get { return true; }
                            }

                            public sealed override MethodKind MethodKind
                            {
                                get { return MethodKind.PropertySet; }
                            }

                            public sealed override bool IsExtern
                            {
                                get
                                {
                                    // Synthesized constructors of ComImport type are extern
                                    NamedTypeSymbol containingType = this.ContainingType;
                                    return (object)containingType != null && containingType.IsComImport;
                                }
                            }

                            public sealed override bool IsSealed
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAbstract
                            {
                                get { return false; }
                            }

                            public sealed override bool IsOverride
                            {
                                get { return false; }
                            }

                            public sealed override bool IsVirtual
                            {
                                get { return false; }
                            }

                            public sealed override bool IsStatic
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAsync
                            {
                                get { return false; }
                            }

                            public sealed override bool HidesBaseMethodsByName
                            {
                                get { return false; }
                            }

                            internal sealed override bool IsMetadataNewSlot(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            internal sealed override bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            public sealed override bool IsExtensionMethod
                            {
                                get { return false; }
                            }

                            internal sealed override Microsoft.Cci.CallingConvention CallingConvention
                            {
                                get { return Microsoft.Cci.CallingConvention.HasThis; }
                            }

                            internal sealed override bool IsExplicitInterfaceImplementation
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations
                            {
                                get { return ImmutableArray<MethodSymbol>.Empty; }
                            }

                            #endregion

                            internal override bool IsMetadataFinal()
                            {
                                return false;
                            }

                            internal override bool GenerateDebugInfo
                            {
                                get { return false; }
                            }

                            public override Accessibility DeclaredAccessibility
                            {
                                get { return Accessibility.Public; }
                            }
                        }

                        private sealed class ArrayGetValueMethod : SynthesizedInstanceMethodSymbol
                        {
                            private readonly ImmutableArray<ParameterSymbol> parameters;
                            private readonly ArrayTypeSymbol arrayTypeSymbol;

                            internal ArrayGetValueMethod(ArrayTypeSymbol arrayTypeSymbol)
                            {
                                this.arrayTypeSymbol = arrayTypeSymbol;
                                var intType = arrayTypeSymbol.BaseType.ContainingAssembly.GetSpecialType(SpecialType.System_Int32);
                                this.parameters = ImmutableArray.Create<ParameterSymbol>(
                                    Enumerable.Range(0, arrayTypeSymbol.Rank).Select(n => new SynthesizedParameterSymbol(this, intType, n, RefKind.None))
                                    .ToArray<ParameterSymbol>());
                            }

                            public override ImmutableArray<ParameterSymbol> Parameters
                            {
                                get { return parameters; }
                            }

                            #region Sealed

                            public sealed override Symbol ContainingSymbol
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override NamedTypeSymbol ContainingType
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override string Name
                            {
                                get
                                {
                                    return "Get";
                                }
                            }

                            internal sealed override bool HasSpecialName
                            {
                                get { return true; }
                            }

                            internal sealed override System.Reflection.MethodImplAttributes ImplementationAttributes
                            {
                                get
                                {
                                    var containingType = this.arrayTypeSymbol.BaseType;
                                    if (containingType.IsComImport)
                                    {
                                        Debug.Assert(containingType.TypeKind == TypeKind.Class);
                                        return System.Reflection.MethodImplAttributes.Runtime | System.Reflection.MethodImplAttributes.InternalCall;
                                    }

                                    if (containingType.TypeKind == TypeKind.Delegate)
                                    {
                                        return System.Reflection.MethodImplAttributes.Runtime;
                                    }

                                    return default(System.Reflection.MethodImplAttributes);
                                }
                            }

                            internal sealed override bool RequiresSecurityObject
                            {
                                get { return false; }
                            }

                            public sealed override DllImportData GetDllImportData()
                            {
                                return null;
                            }

                            internal sealed override MarshalPseudoCustomAttributeData ReturnValueMarshallingInformation
                            {
                                get { return null; }
                            }

                            internal sealed override bool HasDeclarativeSecurity
                            {
                                get { return false; }
                            }

                            internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInformation()
                            {
                                throw ExceptionUtilities.Unreachable;
                            }

                            internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
                            {
                                return ImmutableArray<string>.Empty;
                            }

                            public sealed override bool IsVararg
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<TypeParameterSymbol> TypeParameters
                            {
                                get { return ImmutableArray<TypeParameterSymbol>.Empty; }
                            }

                            internal sealed override LexicalSortKey GetLexicalSortKey()
                            {
                                //For the sake of matching the metadata output of the native compiler, make synthesized constructors appear last in the metadata.
                                //This is not critical, but it makes it easier on tools that are comparing metadata.
                                return LexicalSortKey.Last;
                            }

                            public sealed override ImmutableArray<Location> Locations
                            {
                                get { return ContainingType.Locations; }
                            }

                            public sealed override TypeSymbol ReturnType
                            {
                                get { return this.arrayTypeSymbol.ElementType; }
                            }

                            public sealed override ImmutableArray<CustomModifier> ReturnTypeCustomModifiers
                            {
                                get { return ImmutableArray<CustomModifier>.Empty; }
                            }

                            public sealed override ImmutableArray<TypeSymbol> TypeArguments
                            {
                                get { return ImmutableArray<TypeSymbol>.Empty; }
                            }

                            public sealed override Symbol AssociatedSymbol
                            {
                                get { return this.arrayTypeSymbol; }
                            }

                            public sealed override int Arity
                            {
                                get { return 0; }
                            }

                            public sealed override bool ReturnsVoid
                            {
                                get { return false; }
                            }

                            public sealed override MethodKind MethodKind
                            {
                                get { return MethodKind.PropertyGet; }
                            }

                            public sealed override bool IsExtern
                            {
                                get
                                {
                                    // Synthesized constructors of ComImport type are extern
                                    NamedTypeSymbol containingType = this.ContainingType;
                                    return (object)containingType != null && containingType.IsComImport;
                                }
                            }

                            public sealed override bool IsSealed
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAbstract
                            {
                                get { return false; }
                            }

                            public sealed override bool IsOverride
                            {
                                get { return false; }
                            }

                            public sealed override bool IsVirtual
                            {
                                get { return false; }
                            }

                            public sealed override bool IsStatic
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAsync
                            {
                                get { return false; }
                            }

                            public sealed override bool HidesBaseMethodsByName
                            {
                                get { return false; }
                            }

                            internal sealed override bool IsMetadataNewSlot(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            internal sealed override bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            public sealed override bool IsExtensionMethod
                            {
                                get { return false; }
                            }

                            internal sealed override Microsoft.Cci.CallingConvention CallingConvention
                            {
                                get { return Microsoft.Cci.CallingConvention.HasThis; }
                            }

                            internal sealed override bool IsExplicitInterfaceImplementation
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations
                            {
                                get { return ImmutableArray<MethodSymbol>.Empty; }
                            }

                            #endregion

                            internal override bool IsMetadataFinal()
                            {
                                return false;
                            }

                            internal override bool GenerateDebugInfo
                            {
                                get { return false; }
                            }

                            public override Accessibility DeclaredAccessibility
                            {
                                get { return Accessibility.Public; }
                            }
                        }

                        private sealed class ArrayAddressMethod : SynthesizedInstanceMethodSymbol
                        {
                            private readonly ImmutableArray<ParameterSymbol> parameters;
                            private readonly ArrayTypeSymbol arrayTypeSymbol;

                            internal ArrayAddressMethod(ArrayTypeSymbol arrayTypeSymbol)
                            {
                                this.arrayTypeSymbol = arrayTypeSymbol;
                                var intType = arrayTypeSymbol.BaseType.ContainingAssembly.GetSpecialType(SpecialType.System_Int32);
                                this.parameters = ImmutableArray.Create<ParameterSymbol>(
                                    Enumerable.Range(0, arrayTypeSymbol.Rank).Select(n => new SynthesizedParameterSymbol(this, intType, n, RefKind.None))
                                    .ToArray<ParameterSymbol>());
                            }

                            public override ImmutableArray<ParameterSymbol> Parameters
                            {
                                get { return parameters; }
                            }

                            #region Sealed

                            public sealed override Symbol ContainingSymbol
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override NamedTypeSymbol ContainingType
                            {
                                get
                                {
                                    return this.arrayTypeSymbol.BaseType;
                                }
                            }

                            public sealed override string Name
                            {
                                get
                                {
                                    return "Address";
                                }
                            }

                            internal sealed override bool HasSpecialName
                            {
                                get { return true; }
                            }

                            internal sealed override System.Reflection.MethodImplAttributes ImplementationAttributes
                            {
                                get
                                {
                                    var containingType = this.arrayTypeSymbol.BaseType;
                                    if (containingType.IsComImport)
                                    {
                                        Debug.Assert(containingType.TypeKind == TypeKind.Class);
                                        return System.Reflection.MethodImplAttributes.Runtime | System.Reflection.MethodImplAttributes.InternalCall;
                                    }

                                    if (containingType.TypeKind == TypeKind.Delegate)
                                    {
                                        return System.Reflection.MethodImplAttributes.Runtime;
                                    }

                                    return default(System.Reflection.MethodImplAttributes);
                                }
                            }

                            internal sealed override bool RequiresSecurityObject
                            {
                                get { return false; }
                            }

                            public sealed override DllImportData GetDllImportData()
                            {
                                return null;
                            }

                            internal sealed override MarshalPseudoCustomAttributeData ReturnValueMarshallingInformation
                            {
                                get { return null; }
                            }

                            internal sealed override bool HasDeclarativeSecurity
                            {
                                get { return false; }
                            }

                            internal sealed override IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInformation()
                            {
                                throw ExceptionUtilities.Unreachable;
                            }

                            internal sealed override ImmutableArray<string> GetAppliedConditionalSymbols()
                            {
                                return ImmutableArray<string>.Empty;
                            }

                            public sealed override bool IsVararg
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<TypeParameterSymbol> TypeParameters
                            {
                                get { return ImmutableArray<TypeParameterSymbol>.Empty; }
                            }

                            internal sealed override LexicalSortKey GetLexicalSortKey()
                            {
                                //For the sake of matching the metadata output of the native compiler, make synthesized constructors appear last in the metadata.
                                //This is not critical, but it makes it easier on tools that are comparing metadata.
                                return LexicalSortKey.Last;
                            }

                            public sealed override ImmutableArray<Location> Locations
                            {
                                get { return ContainingType.Locations; }
                            }

                            public sealed override TypeSymbol ReturnType
                            {
                                get { return new ByRefReturnErrorTypeSymbol(this.arrayTypeSymbol.ElementType); }
                            }

                            public sealed override ImmutableArray<CustomModifier> ReturnTypeCustomModifiers
                            {
                                get { return ImmutableArray<CustomModifier>.Empty; }
                            }

                            public sealed override ImmutableArray<TypeSymbol> TypeArguments
                            {
                                get { return ImmutableArray<TypeSymbol>.Empty; }
                            }

                            public sealed override Symbol AssociatedSymbol
                            {
                                get { return this.arrayTypeSymbol; }
                            }

                            public sealed override int Arity
                            {
                                get { return 0; }
                            }

                            public sealed override bool ReturnsVoid
                            {
                                get { return false; }
                            }

                            public sealed override MethodKind MethodKind
                            {
                                get { return MethodKind.PropertyGet; }
                            }

                            public sealed override bool IsExtern
                            {
                                get
                                {
                                    // Synthesized constructors of ComImport type are extern
                                    NamedTypeSymbol containingType = this.ContainingType;
                                    return (object)containingType != null && containingType.IsComImport;
                                }
                            }

                            public sealed override bool IsSealed
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAbstract
                            {
                                get { return false; }
                            }

                            public sealed override bool IsOverride
                            {
                                get { return false; }
                            }

                            public sealed override bool IsVirtual
                            {
                                get { return false; }
                            }

                            public sealed override bool IsStatic
                            {
                                get { return false; }
                            }

                            public sealed override bool IsAsync
                            {
                                get { return false; }
                            }

                            public sealed override bool HidesBaseMethodsByName
                            {
                                get { return false; }
                            }

                            internal sealed override bool IsMetadataNewSlot(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            internal sealed override bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false)
                            {
                                return false;
                            }

                            public sealed override bool IsExtensionMethod
                            {
                                get { return false; }
                            }

                            internal sealed override Microsoft.Cci.CallingConvention CallingConvention
                            {
                                get { return Microsoft.Cci.CallingConvention.HasThis; }
                            }

                            internal sealed override bool IsExplicitInterfaceImplementation
                            {
                                get { return false; }
                            }

                            public sealed override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations
                            {
                                get { return ImmutableArray<MethodSymbol>.Empty; }
                            }

                            #endregion

                            internal override bool IsMetadataFinal()
                            {
                                return false;
                            }

                            internal override bool GenerateDebugInfo
                            {
                                get { return false; }
                            }

                            public override Accessibility DeclaredAccessibility
                            {
                                get { return Accessibility.Public; }
                            }
                        }
             
             */

            /*
             * FIX for Roslyn code
             *  internal override Symbol GetSymbolForMemberRef(MemberReferenceHandle memberRef, TypeSymbol scope = null, bool methodsOnly = false)
                {
                    TypeSymbol targetTypeSymbol = GetMemberRefTypeSymbol(memberRef);

                    // TODO: ASD: MY ADDON
                    if (targetTypeSymbol == null)
                    {
                        Handle container = Module.GetContainingTypeOrThrow(memberRef);
                        HandleType containerType = container.HandleType;
                        if (containerType == HandleType.Method)
                        {
                            return GetSymbolForILToken(container);
                        }
                    }
             
                    ...
             */

            /*
             * FIX for Roslyn Code - 2
                protected override TypeSymbol GetGenericTypeParamSymbol(int position)
                {
                    ...
                    // TODO: ASD ADDON
                    ArrayTypeSymbol arrayTypeSymbol = this.containingType as ArrayTypeSymbol;
                    if ((object)arrayTypeSymbol != null && position == 0 && arrayTypeSymbol.ElementType is TypeParameterSymbol)
                    {
                        return arrayTypeSymbol.ElementType;
                    }

                    ...
                }             
             */

            var symbolForIlToken = peModuleSymbol.GetMetadataDecoder(genericContext).GetSymbolForILToken(methodHandle);
            var methodSymbol = symbolForIlToken as MethodSymbol;
            if (methodSymbol != null)
            {
                if (methodSymbol.MethodKind == MethodKind.Constructor)
                {
                    return new MetadataConstructorAdapter(SubstituteMethodSymbolIfNeeded(methodSymbol, genericContext));
                }

                return new MetadataMethodAdapter(SubstituteMethodSymbolIfNeeded(methodSymbol, genericContext));
            }

            throw new KeyNotFoundException();
        }