本文整理汇总了C#中Castle.DynamicProxy.Generators.CacheKey类的典型用法代码示例。如果您正苦于以下问题:C# CacheKey类的具体用法?C# CacheKey怎么用?C# CacheKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheKey类属于Castle.DynamicProxy.Generators命名空间,在下文中一共展示了CacheKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例12: GetFromCache
protected Type GetFromCache(CacheKey key)
{
return scope.GetFromCache(key);
}
示例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];
}
示例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;
}
示例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;
}
}