internal MetadataOnlyAssembly(MetadataOnlyModule[] modules, string manifestFile) { MetadataOnlyAssembly.VerifyModules(modules); this.m_manifestModule = modules[0]; this.m_name = AssemblyNameHelper.GetAssemblyName(this.m_manifestModule); this.m_manifestFile = manifestFile; MetadataOnlyModule[] metadataOnlyModuleArray = modules; for (int num = 0; num < (int)metadataOnlyModuleArray.Length; num++) { metadataOnlyModuleArray[num].SetContainingAssembly(this); } List <Module> modules1 = new List <Module>(modules); foreach (string fileNamesFromFilesTable in MetadataOnlyAssembly.GetFileNamesFromFilesTable(this.m_manifestModule, false)) { if (modules1.Find((Module i) => i.Name.Equals(fileNamesFromFilesTable, StringComparison.OrdinalIgnoreCase)) != null) { continue; } Module module = this.m_manifestModule.AssemblyResolver.ResolveModule(this, fileNamesFromFilesTable); if (module == null) { throw new InvalidOperationException(MetadataStringTable.ResolverMustResolveToValidModule); } if (module.Assembly != this) { throw new InvalidOperationException(MetadataStringTable.ResolverMustSetAssemblyProperty); } modules1.Add(module); } this.m_modules = modules1.ToArray(); }
public MetadataOnlyPropertyInfo(MetadataOnlyModule resolver, Token propToken, Type[] typeArgs, Type[] methodArgs) { int num; EmbeddedBlobPointer embeddedBlobPointer; int num1; int num2; UnusedIntPtr unusedIntPtr; int num3; PropertyAttributes propertyAttribute; Token token; Token token1; Token token2; uint num4; this.m_resolver = resolver; this.m_PropertyToken = propToken; this.m_context = new GenericContext(typeArgs, methodArgs); IMetadataImport rawImport = this.m_resolver.RawImport; StringBuilder stringBuilder = new StringBuilder(256); rawImport.GetPropertyProps(this.m_PropertyToken, out this.m_declaringClassToken, null, 0, out num, out propertyAttribute, out embeddedBlobPointer, out num1, out num2, out unusedIntPtr, out num3, out token, out token1, out token2, 1, out num4); this.m_attrib = propertyAttribute; stringBuilder.Capacity = num; rawImport.GetPropertyProps(this.m_PropertyToken, out this.m_declaringClassToken, stringBuilder, num, out num, out propertyAttribute, out embeddedBlobPointer, out num1, out num2, out unusedIntPtr, out num3, out token, out token1, out token2, 1, out num4); this.m_name = stringBuilder.ToString(); byte[] numArray = this.m_resolver.ReadEmbeddedBlob(embeddedBlobPointer, num1); int num5 = 0; SignatureUtil.ExtractCallingConvention(numArray, ref num5); SignatureUtil.ExtractInt(numArray, ref num5); this.m_propertyType = SignatureUtil.ExtractType(numArray, ref num5, this.m_resolver, this.m_context); this.m_setterToken = token; this.m_getterToken = token1; }
public MetadataOnlyTypeDef(MetadataOnlyModule scope, Token tokenTypeDef, Type[] typeParameters) { MetadataOnlyTypeDef.ValidateConstructorArguments(scope, tokenTypeDef); this.m_resolver = scope; this.m_tokenTypeDef = tokenTypeDef; this.m_typeParameters = null; this.m_resolver.GetTypeProps(this.m_tokenTypeDef, out this.m_tokenExtends, out this.m_fullName, out this.m_typeAttributes); int num = this.m_resolver.CountGenericParams(this.m_tokenTypeDef); bool flag = (typeParameters == null ? false : (int)typeParameters.Length > 0); if (num <= 0) { this.m_typeParameters = Type.EmptyTypes; } else { if (flag) { if (num != (int)typeParameters.Length) { throw new ArgumentException(MetadataStringTable.WrongNumberOfGenericArguments); } this.m_typeParameters = typeParameters; return; } this.m_typeParameters = new Type[num]; int num1 = 0; foreach (int genericParameterToken in this.m_resolver.GetGenericParameterTokens(this.m_tokenTypeDef)) { int num2 = num1; num1 = num2 + 1; this.m_typeParameters[num2] = this.m_resolver.Factory.CreateTypeVariable(this.m_resolver, new Token(genericParameterToken)); } } }
public MetadataOnlyEventInfo(MetadataOnlyModule resolver, Token eventToken, Type[] typeArgs, Type[] methodArgs) { this.m_resolver = resolver; this.m_eventToken = eventToken; this.m_context = new GenericContext(typeArgs, methodArgs); this.GetInfo(); }
public static IEnumerable <CustomAttributeData> GetTypeForwardedToAttributes(MetadataOnlyModule manifestModule, Token token) { if (token.TokenType != System.Reflection.Adds.TokenType.Assembly) { return(new CustomAttributeData[0]); } return(PseudoCustomAttributes.GetTypeForwardedToAttributes(manifestModule)); }
public override byte[] GetILAsByteArray() { MetadataOnlyModule resolver = base.Method.Resolver; uint methodRva = resolver.GetMethodRva(base.Method.MetadataToken); byte[] numArray = resolver.RawMetadata.ReadRva((long)((ulong)methodRva + (long)this.m_header.HeaderSizeBytes), this.m_header.CodeSize); return(numArray); }
public MetadataOnlyMethodInfo(MetadataOnlyModule resolver, Token methodDef, Type[] typeArgs, Type[] methodArgs) { this.m_resolver = resolver; this.m_methodDef = methodDef; this.m_typeArgs = typeArgs; this.m_methodArgs = methodArgs; resolver.GetMethodProps(methodDef, out this.m_declaringTypeDef, out this.m_name, out this.m_attrs, out this.m_sigBlob); }
public virtual MethodBase CreateMethodOrConstructor(MetadataOnlyModule resolver, Token methodDef, Type[] typeArgs, Type[] methodArgs) { MetadataOnlyMethodInfo metadataOnlyMethodInfo = new MetadataOnlyMethodInfo(resolver, methodDef, typeArgs, methodArgs); if (DefaultFactory.IsRawConstructor(metadataOnlyMethodInfo)) { return(this.CreateConstructorInfo(metadataOnlyMethodInfo)); } return(this.CreateMethodInfo(metadataOnlyMethodInfo)); }
internal static Token GetAssemblyToken(MetadataOnlyModule module) { int num; if (((IMetadataAssemblyImport)module.RawImport).GetAssemblyFromScope(out num) != 0) { return(Token.Nil); } return(new Token(num)); }
internal static MethodBody TryCreate(MetadataOnlyMethodInfo method) { MetadataOnlyModule resolver = method.Resolver; MethodBody methodBody = null; if (resolver.Factory.TryCreateMethodBody(method, ref methodBody)) { return(methodBody); } return(MetadataOnlyMethodBodyWorker.Create(method)); }
internal static MethodBase Create(MetadataOnlyModule resolver, Token methodDef, GenericContext context) { Type[] emptyTypes = Type.EmptyTypes; Type[] methodArgs = Type.EmptyTypes; if (context != null) { emptyTypes = context.TypeArgs; methodArgs = context.MethodArgs; } return(resolver.Factory.CreateMethodOrConstructor(resolver, methodDef, emptyTypes, methodArgs)); }
internal static MethodBody Create(MetadataOnlyMethodInfo method) { MetadataOnlyModule resolver = method.Resolver; uint methodRva = resolver.GetMethodRva(method.MetadataToken); if (methodRva == 0) { return(null); } return(new MetadataOnlyMethodBodyWorker(method, MetadataOnlyMethodBodyWorker.GetMethodHeader(methodRva, resolver))); }
public virtual IEnumerable <CustomAttributeData> GetPseudoCustomAttributes(MetadataOnlyModule module, Token token) { List <CustomAttributeData> customAttributeDatas = new List <CustomAttributeData>(); customAttributeDatas.AddRange(PseudoCustomAttributes.GetTypeForwardedToAttributes(module, token)); CustomAttributeData serializableAttribute = PseudoCustomAttributes.GetSerializableAttribute(module, token); if (serializableAttribute != null) { customAttributeDatas.Add(serializableAttribute); } return(customAttributeDatas); }
public Module ResolveModule(Assembly containingAssembly, string moduleName) { if (containingAssembly == null || string.IsNullOrEmpty(containingAssembly.Location)) { throw new ArgumentException("manifestModule needs to be associated with an assembly with valid location"); } string directoryName = Path.GetDirectoryName(containingAssembly.Location); string str = Path.Combine(directoryName, moduleName); MetadataFile metadataFile = this.m_dispenser.OpenFileAsFileMapping(str); MetadataOnlyModule metadataOnlyModule = new MetadataOnlyModule(this.m_universe, metadataFile, this.Factory, str); metadataOnlyModule.SetContainingAssembly(containingAssembly); return(metadataOnlyModule); }
private bool IsValueTypeHelper() { MetadataOnlyModule resolver = this.Resolver; if (this.Equals(resolver.AssemblyResolver.GetTypeXFromName("System.Enum"))) { return(false); } if (resolver.AssemblyResolver.GetTypeXFromName("System.ValueType").Equals(this.BaseType)) { return(true); } return(this.IsEnum); }
private static void ValidateConstructorArguments(MetadataOnlyModule scope, Token tokenTypeDef) { if (scope == null) { throw new ArgumentNullException("scope"); } if (!tokenTypeDef.IsType(System.Reflection.Adds.TokenType.TypeDef)) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; string expectedTokenType = MetadataStringTable.ExpectedTokenType; object[] str = new object[] { System.Reflection.Adds.TokenType.TypeDef.ToString() }; throw new ArgumentException(string.Format(invariantCulture, expectedTokenType, str)); } }
public OpenGenericContext(MetadataOnlyModule resolver, Type ownerType, Token ownerMethod) : base(null, null) { this.m_resolver = resolver; this.m_ownerMethod = ownerMethod; int length = (int)ownerType.GetGenericArguments().Length; Type[] metadataOnlyTypeVariableRef = new Type[length]; Token token = new Token(ownerType.MetadataToken); for (int i = 0; i < length; i++) { metadataOnlyTypeVariableRef[i] = new MetadataOnlyTypeVariableRef(resolver, token, i); } base.TypeArgs = metadataOnlyTypeVariableRef; }
public static AssemblyName GetAssemblyName(MetadataOnlyModule module) { PortableExecutableKinds portableExecutableKind; ImageFileMachine imageFileMachine; Token assemblyToken = MetadataOnlyAssembly.GetAssemblyToken(module); IMetadataAssemblyImport rawImport = (IMetadataAssemblyImport)module.RawImport; AssemblyNameHelper.AssemblyNameFromDefitionBuilder assemblyNameFromDefitionBuilder = new AssemblyNameHelper.AssemblyNameFromDefitionBuilder(assemblyToken, module.RawMetadata, rawImport); AssemblyName codeBaseFromManifestModule = assemblyNameFromDefitionBuilder.CalculateName(); codeBaseFromManifestModule.CodeBase = MetadataOnlyAssembly.GetCodeBaseFromManifestModule(module); module.GetPEKind(out portableExecutableKind, out imageFileMachine); codeBaseFromManifestModule.ProcessorArchitecture = AssemblyNameHelper.CalculateProcArchIndex(portableExecutableKind, imageFileMachine); return(codeBaseFromManifestModule); }
public MetadataOnlyFieldInfo(MetadataOnlyModule resolver, Token fieldDefToken, Type[] typeArgs, Type[] methodArgs) { int num; EmbeddedBlobPointer embeddedBlobPointer; int num1; int num2; IntPtr intPtr; int num3; FieldAttributes fieldAttribute; this.m_resolver = resolver; this.m_fieldDefToken = fieldDefToken; if (typeArgs != null || methodArgs != null) { this.m_context = new GenericContext(typeArgs, methodArgs); } IMetadataImport rawImport = this.m_resolver.RawImport; StringBuilder stringBuilder = new StringBuilder(256); rawImport.GetFieldProps(this.m_fieldDefToken, out this.m_declaringClassToken, null, 0, out num, out fieldAttribute, out embeddedBlobPointer, out num1, out num2, out intPtr, out num3); this.m_attrib = fieldAttribute; stringBuilder.Capacity = num; rawImport.GetFieldProps(this.m_fieldDefToken, out this.m_declaringClassToken, stringBuilder, num, out num, out fieldAttribute, out embeddedBlobPointer, out num1, out num2, out intPtr, out num3); this.m_attrib = fieldAttribute; this.m_name = stringBuilder.ToString(); byte[] numArray = this.m_resolver.ReadEmbeddedBlob(embeddedBlobPointer, num1); int num4 = 0; SignatureUtil.ExtractCallingConvention(numArray, ref num4); this.m_customModifiers = SignatureUtil.ExtractCustomModifiers(numArray, ref num4, this.m_resolver, this.m_context); if (this.m_resolver.RawImport.IsValidToken((uint)this.m_declaringClassToken)) { Type type = this.m_resolver.ResolveType(this.m_declaringClassToken); if (type.IsGenericType && (this.m_context == null || this.m_context.TypeArgs == null || (int)this.m_context.TypeArgs.Length == 0)) { if (this.m_context != null) { this.m_context = new GenericContext(type.GetGenericArguments(), this.m_context.MethodArgs); } else { this.m_context = new GenericContext(type.GetGenericArguments(), null); } } } this.m_fieldType = SignatureUtil.ExtractType(numArray, ref num4, this.m_resolver, this.m_context); }
internal static System.Reflection.Adds.CorElementType GetTypeId(Type type) { System.Reflection.Adds.CorElementType corElementType; if (type.IsEnum) { return(SignatureUtil.GetTypeId(MetadataOnlyModule.GetUnderlyingType(type))); } if (type.IsArray) { return(System.Reflection.Adds.CorElementType.SzArray); } if (!SignatureUtil.TypeMapForAttributes.LookupPrimitive(type, out corElementType)) { throw new ArgumentException(MetadataStringTable.UnsupportedTypeInAttributeSignature); } return(corElementType); }
public MetadataOnlyMethodInfo(MetadataOnlyMethodInfo method) { this.m_resolver = method.m_resolver; this.m_methodDef = method.m_methodDef; this.m_tOwner = method.m_tOwner; this.m_descriptor = method.m_descriptor; this.m_name = method.m_name; this.m_attrs = method.m_attrs; this.m_returnParameter = method.m_returnParameter; this.m_methodBody = method.m_methodBody; this.m_declaringTypeDef = method.m_declaringTypeDef; this.m_sigBlob = method.m_sigBlob; this.m_typeArgs = method.m_typeArgs; this.m_methodArgs = method.m_methodArgs; this.m_context = method.m_context; this.m_fullyInitialized = method.m_fullyInitialized; }
internal static string GetCodeBaseFromManifestModule(MetadataOnlyModule manifestModule) { string str; string fullyQualifiedName = manifestModule.FullyQualifiedName; if (!Utility.IsValidPath(fullyQualifiedName)) { return(string.Empty); } try { str = (new Uri(fullyQualifiedName)).ToString(); } catch (Exception exception) { throw; } return(str); }
public static Assembly CreateAssembly(ITypeUniverse typeUniverse, MetadataFile manifestModuleImport, MetadataFile[] netModuleImports, IReflectionFactory factory, string manifestFile, string[] netModuleFiles) { int length = 1; if (netModuleImports != null) { length = length + (int)netModuleImports.Length; } MetadataOnlyModule[] metadataOnlyModule = new MetadataOnlyModule[length]; metadataOnlyModule[0] = new MetadataOnlyModule(typeUniverse, manifestModuleImport, factory, manifestFile); if (length > 1) { for (int i = 0; i < (int)netModuleImports.Length; i++) { metadataOnlyModule[i + 1] = new MetadataOnlyModule(typeUniverse, netModuleImports[i], factory, netModuleFiles[i]); } } return(new MetadataOnlyAssembly(metadataOnlyModule, manifestFile)); }
private static List <string> GetFileNamesFromFilesTable(MetadataOnlyModule manifestModule, bool getResources) { int num; int num1; int num2; UnusedIntPtr unusedIntPtr; uint num3; CorFileFlags corFileFlag; HCORENUM hCORENUM = new HCORENUM(); StringBuilder stringBuilder = new StringBuilder(); List <string> strs = new List <string>(); IMetadataAssemblyImport rawImport = (IMetadataAssemblyImport)manifestModule.RawImport; try { while (true) { rawImport.EnumFiles(ref hCORENUM, out num, 1, out num1); if (num1 == 0) { break; } rawImport.GetFileProps(num, null, 0, out num2, out unusedIntPtr, out num3, out corFileFlag); if (getResources || corFileFlag != CorFileFlags.ContainsNoMetaData) { if (num2 > stringBuilder.Capacity) { stringBuilder.Capacity = num2; } rawImport.GetFileProps(num, stringBuilder, num2, out num2, out unusedIntPtr, out num3, out corFileFlag); strs.Add(stringBuilder.ToString()); } } } finally { hCORENUM.Close(rawImport); } return(strs); }
public static IEnumerable <CustomAttributeData> GetTypeForwardedToAttributes(MetadataOnlyModule manifestModule) { ITypeUniverse assemblyResolver = manifestModule.AssemblyResolver; Type builtInType = assemblyResolver.GetBuiltInType(System.Reflection.Adds.CorElementType.Type); Assembly assembly = assemblyResolver.GetSystemAssembly(); Type type = assembly.GetType("System.Runtime.CompilerServices.TypeForwardedToAttribute", false, false); if (type != null) { foreach (UnresolvedTypeName rawTypeForwardedToAttribute in PseudoCustomAttributes.GetRawTypeForwardedToAttributes(manifestModule)) { ConstructorInfo[] constructorInfoArray = type.GetConstructors(); Type type1 = rawTypeForwardedToAttribute.ConvertToType(assemblyResolver, manifestModule); List <CustomAttributeTypedArgument> customAttributeTypedArguments = new List <CustomAttributeTypedArgument>(1) { new CustomAttributeTypedArgument(builtInType, type1) }; List <CustomAttributeNamedArgument> customAttributeNamedArguments = new List <CustomAttributeNamedArgument>(0); yield return(new MetadataOnlyCustomAttributeData(constructorInfoArray[0], customAttributeTypedArguments, customAttributeNamedArguments)); } } }
public static CustomAttributeData GetSerializableAttribute(MetadataOnlyModule module, Token token) { int num; TypeAttributes typeAttribute; int num1; if (token.TokenType != System.Reflection.Adds.TokenType.TypeDef) { return(null); } module.RawImport.GetTypeDefProps(token.Value, null, 0, out num, out typeAttribute, out num1); if ((typeAttribute & TypeAttributes.Serializable) == TypeAttributes.NotPublic) { return(null); } Assembly systemAssembly = module.AssemblyResolver.GetSystemAssembly(); ConstructorInfo[] constructors = systemAssembly.GetType("System.SerializableAttribute", true, false).GetConstructors(); List <CustomAttributeTypedArgument> customAttributeTypedArguments = new List <CustomAttributeTypedArgument>(0); List <CustomAttributeNamedArgument> customAttributeNamedArguments = new List <CustomAttributeNamedArgument>(0); return(new MetadataOnlyCustomAttributeData(constructors[0], customAttributeTypedArguments, customAttributeNamedArguments)); }
internal MetadataOnlyParameterInfo(MetadataOnlyModule resolver, Token parameterToken, Type paramType, CustomModifiers customModifiers) { uint num; uint num1; uint num2; uint num3; uint num4; UnusedIntPtr unusedIntPtr; this.m_resolver = resolver; this.m_parameterToken = parameterToken; this.m_paramType = paramType; this.m_customModifiers = customModifiers; IMetadataImport rawImport = this.m_resolver.RawImport; rawImport.GetParamProps(this.m_parameterToken, out this.m_parentMemberToken, out num, null, 0, out num4, out num1, out num2, out unusedIntPtr, out num3); StringBuilder stringBuilder = new StringBuilder((int)num4); rawImport.GetParamProps(this.m_parameterToken, out this.m_parentMemberToken, out num, stringBuilder, (uint)stringBuilder.Capacity, out num4, out num1, out num2, out unusedIntPtr, out num3); this.m_name = stringBuilder.ToString(); this.m_position = (int)(num - 1); this.m_attrib = (ParameterAttributes)num1; }
public override Type GetInterface(string name, bool ignoreCase) { return(MetadataOnlyModule.GetInterfaceHelper(this.GetInterfaces(), name, ignoreCase)); }
public override FieldInfo[] GetFields(BindingFlags flags) { return(MetadataOnlyModule.GetFieldsOnType(this, flags)); }
public override EventInfo[] GetEvents(BindingFlags flags) { return(MetadataOnlyModule.GetEventsOnType(this, flags)); }