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


C# ClassEmitter.CreateField方法代码示例

本文整理汇总了C#中Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateField方法的典型用法代码示例。如果您正苦于以下问题:C# ClassEmitter.CreateField方法的具体用法?C# ClassEmitter.CreateField怎么用?C# ClassEmitter.CreateField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Castle.DynamicProxy.Generators.Emitters.ClassEmitter的用法示例。


在下文中一共展示了ClassEmitter.CreateField方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateTargetField

		private FieldReference CreateTargetField(ClassEmitter emitter)
		{
			var targetField = emitter.CreateField("__target", targetType);
#if FEATURE_SERIALIZATION
			emitter.DefineCustomAttributeFor<XmlIgnoreAttribute>(targetField);
#endif
			return targetField;
		}
开发者ID:elevine,项目名称:Core,代码行数:8,代码来源:DelegateProxyGenerator.cs

示例2: CreateTargetField

		private FieldReference CreateTargetField(ClassEmitter emitter)
		{
			var targetField = emitter.CreateField("__target", targetType);
#if !SILVERLIGHT
			emitter.DefineCustomAttributeFor<XmlIgnoreAttribute>(targetField);
#endif
			return targetField;
		}
开发者ID:leloulight,项目名称:Core,代码行数:8,代码来源:DelegateProxyGenerator.cs

示例3: BuildMethodInterceptorsField

		protected FieldReference BuildMethodInterceptorsField(ClassEmitter @class, MethodInfo method, INamingScope namingScope)
		{
			var methodInterceptors = @class.CreateField(
				namingScope.GetUniqueName(string.Format("interceptors_{0}", method.Name)),
				typeof(IInterceptor[]),
				false);
#if !SILVERLIGHT
			@class.DefineCustomAttributeFor<XmlIgnoreAttribute>(methodInterceptors);
#endif
			return methodInterceptors;
		}
开发者ID:AndreKraemer,项目名称:Castle.Core,代码行数:11,代码来源:MethodWithInvocationGenerator.cs

示例4: CreateSelectorField

		protected void CreateSelectorField(ClassEmitter emitter)
		{
			if (ProxyGenerationOptions.Selector == null)
			{
				return;
			}

			emitter.CreateField("__selector", typeof(IInterceptorSelector));
			return;
		}
开发者ID:AGiorgetti,项目名称:Castle.Core,代码行数:10,代码来源:BaseProxyGenerator.cs

示例5: CreateInterceptorsField

		protected void CreateInterceptorsField(ClassEmitter emitter)
		{
			var interceptorsField = emitter.CreateField("__interceptors", typeof (IInterceptor[]));

#if !SILVERLIGHT
			emitter.DefineCustomAttributeFor<XmlIgnoreAttribute>(interceptorsField);
#endif
		}
开发者ID:AGiorgetti,项目名称:Castle.Core,代码行数:8,代码来源:BaseProxyGenerator.cs

示例6: CreateFieldWithAttributes

		public void CreateFieldWithAttributes()
		{
			ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes);
			emitter.CreateField("myField", typeof (string), FieldAttributes.FamANDAssem | FieldAttributes.InitOnly);
			Type t = emitter.BuildType();
			FieldInfo field = t.GetField("myField", BindingFlags.NonPublic | BindingFlags.Instance);
			Assert.IsNotNull(field);
			Assert.AreEqual(FieldAttributes.FamANDAssem | FieldAttributes.InitOnly, field.Attributes);
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:9,代码来源:ClassEmitterTestCase.cs

示例7: CreateFields

		private void CreateFields(ClassEmitter emitter, Type proxyTargetType)
		{
			base.CreateFields(emitter);
			targetField = emitter.CreateField("__target", proxyTargetType);

			emitter.DefineCustomAttributeFor<XmlIgnoreAttribute>(targetField);
		}
开发者ID:ThatExtraBit,项目名称:Castle.Core,代码行数:7,代码来源:InterfaceProxyWithTargetGenerator.cs

