コード例 #1
0
        public void LoadReferences()
        {
            List <TypeDefinition> coreTypes = new List <TypeDefinition>();

            AppendTypes("System.Runtime.Extensions", coreTypes);
            AppendTypes("System", coreTypes);
            AppendTypes("mscorlib", coreTypes);
            AppendTypes("System.Runtime", coreTypes);
            AppendTypes("System.Reflection", coreTypes);

            TypeDefinition debugType = GetDebugType(coreTypes);

            DebugWriteLineMethod =
                debugType.Methods.First(
                    method =>
                    method.Matches("WriteLine", ModuleDefinition.TypeSystem.Void, new[] { ModuleDefinition.TypeSystem.String }));

            StringFormatMethod =
                ModuleDefinition.TypeSystem.String.Resolve()
                .Methods.First(
                    method =>
                    method.Matches("Format", ModuleDefinition.TypeSystem.String,
                                   new[] { ModuleDefinition.TypeSystem.String, ModuleDefinition.TypeSystem.Object.MakeArrayType() }));

            CompilerGeneratedAttribute = coreTypes.First(t => t.Name == "CompilerGeneratedAttribute");

            DictionaryInterface = GetDictionaryInterface(coreTypes);

            DictionaryType = GetDictionaryType(coreTypes);
            DictionaryGenericInstanceType = DictionaryType.MakeGenericInstanceType(ModuleDefinition.TypeSystem.String,
                                                                                   ModuleDefinition.TypeSystem.Object);

            DictionaryConstructor =
                DictionaryGenericInstanceType.Resolve()
                .GetConstructors()
                .First(x => !x.Parameters.Any())
                .MakeHostInstanceGeneric(ModuleDefinition.TypeSystem.String, ModuleDefinition.TypeSystem.Object);

            DictionaryAddMethod =
                DictionaryGenericInstanceType.Resolve()
                .Methods.First(
                    method =>
                    method.Matches("Add", ModuleDefinition.TypeSystem.Void,
                                   new TypeReference[] { DictionaryType.GenericParameters[0], DictionaryType.GenericParameters[1] }))
                .MakeHostInstanceGeneric(ModuleDefinition.TypeSystem.String, ModuleDefinition.TypeSystem.Object);

            SystemTypeType = GetSystemTypeType(coreTypes);

            SystemTypeGetTypeFromHandleMethod =
                SystemTypeType.Resolve()
                .Methods.First(
                    method =>
                    method.Matches("GetTypeFromHandle", SystemTypeType,
                                   new TypeReference[] { GetSystemRuntimeTypeHandleType(coreTypes) }));
        }