private MethodInfo CreateNonVirtualCallTrampoline(CodeGenerationContext context, MethodInfo method, string trampolineName) { var methodDeclaration = MethodDeclaration.CreateEquivalent(method); var trampoline = context.MutableType.AddMethod( trampolineName, MethodAttributes.Private, methodDeclaration, ctx => Expression.Call(ctx.This, NonVirtualCallMethodInfoAdapter.Adapt(method), ctx.Parameters.Cast <Expression>())); _memberEmitter.AddMethod(context, trampoline); return(trampoline); }
public void DefineTypeFacets() { EnsureState(2); if (_mutableType.BaseType != null) { _context.TypeBuilder.SetParent(_mutableType.BaseType); } if (_mutableType.MutableTypeInitializer != null) { _memberEmitter.AddConstructor(_context, _mutableType.MutableTypeInitializer); } // Creation of initialization members must happen before interfaces, fields or methods are added. var initializationMembers = _initializationBuilder.CreateInitializationMembers(_mutableType); var initializationMethod = initializationMembers != null ? initializationMembers.Item2 : null; _proxySerializationEnabler.MakeSerializable(_mutableType, initializationMethod); foreach (var attribute in _mutableType.AddedCustomAttributes) { _context.TypeBuilder.SetCustomAttribute(attribute); } foreach (var ifc in _mutableType.AddedInterfaces) { _context.TypeBuilder.AddInterfaceImplementation(ifc); } foreach (var field in _mutableType.AddedFields) { _memberEmitter.AddField(_context, field); } foreach (var ctor in _mutableType.AddedConstructors) { WireAndAddConstructor(_memberEmitter, _context, ctor, initializationMembers); } foreach (var method in _mutableType.AddedMethods) { _memberEmitter.AddMethod(_context, method); } // Note that accessor methods must be added before their associated properties and events. foreach (var property in _mutableType.AddedProperties) { _memberEmitter.AddProperty(_context, property); } foreach (var evt in _mutableType.AddedEvents) { _memberEmitter.AddEvent(_context, evt); } }