示例8: BuildTargetField

 private FieldReference BuildTargetField(ClassEmitter @class, Type type)
 {
     var name = "__mixin_" + type.FullName.Replace(".", "_");
     return @class.CreateField(namingScope.GetUniqueName(name), type);
 }
开发者ID:brianmatic,项目名称:n2cms,代码行数:5,代码来源:MixinContributor.cs

示例9: Build

		/// <summary>
		/// Builds the adapter.
		/// </summary>
		/// <returns></returns>
		public Type Build()
		{

			//Setup emitter 
			ClassEmitter classEmitter = new ClassEmitter(ModuleScope,
				OriginalObject.Name + "Adapter",
				typeof(AdapterBase),
				new Type[] { }, TypeAttributes.Class,
				true);

			//Add a field to hold a reference to the original object that is being adapter.
			FieldReference adaptedObjectReference = classEmitter.CreateField("_Original", OriginalObject);

			//Add a constructor that accepts a reference to the original object and
			//assigns that reference to the field.
			ArgumentReference parameter = new ArgumentReference(OriginalObject);
			ConstructorEmitter constructor = classEmitter.CreateConstructor(parameter);
			constructor.CodeBuilder.AddStatement(
				new AssignStatement(adaptedObjectReference, new ReferenceExpression(parameter)));
			constructor.CodeBuilder.AddStatement(new ReturnStatement());

			//For each method, walk the pipeline
			foreach (MethodInfo method in OriginalObject.GetMethods())
			{
				AdapterBuilderStageContext context =
					new AdapterBuilderStageContext(OriginalObject, classEmitter, adaptedObjectReference, method);
				WalkPipeline(context);
			}

			//build the type			
			return classEmitter.BuildType();

		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:37,代码来源:DynamicAdapterBuilder.cs

示例10: CreateInterceptorsField

		protected void CreateInterceptorsField(ClassEmitter emitter)
		{
			var interceptorsField = emitter.CreateField("__interceptors", typeof(IInterceptor[]));

#if FEATURE_SERIALIZATION
			emitter.DefineCustomAttributeFor<XmlIgnoreAttribute>(interceptorsField);
#endif
		}
开发者ID:textmetal,项目名称:main,代码行数:8,代码来源:BaseProxyGenerator.cs

示例11: CreateFields

		private void CreateFields(ClassEmitter emitter, Type proxyTargetType)
		{
			base.CreateFields(emitter);
			targetField = emitter.CreateField("__target", proxyTargetType);
#if FEATURE_SERIALIZATION
			emitter.DefineCustomAttributeFor<XmlIgnoreAttribute>(targetField);
#endif
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:8,代码来源:InterfaceProxyWithTargetGenerator.cs

示例12: AddMixinFields

		protected FieldReference[] AddMixinFields(ClassEmitter emitter)
		{
			List<FieldReference> mixins = new List<FieldReference>();
			foreach (Type type in ProxyGenerationOptions.MixinData.MixinInterfacesAndPositions.Keys)
			{
				FieldReference fieldReference = emitter.CreateField("__mixin_" + type.FullName.Replace(".", "_"), type);
				interface2MixinFieldReference[type] = fieldReference;
				mixins.Add(fieldReference);
			}
			return mixins.ToArray();
		}
开发者ID:ray2006,项目名称:WCell,代码行数:11,代码来源:BaseProxyGenerator.cs

示例13: ImplementProxiedMethod

		protected MethodEmitter ImplementProxiedMethod(
			Type targetType,
			MethodEmitter methodEmitter,
			MethodInfo method,
			ClassEmitter emitter,
			NestedClassEmitter invocationImpl,
			FieldReference interceptorsField,
			Reference targetRef,
			ConstructorVersion version,
			MethodInfo methodOnTarget)
		{
			CheckNotGenericTypeDefinition(targetType, "targetType");

			methodEmitter.CopyParametersAndReturnTypeFrom(method, emitter);

			TypeReference[] dereferencedArguments = IndirectReference.WrapIfByRef(methodEmitter.Arguments);

			Type iinvocation = invocationImpl.TypeBuilder;

			Trace.Assert(method.IsGenericMethod == iinvocation.IsGenericTypeDefinition);
			bool isGenericInvocationClass = false;
			Type[] genericMethodArgs = new Type[0];
			if (method.IsGenericMethod)
			{
				// bind generic method arguments to invocation's type arguments
				genericMethodArgs = methodEmitter.MethodBuilder.GetGenericArguments();
				iinvocation = iinvocation.MakeGenericType(genericMethodArgs);
				isGenericInvocationClass = true;
			}

			Expression typeTokenFieldExp = typeTokenField.ToExpression();
			Expression methodInfoTokenExp;

			string tokenFieldName;
			if (method2TokenField.ContainsKey(method)) // Token is in the cache
			{
				FieldReference methodTokenField = method2TokenField[method];
				tokenFieldName = methodTokenField.Reference.Name;
				methodInfoTokenExp = methodTokenField.ToExpression();
			}
			else
			{
				// Not in the cache: generic method
				MethodInfo genericMethod = method.MakeGenericMethod(genericMethodArgs);

				// Need random suffix added to the name, so that we don't end up with duplicate field names for
				// methods with the same name, but different generic parameters
				tokenFieldName = string.Format("{0}_{1}_{2}", genericMethod.Name, genericMethodArgs.Length,
				                               Guid.NewGuid().ToString("N"));
				methodInfoTokenExp = new MethodTokenExpression(genericMethod);
			}

			LocalReference invocationImplLocal = methodEmitter.CodeBuilder.DeclareLocal(iinvocation);

			// TODO: Initialize iinvocation instance with ordinary arguments and in and out arguments

			Expression interceptors = interceptorsField.ToExpression();

			// Create the field to store the selected interceptors for this method if an InterceptorSelector is specified
			FieldReference methodInterceptors = null;
			if (proxyGenerationOptions.Selector != null)
			{
				// If no interceptors are returned, should we invoke the base.Method directly? Looks like we should not.
				methodInterceptors = emitter.CreateField(string.Format("{0}_interceptors", tokenFieldName), typeof(IInterceptor[]));
			}

			ConstructorInfo constructor = invocationImpl.Constructors[0].ConstructorBuilder;
			if (isGenericInvocationClass)
			{
				constructor = TypeBuilder.GetConstructor(iinvocation, constructor);
			}

			NewInstanceExpression newInvocImpl;

			if (version == ConstructorVersion.WithTargetMethod)
			{
				Expression methodOnTargetTokenExp;

				if (method2TokenField.ContainsKey(methodOnTarget)) // Token is in the cache
				{
					methodOnTargetTokenExp = method2TokenField[methodOnTarget].ToExpression();
				}
				else
				{
					// Not in the cache: generic method

					methodOnTargetTokenExp = new MethodTokenExpression(methodOnTarget.MakeGenericMethod(genericMethodArgs));
				}
				if (methodInterceptors == null)
				{
					newInvocImpl = //actual contructor call
						new NewInstanceExpression(constructor,
						                          targetRef.ToExpression(),
						                          interceptors,
						                          typeTokenFieldExp,
						                          methodOnTargetTokenExp,
						                          methodInfoTokenExp,
						                          new ReferencesToObjectArrayExpression(dereferencedArguments),
						                          SelfReference.Self.ToExpression());
				}
//.........这里部分代码省略.........
开发者ID:ralescano,项目名称:castle,代码行数:101,代码来源:BaseProxyGenerator.cs

示例14: CreateFields

		private void CreateFields(ClassEmitter emitter, Type proxyTargetType)
		{
			base.CreateFields(emitter);
			targetField = emitter.CreateField("__target", proxyTargetType);

#if SILVERLIGHT
#warning XmlIncludeAttribute is in silverlight, do we want to explore this?
#else
			emitter.DefineCustomAttributeFor<XmlIgnoreAttribute>(targetField);
#endif
		}
开发者ID:AGiorgetti,项目名称:Castle.Core,代码行数:11,代码来源:InterfaceProxyWithTargetGenerator.cs


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