本文整理汇总了C#中ProxyGenerationOptions类的典型用法代码示例。如果您正苦于以下问题:C# ProxyGenerationOptions类的具体用法?C# ProxyGenerationOptions怎么用?C# ProxyGenerationOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProxyGenerationOptions类属于命名空间,在下文中一共展示了ProxyGenerationOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCtorArgumentsAndBaseCtorToCall
protected override ArgumentReference[] GetCtorArgumentsAndBaseCtorToCall(Type targetFieldType, ProxyGenerationOptions proxyGenerationOptions,out ConstructorInfo baseConstructor)
{
if (proxyGenerationOptions.Selector == null)
{
baseConstructor = InvocationMethods.CompositionInvocationConstructorNoSelector;
return new[]
{
new ArgumentReference(targetFieldType),
new ArgumentReference(typeof(object)),
new ArgumentReference(typeof(IInterceptor[])),
new ArgumentReference(typeof(MethodInfo)),
new ArgumentReference(typeof(object[])),
};
}
baseConstructor = InvocationMethods.CompositionInvocationConstructorWithSelector;
return new[]
{
new ArgumentReference(targetFieldType),
new ArgumentReference(typeof(object)),
new ArgumentReference(typeof(IInterceptor[])),
new ArgumentReference(typeof(MethodInfo)),
new ArgumentReference(typeof(object[])),
new ArgumentReference(typeof(IInterceptorSelector)),
new ArgumentReference(typeof(IInterceptor[]).MakeByRefType())
};
}
示例2: GetMethodGenerator
protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
ProxyGenerationOptions options,
OverrideMethodDelegate overrideMethod)
{
if (!method.Proxyable)
{
return new ForwardingMethodGenerator(method,
overrideMethod,
(c, m) => c.GetField("__target"));
}
var targetMethod = options.ProxyEffectiveType == null ? method.Method : InvocationHelper.GetMethodOnType(proxyTargetType, method.Method);
if (targetMethod == null)
{
return new MinimialisticMethodGenerator(method, overrideMethod);
}
var invocation = GetInvocationType(method, targetMethod, @class, options);
return new MethodWithInvocationGenerator(method,
@class.GetField("__interceptors"),
invocation,
(c, m) => c.GetField("__target").ToExpression(),
overrideMethod,
null);
}
示例3: CacheKey
/// <summary>
/// Initializes a new instance of the <see cref = "CacheKey" /> class.
/// </summary>
/// <param name = "target">Target element. This is either target type or target method for invocation types.</param>
/// <param name = "type">The type of the proxy. This is base type for invocation types.</param>
/// <param name = "interfaces">The interfaces.</param>
/// <param name = "options">The options.</param>
private CacheKey(MemberWrapper target, Type type, Type[] interfaces, ProxyGenerationOptions options)
{
this.target = target;
this.type = type;
this.interfaces = interfaces ?? TypeExtender.EmptyTypes;
this.options = options;
}
示例4: GetMethodGenerator
protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
ProxyGenerationOptions options,
OverrideMethodDelegate overrideMethod)
{
if (methodsToSkip.Contains(method.Method))
return null;
if (!method.Proxyable)
{
return new MinimialisticMethodGenerator(method,
overrideMethod);
}
if (ExplicitlyImplementedInterfaceMethod(method))
{
#if SILVERLIGHT
return null;
#else
return ExplicitlyImplementedInterfaceMethodGenerator(method, @class, options, overrideMethod);
#endif
}
var invocation = GetInvocationType(method, @class, options);
return new MethodWithInvocationGenerator(method,
@class.GetField("__interceptors"),
invocation,
(c, m) => new TypeTokenExpression(targetType),
overrideMethod,
null);
}
示例5: GetFieldInterceptionProxy
/// <summary>
/// Returns a proxy capable of field interception.
/// </summary>
/// <returns></returns>
public override object GetFieldInterceptionProxy()
{
var proxyGenerationOptions = new ProxyGenerationOptions();
var interceptor = new LazyFieldInterceptor();
proxyGenerationOptions.AddMixinInstance(interceptor);
return ProxyGenerator.CreateClassProxy(PersistentClass, proxyGenerationOptions, interceptor);
}
示例6: GetInvocationType
private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options)
{
var scope = @class.ModuleScope;
Type[] invocationInterfaces;
if (canChangeTarget)
{
invocationInterfaces = new[] { typeof(IInvocation), typeof(IChangeProxyTarget) };
}
else
{
invocationInterfaces = new[] { typeof(IInvocation) };
}
var key = new CacheKey(method.Method, CompositionInvocationTypeGenerator.BaseType, invocationInterfaces, null);
// no locking required as we're already within a lock
var invocation = scope.GetFromCache(key);
if (invocation != null)
{
return invocation;
}
invocation = new CompositionInvocationTypeGenerator(method.Method.DeclaringType,
method,
method.Method,
canChangeTarget,
null)
.Generate(@class, options, namingScope).BuildType();
scope.RegisterInCache(key, invocation);
return invocation;
}
示例7: Generate
public virtual void Generate(ClassEmitter @class, ProxyGenerationOptions options)
{
foreach (var method in methods)
{
if (!method.Standalone)
{
continue;
}
ImplementMethod(method,
@class,
options,
@class.CreateMethod);
}
foreach (var property in properties)
{
ImplementProperty(@class, property, options);
}
foreach (var @event in events)
{
ImplementEvent(@class, @event, options);
}
}
示例8: CacheKey
/// <summary>
/// Initializes a new instance of the <see cref = "CacheKey" /> class.
/// </summary>
/// <param name = "target">Target element. This is either target type or target method for invocation types.</param>
/// <param name = "type">The type of the proxy. This is base type for invocation types.</param>
/// <param name = "interfaces">The interfaces.</param>
/// <param name = "options">The options.</param>
public CacheKey(MemberInfo target, Type type, Type[] interfaces, ProxyGenerationOptions options)
{
this.target = target;
this.type = type;
this.interfaces = interfaces ?? Type.EmptyTypes;
this.options = options;
}
示例9: GetMethodGenerator
protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class,
ProxyGenerationOptions options,
OverrideMethodDelegate overrideMethod)
{
if (methodsToSkip.Contains(method.Method))
{
return null;
}
if (!method.Proxyable)
{
return new MinimialisticMethodGenerator(method,
overrideMethod);
}
if (IsDirectlyAccessible(method) == false)
{
return IndirectlyCalledMethodGenerator(method, @class, options, overrideMethod);
}
var invocation = GetInvocationType(method, @class, options);
return new MethodWithInvocationGenerator(method,
@class.GetField("__interceptors"),
invocation,
(c, m) => c.GetField("__target").ToExpression(),
overrideMethod,
null);
}
示例10: SetGenerationOptions
protected void SetGenerationOptions (ProxyGenerationOptions options)
{
if (proxyGenerationOptions != null)
{
throw new InvalidOperationException ("ProxyGenerationOptions can only be set once.");
}
proxyGenerationOptions = options;
}
示例11: On_interfaces
public void On_interfaces()
{
ProxyGenerationOptions options = new ProxyGenerationOptions();
options.AttributesToAddToGeneratedTypes.Add(new __Protect());
object proxy = new ProxyGenerator().CreateInterfaceProxyWithoutTarget(typeof(IDisposable), new Type[0], options);
Assert.IsTrue(proxy.GetType().IsDefined(typeof(__Protect), false));
}
示例12: On_class
public void On_class()
{
var options = new ProxyGenerationOptions();
options.AdditionalAttributes.Add(AttributeUtil.CreateInfo<__Protect>());
var proxy = generator.CreateClassProxy(typeof(CanDefineAdditionalCustomAttributes), options);
Assert.IsTrue(proxy.GetType().GetTypeInfo().IsDefined(typeof(__Protect), false));
}
示例13: On_interfaces
public void On_interfaces()
{
var options = new ProxyGenerationOptions();
options.AdditionalAttributes.Add(AttributeUtil.CreateInfo<__Protect>());
var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IDisposable), new Type[0], options);
Assert.IsTrue(proxy.GetType().GetTypeInfo().IsDefined(typeof(__Protect), false));
}
示例14: SetGenerationOptions
protected void SetGenerationOptions (ProxyGenerationOptions options, ClassEmitter emitter)
{
if (proxyGenerationOptions != null)
{
throw new InvalidOperationException ("ProxyGenerationOptions can only be set once.");
}
proxyGenerationOptions = options;
proxyGenerationOptionsField = emitter.CreateStaticField ("proxyGenerationOptions", typeof (ProxyGenerationOptions));
}
示例15: Generate
public virtual void Generate(ClassEmitter @class, ProxyGenerationOptions options)
{
var interceptors = @class.GetField("__interceptors");
ImplementProxyTargetAccessor(@class, interceptors);
foreach (var attribute in targetType.GetNonInheritableAttributes())
{
@class.DefineCustomAttribute(attribute);
}
}