Castle.DynamicProxy.Builder.CodeGenerators.InterfaceProxyGenerator.GenerateCode C# (CSharp) Method

GenerateCode() public method

public GenerateCode ( Type interfaces, Type targetType ) : Type
interfaces System.Type
targetType System.Type
return System.Type
		public virtual Type GenerateCode(Type[] interfaces, Type targetType)
		{
			if (Context.HasMixins)
			{
				_mixins = Context.MixinsAsArray();
				Type[] mixinInterfaces = InspectAndRegisterInterfaces(_mixins);
				interfaces = Join(interfaces, mixinInterfaces);
			}

			//interfaces = AddISerializable(interfaces);
			interfaces = AddInterfaces(new Type[] {typeof(ISerializable), typeof(IProxy)}, interfaces);

			ReaderWriterLock rwlock = ModuleScope.RWLock;

			rwlock.AcquireReaderLock(-1);

			Type cacheType = GetFromCache(targetType, interfaces);

			if (cacheType != null)
			{
				rwlock.ReleaseReaderLock();

				return cacheType;
			}

			rwlock.UpgradeToWriterLock(-1);

			try
			{
				cacheType = GetFromCache(targetType, interfaces);

				if (cacheType != null)
				{
					return cacheType;
				}

				_targetType = targetType;

				CreateTypeBuilder(GenerateTypeName(targetType, interfaces), typeof(Object), interfaces);
				GenerateFields();
				ImplementGetObjectData(interfaces);
				ImplementCacheInvocationCache();
				GenerateInterfaceImplementation(interfaces);
				GenerateConstructor();

				return CreateType();
			}
			finally
			{
				rwlock.ReleaseWriterLock();
			}
		}
	}

Usage Example

Example #1
0
		public virtual Type CreateCustomInterfaceProxy(Type[] interfaces, Type type, GeneratorContext context)
		{
			InterfaceProxyGenerator generator = new InterfaceProxyGenerator(_scope, context);
			return generator.GenerateCode(interfaces, type);
		}
All Usage Examples Of Castle.DynamicProxy.Builder.CodeGenerators.InterfaceProxyGenerator::GenerateCode