本文整理汇总了C#中System.Reflection.Emit.TypeBuilder.GenerateMethodForDirectCall方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.GenerateMethodForDirectCall方法的具体用法?C# TypeBuilder.GenerateMethodForDirectCall怎么用?C# TypeBuilder.GenerateMethodForDirectCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.GenerateMethodForDirectCall方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DynamicType
private DynamicType(Type interfaceType, OrderedDictionary<Type, List<MethodInfo, MethodInfo>> methods, List<Delegate, MethodInfo> delegates, List<MethodInfo> stubs) {
var counter = 0;
_dynamicType = DefineDynamicType(interfaceType);
// if the declaring type contains an OUE method declaration, then the host is permitting the plugin to see their oewn unhandled exceptions for debugging purposes.
OnUnhandledException = interfaceType.GetVirtualMethods().FirstOrDefault(each => each.Name == "OnUnhandledException" && each.GetParameterTypes().SequenceEqual(new Type[] {typeof (string), typeof (Exception)}));
foreach (var instanceType in methods.Keys) {
// generate storage for object
var field = _dynamicType.DefineField("_instance_{0}".format(++counter), instanceType, FieldAttributes.Private);
_storageFields.Add(field);
// create methods
foreach (var method in methods[instanceType]) {
_dynamicType.GenerateMethodForDirectCall(method.Key, field, method.Value, OnUnhandledException);
_implementedMethods.Add(method.Key.Name);
}
}
foreach (var d in delegates) {
var field = _dynamicType.DefineField("_delegate_{0}".format(++counter), d.Key.GetType(), FieldAttributes.Private);
_storageFields.Add(field);
_implementedMethods.Add(d.Value.Name);
_dynamicType.GenerateMethodForDelegateCall(d.Value, field, OnUnhandledException);
}
foreach (var method in stubs) {
// did not find a matching method or signature, or the instance told us that it doesn't actually support it
// that's ok, if we get here, it must not be a required method.
// we'll implement a placeholder method for it.
_dynamicType.GenerateStubMethod(method);
}
_dynamicType.GenerateIsMethodImplemented();
// generate the constructor for the class.
DefineConstructor(interfaceType.GetTypeInfo().IsInterface ? typeof (Object) : interfaceType);
}