本文整理汇总了C#中Castle.DynamicProxy.Generators.CacheKey类的典型用法代码示例。如果您正苦于以下问题:C# CacheKey类的具体用法?C# CacheKey怎么用?C# CacheKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheKey类属于Castle.DynamicProxy.Generators命名空间,在下文中一共展示了CacheKey类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetInvocationType
private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options)
{
var scope = emitter.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(emitter, options, namingScope)
.BuildType();
scope.RegisterInCache(key, invocation);
return invocation;
}
开发者ID:Biswo,项目名称:n2cms,代码行数:34,代码来源:InterfaceProxyWithoutTargetContributor.cs
示例2: GenerateCode
public Type GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
interfaces = TypeUtil.GetAllInterfaces(interfaces);
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
ProxyGenerationOptions = options;
var cacheKey = new CacheKey(targetType, interfaces, options);
return ObtainProxyType(cacheKey, (n, s) => GenerateType(n, interfaces, s));
}
开发者ID:elevine,项目名称:Core,代码行数:11,代码来源:ClassProxyGenerator.cs
示例3: GetInvocationType
private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options)
{
ModuleScope scope = emitter.ModuleScope;
CacheKey key = new CacheKey(method.Method, WCFCompositionInvocationTypeGenerator.BaseType, null, null);
Type invocation = scope.GetFromCache(key);
if (invocation == null)
{
invocation = new WCFCompositionInvocationTypeGenerator(method.Method.DeclaringType, method, method.Method, false, null).Generate(emitter, options, base.namingScope).BuildType();
scope.RegisterInCache(key, invocation);
}
return invocation;
}
开发者ID:Kjubo,项目名称:xms.core,代码行数:12,代码来源:WCFInterfaceProxyWithTargetInterfaceTargetContributor.cs
示例4: InstanceEquivalence
public void InstanceEquivalence()
{
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass), null, ProxyGenerationOptions.Default);
CacheKey key2 = new CacheKey(typeof (NonPublicConstructorClass), null, ProxyGenerationOptions.Default);
Assert.AreEqual(key1, key2);
key1 = new CacheKey(typeof (NonPublicConstructorClass), null, ProxyGenerationOptions.Default);
key2 = new CacheKey(typeof (NonPublicConstructorClass), null, new ProxyGenerationOptions());
Assert.AreEqual(key1, key2);
}
开发者ID:jeremymeng,项目名称:Core,代码行数:12,代码来源:CacheKeyTestCase.cs
示例5: InstanceEquivalence_WithInterfaces
public void InstanceEquivalence_WithInterfaces()
{
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass), new Type[0], ProxyGenerationOptions.Default);
CacheKey key2 = new CacheKey(typeof (NonPublicConstructorClass), new Type[0], ProxyGenerationOptions.Default);
Assert.AreEqual(key1, key2);
key1 =
new CacheKey(typeof (NonPublicConstructorClass), new Type[] {typeof (IDisposable)}, ProxyGenerationOptions.Default);
key2 =
new CacheKey(typeof (NonPublicConstructorClass), new Type[] {typeof (IDisposable)}, ProxyGenerationOptions.Default);
Assert.AreEqual(key1, key2);
}
开发者ID:jeremymeng,项目名称:Core,代码行数:14,代码来源:CacheKeyTestCase.cs
示例6: GenerateCode
public Type GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
CheckNotGenericTypeDefinition(proxyTargetType, "proxyTargetType");
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
EnsureValidBaseType(options.BaseTypeForInterfaceProxy);
ProxyGenerationOptions = options;
interfaces = TypeUtil.GetAllInterfaces(interfaces).ToArray();
var cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, options);
return ObtainProxyType(cacheKey, (n, s) => GenerateType(n, proxyTargetType, interfaces, s));
}
开发者ID:AndreKraemer,项目名称:Castle.Core,代码行数:15,代码来源:InterfaceProxyWithTargetGenerator.cs
示例7: GenerateCode
public Type GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
CheckNotGenericTypeDefinition(proxyTargetType, "proxyTargetType");
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
EnsureValidBaseType(options.BaseTypeForInterfaceProxy);
Type proxyType;
interfaces = TypeUtil.GetAllInterfaces(interfaces).ToArray();
CacheKey cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, options);
using (var locker = Scope.Lock.ForReadingUpgradeable())
{
Type cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.Debug("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Upgrade the lock to a write lock, then read again. This is to avoid generating duplicate types
// under heavy multithreaded load.
locker.Upgrade();
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.Debug("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Log details about the cache miss
Logger.Debug("No cached proxy type was found for target type {0}.", targetType.FullName);
EnsureOptionsOverrideEqualsAndGetHashCode(options);
ProxyGenerationOptions = options;
var name = Scope.NamingScope.GetUniqueName("Castle.Proxies." + targetType.Name + "Proxy");
proxyType = GenerateType(name, proxyTargetType, interfaces, Scope.NamingScope.SafeSubScope());
AddToCache(cacheKey, proxyType);
}
return proxyType;
}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:47,代码来源:InterfaceProxyWithTargetGenerator.cs
示例8: DifferentOptions
public void DifferentOptions()
{
ProxyGenerationOptions options1 = new ProxyGenerationOptions();
ProxyGenerationOptions options2 = new ProxyGenerationOptions();
options1.BaseTypeForInterfaceProxy = typeof (IConvertible);
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass), null, options1);
CacheKey key2 = new CacheKey(typeof (NonPublicConstructorClass), null, options2);
Assert.AreNotEqual(key1, key2);
options1 = new ProxyGenerationOptions();
options2 = new ProxyGenerationOptions();
options2.Selector = new AllInterceptorSelector();
key1 = new CacheKey(typeof (NonPublicConstructorClass), null, options1);
key2 = new CacheKey(typeof (NonPublicConstructorClass), null, options2);
Assert.AreNotEqual(key1, key2);
}
开发者ID:jeremymeng,项目名称:Core,代码行数:18,代码来源:CacheKeyTestCase.cs
示例9: DifferentKeys
public void DifferentKeys()
{
CacheKey key1 = new CacheKey(typeof (NonPublicConstructorClass), null, ProxyGenerationOptions.Default);
CacheKey key2 = new CacheKey(typeof (NonPublicMethodsClass), null, ProxyGenerationOptions.Default);
Assert.AreNotEqual(key1, key2);
key1 =
new CacheKey(typeof (NonPublicConstructorClass), new Type[] {typeof (IDisposable)}, ProxyGenerationOptions.Default);
key2 =
new CacheKey(typeof (NonPublicConstructorClass), new Type[] {typeof (IConvertible)}, ProxyGenerationOptions.Default);
Assert.AreNotEqual(key1, key2);
key1 =
new CacheKey(typeof (NonPublicConstructorClass), new Type[] {typeof (IDisposable)}, ProxyGenerationOptions.Default);
key2 = new CacheKey(typeof (NonPublicMethodsClass), new Type[] {typeof (IDisposable)}, ProxyGenerationOptions.Default);
Assert.AreNotEqual(key1, key2);
}
开发者ID:jeremymeng,项目名称:Core,代码行数:20,代码来源:CacheKeyTestCase.cs
示例10: GetInvocationType
private Type GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options)
{
var scope = emitter.ModuleScope;
var key = new CacheKey(method.Method, InterfaceInvocationTypeGenerator.BaseType, null, null);
// no locking required as we're already within a lock
var invocation = scope.GetFromCache(key);
if (invocation != null)
{
return invocation;
}
invocation = new InterfaceInvocationTypeGenerator(method.Method.DeclaringType,
method,
method.Method,
false)
.Generate(emitter, options, namingScope).BuildType();
scope.RegisterInCache(key, invocation);
return invocation;
}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:22,代码来源:InterfaceProxyWithoutTargetContributor.cs
示例11: GetGeneratedType
public Type GetGeneratedType()
{
Type proxyType;
var cacheKey = new CacheKey(targetType, additionalInterfacesToProxy, ProxyGenerationOptions);
using (var locker = Scope.Lock.ForReadingUpgradeable())
{
var cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.Debug("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Upgrade the lock to a write lock, then read again. This is to avoid generating duplicate types
// under heavy multithreaded load.
locker.Upgrade();
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.Debug("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Log details about the cache miss
Logger.Debug("No cached proxy type was found for target type {0}.", targetType.FullName);
EnsureOptionsOverrideEqualsAndGetHashCode(ProxyGenerationOptions);
var name = Scope.NamingScope.GetUniqueName("Castle.Proxies." + targetType.Name + "Proxy");
proxyType = GenerateType(name, Scope.NamingScope.SafeSubScope());
AddToCache(cacheKey, proxyType);
}
return proxyType;
}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:37,代码来源:ClassProxyWithTargetGenerator.cs
示例12: GetFromCache
protected Type GetFromCache(CacheKey key)
{
return scope.GetFromCache(key);
}
开发者ID:AGiorgetti,项目名称:Castle.Core,代码行数:4,代码来源:BaseProxyGenerator.cs
示例13: GetFromCache
/// <summary>
/// Returns a type from this scope's type cache, or null if the key cannot be found.
/// </summary>
/// <param name="key">The key to be looked up in the cache.</param>
/// <returns>The type from this scope's type cache matching the key, or null if the key cannot be found</returns>
public Type GetFromCache (CacheKey key)
{
// no lock needed, typeCache is synchronized
return (Type) typeCache[key];
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:10,代码来源:ModuleScope.cs
示例14: RegisterInCache
/// <summary>
/// Registers a type in this scope's type cache.
/// </summary>
/// <param name="key">The key to be associated with the type.</param>
/// <param name="type">The type to be stored in the cache.</param>
public void RegisterInCache (CacheKey key, Type type)
{
// no lock needed, typeCache is synchronized
typeCache[key] = type;
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:10,代码来源:ModuleScope.cs
示例15: ObtainProxyType
protected Type ObtainProxyType(CacheKey cacheKey, Func<string, INamingScope, Type> factory)
{
using (var locker = Scope.Lock.ForReadingUpgradeable())
{
var cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.DebugFormat("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Upgrade the lock to a write lock, then read again. This is to avoid generating duplicate types
// under heavy multithreaded load.
locker.Upgrade();
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.DebugFormat("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Log details about the cache miss
Logger.DebugFormat("No cached proxy type was found for target type {0}.", targetType.FullName);
EnsureOptionsOverrideEqualsAndGetHashCode(ProxyGenerationOptions);
var name = Scope.NamingScope.GetUniqueName("Castle.Proxies." + targetType.Name + "Proxy");
var proxyType = factory.Invoke(name, Scope.NamingScope.SafeSubScope());
AddToCache(cacheKey, proxyType);
return proxyType;
}
}
开发者ID:mbrit,项目名称:MoqForWinRT,代码行数:33,代码来源:BaseProxyGenerator.cs
示例16: GetInvocationType
private Type GetInvocationType(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options)
{
var scope = @class.ModuleScope;
var 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 = BuildInvocationType(method, @class, options);
scope.RegisterInCache(key, invocation);
return invocation;
}
开发者ID:gitter-badger,项目名称:MobileMoq,代码行数:20,代码来源:ClassProxyWithTargetTargetContributor.cs
示例17: GetProxyType
public Type GetProxyType()
{
var cacheKey = new CacheKey(targetType, null, null);
return ObtainProxyType(cacheKey, GenerateType);
}
开发者ID:leloulight,项目名称:Core,代码行数:5,代码来源:DelegateProxyGenerator.cs
示例18: GenerateCode
public Type GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
CheckNotGenericTypeDefinition(proxyTargetType, "proxyTargetType");
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
Type generatedType;
ReaderWriterLock rwlock = Scope.RWLock;
rwlock.AcquireReaderLock(-1);
CacheKey cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, options);
Type cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
rwlock.ReleaseReaderLock();
return cacheType;
}
rwlock.UpgradeToWriterLock(-1);
try
{
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
return cacheType;
}
SetGenerationOptions (options);
String newName = targetType.Name + "Proxy" + Guid.NewGuid().ToString("N");
// Add Interfaces that the proxy implements
ArrayList interfaceList = new ArrayList();
interfaceList.Add(targetType);
if (interfaces != null)
{
interfaceList.AddRange(interfaces);
}
if (!interfaceList.Contains(typeof(ISerializable)))
interfaceList.Add(typeof(ISerializable));
AddMixinInterfaces(interfaceList);
AddDefaultInterfaces(interfaceList);
Type baseType = options.BaseTypeForInterfaceProxy;
ClassEmitter emitter = BuildClassEmitter(newName, baseType, interfaceList);
CreateOptionsField (emitter);
emitter.DefineCustomAttribute(new XmlIncludeAttribute(targetType));
emitter.DefineCustomAttribute(new SerializableAttribute());
// Custom attributes
ReplicateNonInheritableAttributes(targetType, emitter);
// Fields generations
FieldReference interceptorsField = emitter.CreateField("__interceptors", typeof(IInterceptor[]));
targetField = emitter.CreateField("__target", proxyTargetType);
emitter.DefineCustomAttributeFor(interceptorsField, new XmlIgnoreAttribute());
emitter.DefineCustomAttributeFor(targetField, new XmlIgnoreAttribute());
// Implement builtin Interfaces
ImplementProxyTargetAccessor(targetType, emitter,interceptorsField);
// Collect methods
PropertyToGenerate[] propsToGenerate;
EventToGenerate[] eventToGenerates;
MethodInfo[] methods = CollectMethodsAndProperties(emitter, targetType, out propsToGenerate, out eventToGenerates);
if (interfaces != null && interfaces.Length != 0)
{
ArrayList tmpInterfaces = new ArrayList(interfaces);
foreach(Type inter in interfaces)
{
if (inter.IsAssignableFrom(proxyTargetType))
{
PropertyToGenerate[] tempPropsToGenerate;
EventToGenerate[] tempEventToGenerates;
MethodInfo[] methodsTemp =
CollectMethodsAndProperties(emitter, inter, out tempPropsToGenerate, out tempEventToGenerates);
PropertyToGenerate[] newPropsToGenerate =
new PropertyToGenerate[tempPropsToGenerate.Length + propsToGenerate.Length];
MethodInfo[] newMethods = new MethodInfo[methodsTemp.Length + methods.Length];
EventToGenerate[] newEvents = new EventToGenerate[eventToGenerates.Length + tempEventToGenerates.Length];
//.........这里部分代码省略.........
开发者ID:pallmall,项目名称:WCell,代码行数:101,代码来源:InterfaceProxyWithTargetGenerator.cs
示例19: GenerateCode
public Type GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
{
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
Type type;
ReaderWriterLock rwlock = Scope.RWLock;
rwlock.AcquireReaderLock(-1);
CacheKey cacheKey = new CacheKey(targetType, interfaces, options);
Type cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
rwlock.ReleaseReaderLock();
return cacheType;
}
rwlock.UpgradeToWriterLock(-1);
try
{
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
return cacheType;
}
String newName = targetType.Name + "Proxy" + Guid.NewGuid().ToString("N");
// Add Interfaces that the proxy implements
ArrayList interfaceList = new ArrayList();
if (interfaces != null)
{
interfaceList.AddRange(interfaces);
}
AddDefaultInterfaces(interfaceList);
if (targetType.IsSerializable)
{
delegateToBaseGetObjectData = VerifyIfBaseImplementsGetObjectData(targetType);
if (!interfaceList.Contains(typeof(ISerializable)))
{
interfaceList.Add(typeof(ISerializable));
}
}
ClassEmitter emitter = BuildClassEmitter(newName, targetType, interfaceList);
SetGenerationOptions (options, emitter);
emitter.DefineCustomAttribute(new XmlIncludeAttribute(targetType));
// Custom attributes
ReplicateNonInheritableAttributes(targetType, emitter);
// Fields generations
FieldReference interceptorsField =
emitter.CreateField("__interceptors", typeof(IInterceptor[]));
// Implement builtin Interfaces
ImplementProxyTargetAccessor(targetType, emitter,interceptorsField);
emitter.DefineCustomAttributeFor(interceptorsField, new XmlIgnoreAttribute());
// Collect methods
PropertyToGenerate[] propsToGenerate;
EventToGenerate[] eventToGenerates;
MethodInfo[] methods = CollectMethodsAndProperties(emitter, targetType, out propsToGenerate, out eventToGenerates);
options.Hook.MethodsInspected();
// Constructor
ConstructorEmitter typeInitializer = GenerateStaticConstructor(emitter);
CreateInitializeCacheMethodBody(targetType, methods, emitter, typeInitializer);
GenerateConstructors(emitter, targetType, interceptorsField);
GenerateParameterlessConstructor(emitter, targetType, interceptorsField);
if (delegateToBaseGetObjectData)
{
GenerateSerializationConstructor(emitter, interceptorsField, delegateToBaseGetObjectData);
}
// Implement interfaces
if (interfaces != null && interfaces.Length != 0)
{
foreach(Type inter in interfaces)
{
//.........这里部分代码省略.........
开发者ID:havard,项目名称:strongbind,代码行数:101,代码来源:ClassProxyGenerator.cs
示例20: GetGeneratedType
public Type GetGeneratedType()
{
var cacheKey = new CacheKey(targetType, targetType, additionalInterfacesToProxy, ProxyGenerationOptions);
return ObtainProxyType(cacheKey, GenerateType);
}
开发者ID:gitter-badger,项目名称:MobileMoq,代码行数:5,代码来源:ClassProxyWithTargetGenerator.cs
注:本文中的Castle.DynamicProxy.Generators.CacheKey类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论