public TargetMethodContext CreateMethod(string name, MethodAttributes attrs, TypeReference returnType) { var method = new MethodDefinition(name, attrs, TypeDefinition.Module.Import(returnType)); var processor = ILProcessorFactory.GetOrCreateProcessor(method.Body); processor.Append(processor.Create(OpCodes.Nop)); processor.Append(processor.Create(OpCodes.Ret)); TypeDefinition.Methods.Add(method); return(MethodContextFactory.GetOrCreateContext(method)); }
public static TargetTypeContext GetOrCreateContext(TypeDefinition td) { lock (Contexts) { TargetTypeContext result; if (!Contexts.TryGetValue(td, out result)) { var ctors = td.Methods.Where(m => m.IsConstructor).Select(c => MethodContextFactory.GetOrCreateContext(c)).ToArray(); result = new TargetTypeContext(td, ctors); Contexts.Add(td, result); } return(result); } }