本文整理汇总了C#中IInterceptor.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IInterceptor.GetType方法的具体用法?C# IInterceptor.GetType怎么用?C# IInterceptor.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInterceptor
的用法示例。
在下文中一共展示了IInterceptor.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public override Type Generate(IInterceptor interceptor, Type baseType, Type handlerType, params Type[] additionalInterfaceTypes)
{
var properties = this.GetProperties(baseType, additionalInterfaceTypes);
var methods = this.GetMethods(baseType, additionalInterfaceTypes);
var constructors = this.GetConstructors(baseType);
var targetClass = new CodeTypeDeclaration(string.Concat(baseType.Name, "_Dynamic"));
targetClass.IsClass = baseType.IsClass;
targetClass.TypeAttributes = TypeAttributes.Sealed | TypeAttributes.Serializable;
targetClass.BaseTypes.Add((baseType.IsInterface == false) ? baseType : typeof(object));
targetClass.BaseTypes.Add(proxyTypeReference.BaseType);
foreach (var additionalInterfaceType in additionalInterfaceTypes)
{
targetClass.BaseTypes.Add(additionalInterfaceType);
}
var samples = new CodeNamespace(baseType.Namespace);
samples.Imports.Add(new CodeNamespaceImport(typeof(string).Namespace));
samples.Types.Add(targetClass);
var targetUnit = new CodeCompileUnit();
targetUnit.Namespaces.Add(samples);
this.GenerateFields(targetClass, baseType, handlerType, (interceptor != null) ? interceptor.GetType() : null);
this.GenerateConstructors(targetClass, baseType, constructors);
this.GenerateMethods(targetClass, baseType, methods);
this.GenerateProperties(targetClass, baseType, properties);
var builder = new StringBuilder();
using (var sourceWriter = new StringWriter(builder))
{
provider.GenerateCodeFromCompileUnit(targetUnit, sourceWriter, options);
}
var parameters = new CompilerParameters() { GenerateInMemory = true };
this.AddReferences(parameters, baseType, handlerType, (interceptor != null) ? interceptor.GetType() : null, additionalInterfaceTypes);
var results = provider.CompileAssemblyFromDom(parameters, targetUnit);
if (results.Errors.HasErrors == true)
{
throw new InvalidOperationException(string.Join(Environment.NewLine, results.Errors.OfType<object>()));
}
return (results.CompiledAssembly.GetTypes().First());
}