本文整理汇总了C#中Castle.DynamicProxy.ProxyGenerator.CreateClassProxy方法的典型用法代码示例。如果您正苦于以下问题:C# ProxyGenerator.CreateClassProxy方法的具体用法?C# ProxyGenerator.CreateClassProxy怎么用?C# ProxyGenerator.CreateClassProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle.DynamicProxy.ProxyGenerator
的用法示例。
在下文中一共展示了ProxyGenerator.CreateClassProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DynamicProxyHelper
public DynamicProxyHelper(SerializationInfo info, StreamingContext context)
{
_info = info;
_context = context;
_argumentsForConstructor = (Type[])info.GetValue(DynamicPropertyChangedProxy.ARGUMENTS_TYPES4CONSTRUCTOR, typeof(Type[]));
_valuesForConstructor = (object[])info.GetValue(DynamicPropertyChangedProxy.VALUES4CONSTRUCTOR, typeof(object[]));
_baseTypeName = (string)info.GetValue(DynamicPropertyChangedProxy.OBJECT_BASE_TYPE, typeof(string));
bool isBusinessObj = (bool)info.GetValue(DynamicPropertyChangedProxy.IS_BUSINESS_OBJECT, typeof(bool));
_baseT = Type.GetType(_baseTypeName, true, false);
Type firstProxyType;
object[] baseMemberData = (object[])_info.GetValue(DynamicPropertyChangedProxy.SERIALIZED_DATA, typeof(object[]));
ProxyGenerator generator = new ProxyGenerator();
if (isBusinessObj)
{
// the business objects have to have a default constructor
firstProxyType = DynamicPropertyChangedProxy.CreateBusinessObjectProxy(_baseT, _argumentsForConstructor);
_proxy = generator.CreateClassProxy(firstProxyType, (IInterceptor[])baseMemberData[0]);
}
else
{
// if it is not a business object then it has to be a BindableFields class which constructor has always an interceptor
firstProxyType = DynamicPropertyChangedProxy.CreateBindableWrapperProxy(_baseT, _argumentsForConstructor, _valuesForConstructor);
_proxy = generator.CreateClassProxy(firstProxyType, (IInterceptor[])baseMemberData[0], _valuesForConstructor);
}
}
示例2: DynamicProxy
public void DynamicProxy()
{
var g = new ProxyGenerator();
//g.CreateInterfaceProxyWithTarget()
var cs = g.CreateClassProxy<ComparerCS>(new TestInterceptor()) as IComparer;
var cs2 = g.CreateClassProxy(typeof (ComparerCS), new[] {typeof (IComparer)}, new TestInterceptor()) as IComparer;
var vb = g.CreateClassProxy<ComparerVB>(new TestInterceptor()) as IComparer;
var fs = g.CreateClassProxy<ComparerFS>(new TestInterceptor()) as IComparer;
cs.Compare(0, 0);
cs2.Compare(0, 0);
}
示例3: InitializeProxy
public void InitializeProxy()
{
IBar bar = new Bar();
var pg = new ProxyGenerator();
this.BarInterfaceProxy = pg.CreateInterfaceProxyWithTarget(bar, new CacheInterceptor());
this.FooBarProxy = pg.CreateClassProxy<FooBar>(new CacheInterceptor());
}
示例4: Parallel
public void Parallel()
{
var generator = new ProxyGenerator();
var t = generator.CreateClassProxy<SomethingToIntercept>(new ProcessInterceptor());
var r = Enumerable.Range(0, 100).AsParallel().Sum(i => t.Add(i, i));
Assert.AreEqual(9900, r);
}
示例5: NullReturn
public void NullReturn()
{
var generator = new ProxyGenerator();
var t = generator.CreateClassProxy<SomethingToIntercept>(new ProcessInterceptor());
var r = t.NullReturn();
Assert.IsNull(r);
}
示例6: TrySetActionInvoker
internal static IController TrySetActionInvoker(this IController iController, IGlimpseLogger logger)
{
var controller = iController as Controller;
if (controller == null)
{
//TODO: Add Logging
return iController;
}
var actionInvoker = controller.ActionInvoker;
if (actionInvoker.CanSupportDynamicProxy(logger))
{
var proxyConfig = new Dictionary<string, IInterceptor>
{
{"GetFilters", new GetFiltersInterceptor()},
{"InvokeActionResult", new InvokeActionResultInterceptor()},
{"InvokeActionMethod",new InvokeActionMethodInterceptor()}
};
var proxyGenerator = new ProxyGenerator();
var proxyGenOptions = new ProxyGenerationOptions(new SimpleProxyGenerationHook(logger, proxyConfig.Keys.ToArray())) { Selector = new SimpleInterceptorSelector(proxyConfig) };
var newInvoker = (ControllerActionInvoker)proxyGenerator.CreateClassProxy(actionInvoker.GetType(), proxyGenOptions, proxyConfig.Values.ToArray());
controller.ActionInvoker = newInvoker;
}
return controller;
}
示例7: Call
public void Call()
{
var generator = new ProxyGenerator();
var t = generator.CreateClassProxy<SomethingToIntercept>(new ProcessInterceptor());
var r = t.DoSomething("a", "b");
Assert.AreEqual("ab", r);
}
示例8: Proceed
public override void Proceed()
{
var expectation = stubMessageBus.GetExpectationFor(Request.GetType());
if (expectation == null)
{
var response = (Response)Activator.CreateInstance(Request.GetResponseType());
response.CorrelationGuid = Request.CorrelationGuid;
Response = GetSerializedVersion(response);
}
else
{
Response = GetSerializedVersion(expectation.Execute(Request));
}
if(Request.IsSideEffectFree)
{
try
{
var options = new ProxyGenerationOptions(new NonVirtualCheckProxyGenerationHook());
var proxyGen = new ProxyGenerator();
proxyGen.CreateClassProxy(Request.GetResponseType(), options);
}
catch (Exception ex)
{
throw new ColomboTestSupportException(string.Format("Response {0} cannot be proxied, probably because one or several of its members are not virtual.", Request.GetResponseType()), ex);
}
}
}
示例9: CreateProxy
private object CreateProxy(Type type, object settings)
{
var proxyGenerator = new ProxyGenerator();
var settingsInterceptor = SetInterceptor(type, settings);
var proxy = proxyGenerator.CreateClassProxy(type, settingsInterceptor);
return proxy;
}
示例10: WrapInterface
/// <summary>
/// �����ʽʵ��������
/// </summary>
/// <param name="engine"></param>
/// <returns></returns>
public static object WrapInterface(Type engine)
{
ProxyInterceptor proxyInterceptor = new ProxyInterceptor();
ProxyGenerator generator = new ProxyGenerator();
object proxy = generator.CreateClassProxy(engine, proxyInterceptor);
return proxy;
}
示例11: Main
static void Main(string[] args)
{
System.Console.WriteLine("现在是Castle的代理在运行");
ProxyGenerator generator = new ProxyGenerator();
object proxy = generator.CreateClassProxy(typeof(RealA), new ProxyInterceptor());
(proxy as RealA).DoSomething();
System.Console.ReadLine();
}
示例12: Main
static void Main(string[] args)
{
var proxyGenerator = new ProxyGenerator();
var svc = proxyGenerator
.CreateClassProxy<TwitterClient>(
new MyInterceptorAspect());
svc.Send("hi");
}
示例13: Foo1
public void Foo1()
{
ProxyGenerator generator = new ProxyGenerator();
Castle.DynamicProxy.IInterceptor[] interceptors = { new MyCastleInterceptor() };
CastleUserProcessor userProcessor = generator.CreateClassProxy<CastleUserProcessor>(interceptors);
User user = new User() { Name = "lee", PassWord = "123123123123" };
userProcessor.RegUser(user);
}
示例14: LoadObjectDefinitions
protected override void LoadObjectDefinitions(DefaultListableObjectFactory objectFactory)
{
//wrap the objectFactory with our own proxy so that we keep track of the objects ids defined in the Spring.NET context
callbacks.Add(new BeanohObjectFactoryMethodInterceptor(objectFactory));
ProxyGenerator generator = new ProxyGenerator();
DefaultListableObjectFactory wrapper = (DefaultListableObjectFactory)generator.CreateClassProxy(objectFactory.GetType(), callbacks.ToArray());
//delegate to our proxy
base.LoadObjectDefinitions(wrapper);
}
示例15: Foo1
public void Foo1()
{
ProxyGenerator generator = new ProxyGenerator();
//Castle.DynamicProxy.IInterceptor[] interceptors = { new MyCastleInterceptor() };
var options = new ProxyGenerationOptions(new InterceptorFilter()) { Selector = new InterceptorSelector() };
CastleUserProcessor userProcessor = generator.CreateClassProxy<CastleUserProcessor>(options,new MyCastleInterceptor(), new SimpleLogInterceptor());
User user = new User() { Name = "lee", PassWord = "123123123123" };
userProcessor.RegUser(user);
}