public static void LoadReferences(BaseModuleWeaver weaver) { _weaver = weaver; DebugWriteLineMethod = weaver.FindType("System.Diagnostics.Debug").Method("WriteLine"); StringFormatMethod = weaver.FindType("System.String").Method("Format", new string[] { "String", "Object[]" }); SystemTypeGetTypeFromHandleMethod = weaver.FindType("Type").Method("GetTypeFromHandle"); var typeDictionary = weaver.FindType("Dictionary`2"); var genericArg = new TypeReference[] { weaver.ModuleDefinition.TypeSystem.String, weaver.ModuleDefinition.TypeSystem.Object }; var genericDic = typeDictionary.MakeGenericInstanceType(genericArg); DictionaryConstructor = genericDic.Resolve().GetConstructors().FirstOrDefault(); DictionaryAddMethod = genericDic.Resolve().Method("Add"); //make ctor method has generic parms, cause Resolve() will remove generic parameters all DictionaryConstructor.DeclaringType = DictionaryConstructor.DeclaringType.MakeGenericInstanceType(genericArg); DictionaryAddMethod.DeclaringType = DictionaryAddMethod.DeclaringType.MakeGenericInstanceType(genericArg); #if DEBUG CacheAssembly = weaver.ResolveAssembly("Cache"); #else //load Cache reference var references = SplitUpReferences(weaver); AssemblyResolver = new AssemblyResolver(references); CacheAssembly = AssemblyResolver.Resolve("Cache"); #endif }
public void FindReferences(BaseModuleWeaver moduleWeaver) { var moduleDefinition = moduleWeaver.ModuleDefinition; SystemType = moduleWeaver.FindType("System.Type"); DebuggerBrowsableStateType = moduleWeaver.FindType("System.Diagnostics.DebuggerBrowsableState"); var listType = moduleWeaver.FindType("System.Collections.Generic.List`1"); ListCtor = moduleDefinition.ImportReference(listType.Methods.First(m => m.IsConstructor && m.Parameters.Count == 1 && m.Parameters[0].ParameterType.Name.StartsWith("IEnumerable"))); ListToArray = moduleDefinition.ImportReference(listType.Methods.First(m => m.Name == "ToArray")); var debuggerBrowsableAttribute = moduleWeaver.FindType("System.Diagnostics.DebuggerBrowsableAttribute"); DebuggerBrowsableAttributeCtor = moduleDefinition.ImportReference(debuggerBrowsableAttribute.Methods.First(x => x.IsConstructor)); var debuggerDisplayAttribute = moduleWeaver.FindType("System.Diagnostics.DebuggerDisplayAttribute"); DebuggerDisplayAttributeCtor = moduleDefinition.ImportReference(debuggerDisplayAttribute.Methods.First(x => x.IsConstructor)); var debuggerTypeProxyAttribute = moduleWeaver.FindType("System.Diagnostics.DebuggerTypeProxyAttribute"); DebuggerTypeProxyAttributeCtor = moduleDefinition.ImportReference(debuggerTypeProxyAttribute.Methods.First(x => x.IsConstructor && x.Parameters[0].ParameterType.FullName == "System.Type")); var compilerGeneratedAttribute = moduleWeaver.FindType("System.Runtime.CompilerServices.CompilerGeneratedAttribute"); CompilerGeneratedAttributeCtor = moduleDefinition.ImportReference(compilerGeneratedAttribute.Methods.First(x => x.IsConstructor)); StringFormat = moduleDefinition.ImportReference(moduleWeaver.FindType("System.String").Methods .First(m => m.Name == "Format" && m.Parameters.Count == 2 && m.Parameters[0].ParameterType.FullName == "System.String" && m.Parameters[1].ParameterType.FullName == "System.Object[]")); }
private static MethodReference GetMemberInfoNamePropertyGetMethod(BaseModuleWeaver weaver) { TypeDefinition memberInfoType = weaver.FindType(typeof(MemberInfo).FullName); PropertyDefinition memberInfoNameProperty = memberInfoType.Properties.Single(property => property.Name == nameof(MemberInfo.Name)); return(weaver.ModuleDefinition.ImportReference(memberInfoNameProperty.GetMethod)); }
private static MethodReference GetHasValueGetMethod(BaseModuleWeaver weaver) { TypeDefinition nullableType = weaver.FindType(typeof(Nullable <>).FullName); PropertyDefinition hasValueProperty = nullableType.Properties.Single(property => property.Name == nameof(Nullable <int> .HasValue)); return(weaver.ModuleDefinition.ImportReference(hasValueProperty.GetMethod)); }
private static MethodReference GetIndexerGetMethod(BaseModuleWeaver weaver) { TypeDefinition stringType = weaver.FindType(typeof(string).FullName); PropertyDefinition indexer = stringType.Properties.Single(property => property.Parameters.Count == 1 && property.Parameters[0].ParameterType.FullName == typeof(int).FullName); return(weaver.ModuleDefinition.ImportReference(indexer.GetMethod)); }
private static MethodReference GetToStringMethod(BaseModuleWeaver weaver) { TypeDefinition objectType = weaver.FindType(typeof(object).FullName); MethodDefinition objectToStringMethod = objectType.Methods.Single(method => method.IsStatic == false && method.Name == nameof(object.ToString) && method.Parameters.Count == 0); return(weaver.ModuleDefinition.ImportReference(objectToStringMethod)); }
private static MethodReference GetArgumentNullExceptionWithMessageConstructor(BaseModuleWeaver weaver) { TypeDefinition argumentNullExceptionType = weaver.FindType(typeof(ArgumentNullException).FullName); MethodDefinition argumentNullExceptionWithMessageConstructor = argumentNullExceptionType.Methods.Single(method => method.IsConstructor && method.Parameters.Count == 2 && method.Parameters[0].ParameterType.FullName == typeof(string).FullName && method.Parameters[1].ParameterType.FullName == typeof(string).FullName); return(weaver.ModuleDefinition.ImportReference(argumentNullExceptionWithMessageConstructor)); }
private static MethodReference GetGetTypeFromHandleMethod(BaseModuleWeaver weaver) { TypeDefinition typeType = weaver.FindType(typeof(Type).FullName); MethodDefinition getTypeFromHandleMethod = typeType.Methods.Single(method => method.IsStatic && method.Name == nameof(Type.GetTypeFromHandle) && method.Parameters.Count == 1 && method.Parameters[0].ParameterType.FullName == typeof(RuntimeTypeHandle).FullName); return(weaver.ModuleDefinition.ImportReference(getTypeFromHandleMethod)); }
private static MethodReference GetConcatThreeStringsMethod(BaseModuleWeaver weaver) { TypeDefinition stringType = weaver.FindType(typeof(string).FullName); MethodDefinition concatThreeStringsMethod = stringType.Methods.Single(method => method.IsStatic && method.Name == nameof(string.Concat) && method.Parameters.Count == 3 && method.Parameters[0].ParameterType.FullName == typeof(string).FullName && method.Parameters[1].ParameterType.FullName == typeof(string).FullName && method.Parameters[2].ParameterType.FullName == typeof(string).FullName); return(weaver.ModuleDefinition.ImportReference(concatThreeStringsMethod)); }
private static TypeReference GetNullableType(BaseModuleWeaver weaver) { return(weaver.ModuleDefinition.ImportReference(weaver.FindType(typeof(Nullable <>).FullName))); }