当前位置: 首页>>代码示例>>C#>>正文


C# Generators.CacheKey类代码示例

本文整理汇总了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;
        }
开发者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


注:本文中的Castle.DynamicProxy.Generators.CacheKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。