本文整理汇总了C#中Castle.DynamicProxy.ProxyGenerator类的典型用法代码示例。如果您正苦于以下问题:C# ProxyGenerator类的具体用法?C# ProxyGenerator怎么用?C# ProxyGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProxyGenerator类属于Castle.DynamicProxy命名空间,在下文中一共展示了ProxyGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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);
}
示例6: 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);
}
}
}
示例7: BuildProxy
public override object BuildProxy(ProxyGenerator generator, Type objType, CommonData data, object baseObj)
{
if (!objType.IsInterface)
{
throw new Exception("Set can only be created from ISet Interface");
}
object proxy;
if (baseObj == null)
{
proxy = generator.CreateInterfaceProxyWithoutTarget(objType,
new ProxyGenerationOptions(new GeneralProxyGenerationHook())
{
Selector = _setSelector
},
new GeneralGetInterceptor(data), new SetAddInterceptor(data), new SetRemoveInterceptor(data));
}
else
{
proxy = generator.CreateInterfaceProxyWithTarget(objType, baseObj,
new ProxyGenerationOptions(new GeneralProxyGenerationHook())
{
Selector = _setSelector
},
new GeneralGetInterceptor(data), new SetAddInterceptor(data), new SetRemoveInterceptor(data));
}
return proxy;
}
示例8: Main
public static int Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
var dokanOptions = new DokanOptions
{
MountPoint = "r:\\",
DebugMode = true,
UseStdErr = true,
VolumeLabel = "TAGFS",
ThreadCount = 1
};
var options = new TaggedFileSystemOptions { RootPath = "d:\\tmp" };
options.Init();
var databaseOriginal = new Database(options.ServicePath);
var taggedFileStorage = new TaggedFileStorage(databaseOriginal);
var target = new TaggedFileSystem(options, taggedFileStorage);
var fileSystemPxy = new ProxyGenerator()
.CreateInterfaceProxyWithTarget<DokanOperations>(
target,
new WrappingInterceptor(),
new TransactionManagementInterceptor(databaseOriginal)
);
var status = DokanNet.DokanMain(
dokanOptions,
fileSystemPxy
);
return status;
}
示例9: 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;
}
示例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: CastleDynamicProxyFactory
public CastleDynamicProxyFactory()
{
ConfigureDynamicProxyToAvoidReplicatingProblematicAttributes();
_proxyGenerator = new ProxyGenerator();
_allMethodsExceptCallRouterCallsHook = new AllMethodsExceptCallRouterCallsHook();
}
示例12: TrinketProxyEgg
public TrinketProxyEgg()
{
streamFactory = new StreamFactory();
processProxy = new ProcessProxy();
var pofContext = new PofContext().With(x => {
x.MergeContext(new DspPofContext());
x.MergeContext(new TrinketsApiPofContext());
x.MergeContext(new TrinketsImplPofContext());
});
ICollectionFactory collectionFactory = new CollectionFactory();
IFileSystemProxy fileSystemProxy = new FileSystemProxy(streamFactory);
IThreadingProxy threadingProxy = new ThreadingProxy(new ThreadingFactory(), new SynchronizationFactory());
var dnsProxy = new DnsProxy();
INetworkingProxy networkingProxy = new NetworkingProxy(new SocketFactory(new TcpEndPointFactory(dnsProxy), new NetworkingInternalFactory(threadingProxy, streamFactory)), new TcpEndPointFactory(dnsProxy));
pofSerializer = new PofSerializer(pofContext);
PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer);
ProxyGenerator proxyGenerator = new ProxyGenerator();
var serviceClientFactory = new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory);
// construct libdsp local service node
ClusteringConfiguration clusteringConfiguration = new ClientClusteringConfiguration();
ServiceClient localServiceClient = serviceClientFactory.Construct(clusteringConfiguration);
keepaliveObjects.Add(localServiceClient);
temporaryFileService = localServiceClient.GetService<TemporaryFileService>();
var processInjector = new ProcessInjectorImpl();
ProcessInjectionConfiguration processInjectionConfiguration = new ProcessInjectionConfigurationImpl(injectionAttempts: 10, injectionAttemptsDelay: 200);
processInjectionService = new ProcessInjectionServiceImpl(processInjector, processInjectionConfiguration);
IDtpNodeFactory transportNodeFactory = new DefaultDtpNodeFactory();
BootstrapConfigurationGenerator bootstrapConfigurationGenerator = new BootstrapConfigurationGeneratorImpl();
trinketInternalUtilities = new TrinketInternalUtilitiesImpl(fileSystemProxy);
trinketDtpServerFactory = new TrinketDtpServerFactoryImpl(streamFactory, transportNodeFactory, bootstrapConfigurationGenerator);
}
示例13: NullReturn
public void NullReturn()
{
var generator = new ProxyGenerator();
var t = generator.CreateClassProxy<SomethingToIntercept>(new ProcessInterceptor());
var r = t.NullReturn();
Assert.IsNull(r);
}
示例14: Decorate
/// <summary>
/// Decoration request
/// </summary>
/// <param name="context">Context info</param>
/// <remarks>do not have to decorate, but may if it wants to. sorta..</remarks>
public void Decorate(DecoratorContext context)
{
if (!CanDecorate(context))
return;
var options = new ProxyGenerationOptions();
var services = context.Services;
if (IgnoreClassAsService && services.Length > 1)
services = services.Where(x => !x.IsClass).ToArray();
var generator = new ProxyGenerator();
if (services.Any(x => x.IsClass))
{
if (services.Length > 1)
throw new InvalidOperationException(
"A class that register itself as a service may not also be registered with interfaces. See the remarks in the IgnoreClassAsService property.");
var clazz = context.Services.Single(x => x.IsClass);
context.Instance = generator.CreateClassProxyWithTarget(clazz, context.Instance,
CreateInterceptor(context));
}
else
{
var others = services.Where(x => x.IsInterface).Skip(1);
var first = services.First();
context.Instance = generator.CreateInterfaceProxyWithTarget
(first, others.ToArray(), context.Instance,
CreateInterceptor(context));
}
}
示例15: SpotiFireRegistry
public SpotiFireRegistry()
{
var pg = new ProxyGenerator();
//For<ISpotiFireService>().EnrichAllWith((context, z) => pg.CreateInterfaceProxyWithTarget(z, new SpotiFireServiceInterceptor(context.GetInstance<ILibraryValidator>()))).OnCreationForAll((context, x) => x.ConfigureSpotiFire());
For<ISpotiFireService>().HybridHttpOrThreadLocalScoped().Use<SpotiFireService>().OnCreation(x => x.ConfigureSpotiFire());
}