public void Run(string [] args) { asses = args.Select (arg => univ.LoadFile (arg)).ToArray (); android_ass = asses.First (a => a.GetName ().Name == "Mono.Android"); CollectViews (); }
private static IKType Load(Type type) { IKType reference = null; if (!typeRegister.TryGetValue(type, out reference)) { r.Assembly assembly = null; if (!assemblyRegister.TryGetValue(type.Assembly, out assembly)) { assembly = universe.Load(type.Assembly.FullName); } reference = assembly.GetType(type.FullName, true); //reference = module. typeRegister.Add(type, reference); } return(reference); }
internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, ByteReader br) { this.lazyConstructor = constructor; if (br.Length == 0) { // it's legal to have an empty blob lazyConstructorArguments = Empty<CustomAttributeTypedArgument>.Array; lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array; } else { if (br.ReadUInt16() != 1) { throw new BadImageFormatException(); } lazyConstructorArguments = ReadConstructorArguments(asm, br, constructor); lazyNamedArguments = ReadNamedArguments(asm, br, br.ReadUInt16(), constructor.DeclaringType); } }
public static void Init(string baseCorlibDir) { if (baseCorlibDir == null) baseCorlibDir = typeof(int).Assembly.Location; mscorlib = universe.LoadFile(baseCorlibDir); if (mscorlib == null) { Report.Error($"Could not load mscorlib from {baseCorlibDir}"); } AttributeType = mscorlib.GetType("System.Attribute"); VoidType = mscorlib.GetType("System.Void"); IntPtrType = mscorlib.GetType("System.IntPtr"); UIntPtrType = mscorlib.GetType("System.UIntPtr"); StringType = mscorlib.GetType("System.String"); ObjectType = mscorlib.GetType("System.Object"); TypeType = mscorlib.GetType("System.Type"); MethodInfoType = mscorlib.GetType("System.Reflection.MethodInfo"); FieldInfoType = mscorlib.GetType("System.Reflection.FieldInfo"); PropertyInfoType = mscorlib.GetType("System.Reflection.PropertyInfo"); AssemblyType = mscorlib.GetType("System.Reflection.Assembly"); ModuleType = mscorlib.GetType("System.Reflection.Module"); }
internal MissingModule(Assembly assembly, int index) : base(assembly.universe) { this.assembly = assembly; this.index = index; }
private static bool IsSigned(Assembly asm) { byte[] key = asm.GetName().GetPublicKey(); return key != null && key.Length != 0; }
public virtual void __ResolveReferencedAssemblies(Assembly[] assemblies) { throw new NotSupportedException(); }
public static IList<CustomAttributeData> __GetCustomAttributes(Assembly assembly, Type attributeType, bool inherit) { return assembly.GetCustomAttributesData(attributeType); }
// 5) Unresolved declarative security internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, int securityAction, byte[] blob, int index) { this.module = asm.ManifestModule; this.customAttributeIndex = -1; this.declSecurityIndex = index; Universe u = constructor.Module.universe; this.lazyConstructor = constructor; List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>(); list.Add(new CustomAttributeTypedArgument(u.System_Security_Permissions_SecurityAction, securityAction)); this.lazyConstructorArguments = list.AsReadOnly(); this.declSecurityBlob = blob; }
private static IList<CustomAttributeTypedArgument> ReadConstructorArguments(Assembly asm, ByteReader br, ConstructorInfo constructor) { MethodSignature sig = constructor.MethodSignature; int count = sig.GetParameterCount(); List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>(count); for (int i = 0; i < count; i++) { list.Add(ReadFixedArg(asm, br, sig.GetParameterType(i))); } return list.AsReadOnly(); }
internal Assembly Load(string refname, Assembly requestingAssembly, bool throwOnError) { Assembly asm = GetLoadedAssembly(refname); if (asm != null) { return asm; } if (resolvers.Count == 0) { asm = DefaultResolver(refname, throwOnError); } else { ResolveEventArgs args = new ResolveEventArgs(refname, requestingAssembly); foreach (ResolveEventHandler evt in resolvers) { asm = evt(this, args); if (asm != null) { break; } } } if (asm != null) { string defname = asm.FullName; if (refname != defname) { assembliesByName.Add(refname, asm); } return asm; } if (throwOnError) { throw new FileNotFoundException(refname); } return null; }
public ResolveEventArgs(string name, Assembly requestingAssembly) { this.name = name; this.requestingAssembly = requestingAssembly; }
static void Process(Assembly asm) { currentAssembly = asm; string shortName = asm.GetName().Name; string name = shortName.Replace(".", "_"); var typeList = new List<IKVM.Reflection.Type>(); headerWriter.WriteLine("/*"); headerWriter.WriteLine(" * Automatically generated by thunktool from {0}", shortName); headerWriter.WriteLine(" */"); headerWriter.WriteLine(); headerWriter.WriteLine("#ifndef __{0}_THUNKTOOL__", name.ToUpperInvariant()); headerWriter.WriteLine("#define __{0}_THUNKTOOL__", name.ToUpperInvariant()); headerWriter.WriteLine(); headerWriter.WriteLine("#include <mono/utils/mono-publib.h>"); headerWriter.WriteLine("#include <mono/metadata/assembly.h>"); headerWriter.WriteLine("#include <mono/metadata/class.h>"); headerWriter.WriteLine("#include <mono/metadata/object.h>"); headerWriter.WriteLine(); headerWriter.WriteLine("MONO_BEGIN_DECLS"); headerWriter.WriteLine(); headerWriter.WriteLine("#ifdef WIN32"); headerWriter.WriteLine("#define THUNKCALL __stdcall"); headerWriter.WriteLine("#else"); headerWriter.WriteLine("#define THUNKCALL"); headerWriter.WriteLine("#endif"); headerWriter.WriteLine(); sourceWriter.WriteLine("/*"); sourceWriter.WriteLine(" * Automatically generated by thunktool from {0}", shortName); sourceWriter.WriteLine(" */"); sourceWriter.WriteLine(); sourceWriter.WriteLine("#include <stdlib.h>"); sourceWriter.WriteLine("#include <string.h>"); sourceWriter.WriteLine("#include <assert.h>"); sourceWriter.WriteLine("#include <mono/jit/jit.h>"); sourceWriter.WriteLine("#include <mono/metadata/reflection.h>"); sourceWriter.WriteLine("#include \"{0}.h\"", outputPrefix ?? "thunks"); sourceWriter.WriteLine(); foreach (var typeInfo in asm.GetTypes ()) { currentMethods = new List<ThunkMethodInfo>(); foreach (var ctor in typeInfo.GetConstructors ()) Process(ctor); foreach (var method in typeInfo.GetMethods ()) Process(method); foreach (var prop in typeInfo.GetProperties ()) Process(prop); if (currentMethods.Count == 0) continue; headerWriter.WriteLine("MonoClass *{0}__Class;", typeInfo.Name); foreach (var m in currentMethods) { headerWriter.WriteLine(); if (wantComments) headerWriter.WriteLine("/*\n * {0}\n */", m.Comments); if (!m.IsGeneric) headerWriter.WriteLine("{0}", m.QualMethodDecl); else headerWriter.WriteLine("MonoMethod *{0}__Method;", m.QualMethodName); } headerWriter.WriteLine(); sourceWriter.WriteLine("static void\n{0}_Init (MonoClass *klass)", typeInfo.Name); sourceWriter.WriteLine("{"); sourceWriter.WriteLine("\tMonoMethod *method;\n"); sourceWriter.WriteLine("\tassert (klass && \"could not lookup class '{0}'\");", typeInfo.FullName); sourceWriter.WriteLine("\t{0}__Class = klass;", typeInfo.Name); foreach (var m in currentMethods) { sourceWriter.WriteLine(); sourceWriter.WriteLine("\tmethod = mono_class_get_method_from_name (klass, \"{0}\", -1);", m.ClrMethodName); sourceWriter.WriteLine("\tassert (method && \"could not lookup method '{0}.{1}'\");", typeInfo.FullName, m.ClrMethodName); if (!m.IsGeneric) sourceWriter.WriteLine("\t{0} = mono_method_get_unmanaged_thunk (method);", m.QualMethodName); else sourceWriter.WriteLine("\t{0}__Method = method;", m.QualMethodName); } sourceWriter.WriteLine("}\n"); typeList.Add(typeInfo); } if (typeList.Count > 0) { headerWriter.WriteLine("MonoAssembly *{0}_Assembly;", name); headerWriter.WriteLine("MonoImage *{0}_Image;", name); headerWriter.WriteLine(); headerWriter.WriteLine("void\n{0}_Init (MonoAssembly *assembly);", name); headerWriter.WriteLine(); headerWriter.WriteLine("void\n{0}_Exec (void);", name); sourceWriter.WriteLine("void\n{0}_Init (MonoAssembly *assembly)", name); sourceWriter.WriteLine("{"); sourceWriter.WriteLine("\tstatic int initialized;"); sourceWriter.WriteLine("\tMonoImage *image;"); sourceWriter.WriteLine(); sourceWriter.WriteLine("\tif (initialized) return;"); sourceWriter.WriteLine(); sourceWriter.WriteLine("\tassert (assembly && \"{0}\");", name); sourceWriter.WriteLine("\timage = mono_assembly_get_image (assembly);"); sourceWriter.WriteLine("\t{0}_Assembly = assembly;", name); sourceWriter.WriteLine("\t{0}_Image = image;", name); sourceWriter.WriteLine(); foreach (var typeInfo in typeList) { sourceWriter.WriteLine("\t{1}_Init (mono_class_from_name (image, \"{0}\", \"{1}\"));", typeInfo.Namespace, typeInfo.Name); } sourceWriter.WriteLine(); sourceWriter.WriteLine("\tinitialized = 1;"); sourceWriter.WriteLine("}"); sourceWriter.WriteLine(); sourceWriter.WriteLine("void\n{0}_Exec (void)", name); sourceWriter.WriteLine("{"); sourceWriter.WriteLine("\tstatic int initialized;"); sourceWriter.WriteLine("\tchar *arg0;"); sourceWriter.WriteLine(); sourceWriter.WriteLine("\tif (initialized) return;"); sourceWriter.WriteLine("\tassert ({0}_Assembly);", name); sourceWriter.WriteLine("\targ0 = strdup(mono_image_get_filename ({0}_Image));", name); sourceWriter.WriteLine("\tmono_jit_exec (mono_domain_get (), {0}_Assembly, 1, &arg0);", name); sourceWriter.WriteLine("\tinitialized = 1;"); sourceWriter.WriteLine("}"); } headerWriter.WriteLine(); headerWriter.WriteLine("MONO_END_DECLS"); headerWriter.WriteLine("#endif"); }
private AssemblyName ReadCustomAttributesFromTemplateFile(string templateFile, AssemblyName aname) { // LAMESPEC: according to MSDN, the template assembly must have a // strong name but this is not enforced const IKR.UniverseOptions options = IKR.UniverseOptions.MetadataOnly; var universe = new IKR.Universe(options); var asm = universe.LoadFile(templateFile); // Create missing assemblies, we don't want to load them! // Code taken from ikdasm var names = new HashSet <string> (); IKR.AssemblyName[] assembly_refs = asm.ManifestModule.__GetReferencedAssemblies(); var resolved_assemblies = new IKR.Assembly [assembly_refs.Length]; for (int i = 0; i < resolved_assemblies.Length; i++) { string name = assembly_refs [i].Name; while (names.Contains(name)) { name = name + "_" + i; } names.Add(name); resolved_assemblies [i] = universe.CreateMissingAssembly(assembly_refs [i].FullName); } asm.ManifestModule.__ResolveReferencedAssemblies(resolved_assemblies); foreach (var attr_data in asm.__GetCustomAttributes(null, false)) { string asm_name = attr_data.AttributeType.Assembly.GetName().Name; if (asm_name != "mscorlib") { continue; } switch (attr_data.AttributeType.FullName) { case "System.Reflection.AssemblyKeyFileAttribute": { if (keyfile != null) { // ignore if specified on command line continue; } // / AssemblyKeyFileAttribute .ctor(string keyFile) string key_file_value = (string)attr_data.ConstructorArguments [0].Value; if (!String.IsNullOrEmpty(key_file_value)) { keyfile = Path.Combine(Path.GetDirectoryName(templateFile), key_file_value); } } break; case "System.Reflection.AssemblyDelaySignAttribute": { if (delaysign != DelaySign.NotSet) { // ignore if specified on command line continue; } // AssemblyDelaySignAttribute .ctor(bool delaySign) bool delay_sign_value = (bool)attr_data.ConstructorArguments [0].Value; delaysign = delay_sign_value ? DelaySign.Yes : DelaySign.No; } break; case "System.Reflection.AssemblyKeyNameAttribute": { if (keyname != null) { // ignore if specified on command line continue; } // AssemblyKeyNameAttribute .ctor(string keyName) string key_name_value = (string)attr_data.ConstructorArguments [0].Value; // ignore null or zero-length keyname if (!String.IsNullOrEmpty(key_name_value)) { keyname = key_name_value; } } break; } } var asm_name_for_template_file = asm.GetName(); aname.Version = asm_name_for_template_file.Version; aname.HashAlgorithm = asm_name_for_template_file.HashAlgorithm; return(aname); }
internal static void ReadDeclarativeSecurity(Assembly asm, List<CustomAttributeData> list, int action, ByteReader br) { Universe u = asm.universe; if (br.PeekByte() == '.') { br.ReadByte(); int count = br.ReadCompressedInt(); for (int j = 0; j < count; j++) { Type type = ReadType(asm, br); ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(u.System_Security_Permissions_SecurityAction); // LAMESPEC there is an additional length here (probably of the named argument list) byte[] blob = br.ReadBytes(br.ReadCompressedInt()); list.Add(new CustomAttributeData(asm, constructor, action, blob)); } } else { // .NET 1.x format (xml) char[] buf = new char[br.Length / 2]; for (int i = 0; i < buf.Length; i++) { buf[i] = br.ReadChar(); } string xml = new String(buf); ConstructorInfo constructor = u.System_Security_Permissions_PermissionSetAttribute.GetPseudoCustomAttributeConstructor(u.System_Security_Permissions_SecurityAction); List<CustomAttributeNamedArgument> args = new List<CustomAttributeNamedArgument>(); args.Add(new CustomAttributeNamedArgument(GetProperty(u.System_Security_Permissions_PermissionSetAttribute, "XML", u.System_String), new CustomAttributeTypedArgument(u.System_String, xml))); list.Add(new CustomAttributeData(asm.ManifestModule, constructor, new object[] { action }, args)); } }
public static IList<CustomAttributeData> __GetDeclarativeSecurity(Assembly assembly) { return assembly.ManifestModule.GetDeclarativeSecurity(0x20000001); }
private static Type ReadType(Assembly asm, ByteReader br) { string typeName = br.ReadString(); if (typeName == null) { return null; } if (typeName.Length > 0 && typeName[typeName.Length - 1] == 0) { // there are broken compilers that emit an extra NUL character after the type name typeName = typeName.Substring(0, typeName.Length - 1); } return asm.universe.GetType(asm, typeName, true); }
// note that context is slightly different from the calling assembly (System.Type.GetType), // because context is passed to the AssemblyResolve event as the RequestingAssembly public Type GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError) { TypeNameParser parser = TypeNameParser.Parse(assemblyQualifiedTypeName, throwOnError); if (parser.Error) { return null; } return parser.GetType(this, context, throwOnError, assemblyQualifiedTypeName); }
private static IList<CustomAttributeNamedArgument> ReadNamedArguments(Assembly asm, ByteReader br, int named, Type type) { List<CustomAttributeNamedArgument> list = new List<CustomAttributeNamedArgument>(named); for (int i = 0; i < named; i++) { byte fieldOrProperty = br.ReadByte(); Type fieldOrPropertyType = ReadFieldOrPropType(asm, br); string name = br.ReadString(); CustomAttributeTypedArgument value = ReadFixedArg(asm, br, fieldOrPropertyType); MemberInfo member; switch (fieldOrProperty) { case 0x53: member = GetField(type, name); break; case 0x54: member = GetProperty(type, name); break; default: throw new BadImageFormatException(); } if (member == null) { throw new BadImageFormatException(); } list.Add(new CustomAttributeNamedArgument(member, value)); } return list.AsReadOnly(); }
internal void RenameAssembly(Assembly assembly, AssemblyName oldName) { List<string> remove = new List<string>(); foreach (KeyValuePair<string, Assembly> kv in assembliesByName) { if (kv.Value == assembly) { remove.Add(kv.Key); } } foreach (string key in remove) { assembliesByName.Remove(key); } }
public AssemblyLocationProvider (Assembly assembly, MonoSymbolFile symbolFile, string seqPointDataPath) { this.assembly = assembly; this.symbolFile = symbolFile; this.seqPointDataPath = seqPointDataPath; }
IAssemblyReference GetAssemblyReference(Assembly scope) { if (scope == null || scope == currentAssemblyDefinition) return DefaultAssemblyReference.CurrentAssembly; return interningProvider.Intern (new DefaultAssemblyReference (scope.FullName)); }
public static IList<CustomAttributeData> GetCustomAttributes(Assembly assembly) { return assembly.GetCustomAttributesData(null); }
public IUnresolvedAssembly LoadAssembly(Assembly assembly) { if (assembly == null) throw new ArgumentNullException ("assembly"); // Read assembly and module attributes IList<IUnresolvedAttribute> assemblyAttributes = new List<IUnresolvedAttribute>(); IList<IUnresolvedAttribute> moduleAttributes = new List<IUnresolvedAttribute>(); AddAttributes(assembly, assemblyAttributes); AddAttributes(assembly.ManifestModule, moduleAttributes); assemblyAttributes = interningProvider.InternList(assemblyAttributes); moduleAttributes = interningProvider.InternList(moduleAttributes); currentAssemblyDefinition = assembly; currentAssembly = new IkvmUnresolvedAssembly (assembly.FullName, DocumentationProvider); currentAssembly.Location = assembly.Location; currentAssembly.AssemblyAttributes.AddRange(assemblyAttributes); currentAssembly.ModuleAttributes.AddRange(moduleAttributes); // Register type forwarders: foreach (var type in assembly.ManifestModule.__GetExportedTypes ()) { if (type.Assembly != assembly) { int typeParameterCount; string ns = type.Namespace; string name = ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount); ns = interningProvider.Intern(ns); name = interningProvider.Intern(name); var typeRef = new GetClassTypeReference(GetAssemblyReference(type.Assembly), ns, name, typeParameterCount); typeRef = interningProvider.Intern(typeRef); var key = new TopLevelTypeName(ns, name, typeParameterCount); currentAssembly.AddTypeForwarder(key, typeRef); } } // Create and register all types: var ikvmTypeDefs = new List<IKVM.Reflection.Type>(); var typeDefs = new List<DefaultUnresolvedTypeDefinition>(); foreach (var td in assembly.GetTypes ()) { if (td.DeclaringType != null) continue; CancellationToken.ThrowIfCancellationRequested(); if (IncludeInternalMembers || td.IsPublic) { string name = td.Name; if (name.Length == 0) continue; var t = CreateTopLevelTypeDefinition(td); ikvmTypeDefs.Add(td); typeDefs.Add(t); currentAssembly.AddTypeDefinition(t); // The registration will happen after the members are initialized } } // Initialize the type's members: for (int i = 0; i < typeDefs.Count; i++) { InitTypeDefinition(ikvmTypeDefs[i], typeDefs[i]); } // Freezing the assembly here is important: // otherwise it will be frozen when a compilation is first created // from it. But freezing has the effect of changing some collection instances // (to ReadOnlyCollection). This hidden mutation was causing a crash // when the FastSerializer was saving the assembly at the same time as // the first compilation was created from it. // By freezing the assembly now, we ensure it is usable on multiple // threads without issues. currentAssembly.Freeze(); var result = currentAssembly; currentAssembly = null; return result; }
public static IList<CustomAttributeData> __GetDeclarativeSecurity(Assembly assembly) { if (assembly.__IsMissing) { throw new MissingAssemblyException((MissingAssembly)assembly); } return assembly.ManifestModule.GetDeclarativeSecurity(0x20000001); }
void AddAttributes(Assembly assembly, IList<IUnresolvedAttribute> outputList) { AddCustomAttributes(assembly.CustomAttributes, outputList); AddSecurityAttributes(CustomAttributeData.__GetDeclarativeSecurity (assembly), outputList); // AssemblyVersionAttribute if (assembly.GetName ().Version != null) { var assemblyVersion = new DefaultUnresolvedAttribute(assemblyVersionAttributeTypeRef, new[] { KnownTypeReference.String }); assemblyVersion.PositionalArguments.Add(CreateSimpleConstantValue(KnownTypeReference.String, assembly.GetName ().Version.ToString())); outputList.Add(interningProvider.Intern(assemblyVersion)); } }
internal Module ToModule(Assembly assembly) { if (module.Assembly != null) { throw new InvalidOperationException(); } imported = true; module.SetAssembly(assembly); return module; }
internal static void ReadDeclarativeSecurity(Assembly asm, List<CustomAttributeData> list, int action, ByteReader br) { Universe u = asm.universe; if (br.PeekByte() == '.') { br.ReadByte(); int count = br.ReadCompressedInt(); for (int j = 0; j < count; j++) { Type type = ReadType(asm, br); ConstructorInfo constructor; if (type == u.System_Security_Permissions_HostProtectionAttribute && action == (int)System.Security.Permissions.SecurityAction.LinkDemand) { constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); } else { constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { u.System_Security_Permissions_SecurityAction }, null); } // LAMESPEC there is an additional length here (probably of the named argument list) ByteReader slice = br.Slice(br.ReadCompressedInt()); // LAMESPEC the count of named arguments is a compressed integer (instead of UInt16 as NumNamed in custom attributes) list.Add(new CustomAttributeData(constructor, action, ReadNamedArguments(asm, slice, slice.ReadCompressedInt(), type))); } } else { // .NET 1.x format (xml) char[] buf = new char[br.Length / 2]; for (int i = 0; i < buf.Length; i++) { buf[i] = br.ReadChar(); } string xml = new String(buf); ConstructorInfo constructor = u.System_Security_Permissions_PermissionSetAttribute.GetConstructor(new Type[] { u.System_Security_Permissions_SecurityAction }); List<CustomAttributeNamedArgument> args = new List<CustomAttributeNamedArgument>(); args.Add(new CustomAttributeNamedArgument(u.System_Security_Permissions_PermissionSetAttribute.GetProperty("XML"), new CustomAttributeTypedArgument(u.System_String, xml))); list.Add(new CustomAttributeData(constructor, action, args)); } }
internal static bool IsCoreAssembly(Assembly asm) { return asm.IsDefined(StaticCompiler.GetRuntimeType("IKVM.Attributes.RemappedClassAttribute"), false); }
private static Type ReadFieldOrPropType(Assembly asm, ByteReader br) { Universe u = asm.universe; switch (br.ReadByte()) { case Signature.ELEMENT_TYPE_BOOLEAN: return u.System_Boolean; case Signature.ELEMENT_TYPE_CHAR: return u.System_Char; case Signature.ELEMENT_TYPE_I1: return u.System_SByte; case Signature.ELEMENT_TYPE_U1: return u.System_Byte; case Signature.ELEMENT_TYPE_I2: return u.System_Int16; case Signature.ELEMENT_TYPE_U2: return u.System_UInt16; case Signature.ELEMENT_TYPE_I4: return u.System_Int32; case Signature.ELEMENT_TYPE_U4: return u.System_UInt32; case Signature.ELEMENT_TYPE_I8: return u.System_Int64; case Signature.ELEMENT_TYPE_U8: return u.System_UInt64; case Signature.ELEMENT_TYPE_R4: return u.System_Single; case Signature.ELEMENT_TYPE_R8: return u.System_Double; case Signature.ELEMENT_TYPE_STRING: return u.System_String; case Signature.ELEMENT_TYPE_SZARRAY: return ReadFieldOrPropType(asm, br).MakeArrayType(); case 0x55: return ReadType(asm, br); case 0x50: return u.System_Type; case 0x51: return u.System_Object; default: throw new InvalidOperationException(); } }
internal static void Load(Assembly assembly) { genericEnumEnumType = assembly.GetType(DotNetTypeWrapper.GenericEnumEnumTypeName); genericDelegateInterfaceType = assembly.GetType(DotNetTypeWrapper.GenericDelegateInterfaceTypeName); genericAttributeAnnotationType = assembly.GetType(DotNetTypeWrapper.GenericAttributeAnnotationTypeName); genericAttributeAnnotationMultipleType = assembly.GetType(DotNetTypeWrapper.GenericAttributeAnnotationMultipleTypeName); genericAttributeAnnotationReturnValueType = assembly.GetType(DotNetTypeWrapper.GenericAttributeAnnotationReturnValueTypeName); }
private static CustomAttributeTypedArgument ReadFixedArg(Assembly asm, ByteReader br, Type type) { Universe u = asm.universe; if (type == u.System_String) { return new CustomAttributeTypedArgument(type, br.ReadString()); } else if (type == u.System_Type) { return new CustomAttributeTypedArgument(type, ReadType(asm, br)); } else if (type == u.System_Object) { return ReadFixedArg(asm, br, ReadFieldOrPropType(asm, br)); } else if (type.IsArray) { int length = br.ReadInt32(); if (length == -1) { return new CustomAttributeTypedArgument(type, null); } Type elementType = type.GetElementType(); CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length]; for (int i = 0; i < length; i++) { array[i] = ReadFixedArg(asm, br, elementType); } return new CustomAttributeTypedArgument(type, array); } else if (type.IsEnum) { return new CustomAttributeTypedArgument(type, ReadFixedArg(asm, br, type.GetEnumUnderlyingTypeImpl()).Value); } else { switch (Type.GetTypeCode(type)) { case TypeCode.Boolean: return new CustomAttributeTypedArgument(type, br.ReadByte() != 0); case TypeCode.Char: return new CustomAttributeTypedArgument(type, br.ReadChar()); case TypeCode.Single: return new CustomAttributeTypedArgument(type, br.ReadSingle()); case TypeCode.Double: return new CustomAttributeTypedArgument(type, br.ReadDouble()); case TypeCode.SByte: return new CustomAttributeTypedArgument(type, br.ReadSByte()); case TypeCode.Int16: return new CustomAttributeTypedArgument(type, br.ReadInt16()); case TypeCode.Int32: return new CustomAttributeTypedArgument(type, br.ReadInt32()); case TypeCode.Int64: return new CustomAttributeTypedArgument(type, br.ReadInt64()); case TypeCode.Byte: return new CustomAttributeTypedArgument(type, br.ReadByte()); case TypeCode.UInt16: return new CustomAttributeTypedArgument(type, br.ReadUInt16()); case TypeCode.UInt32: return new CustomAttributeTypedArgument(type, br.ReadUInt32()); case TypeCode.UInt64: return new CustomAttributeTypedArgument(type, br.ReadUInt64()); default: throw new InvalidOperationException(); } } }