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


C# ClassEmitter.BuildType方法代码示例

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


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

示例1: AutomaticDefaultConstructorGenerationWithClosedGenericType

		public void AutomaticDefaultConstructorGenerationWithClosedGenericType()
		{
			ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "Foo", typeof (List<object>),
			                                        Type.EmptyTypes);
			Type t = emitter.BuildType();
			Activator.CreateInstance(t);
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:7,代码来源:ClassEmitterTestCase.cs

示例2: ForceUnsignedTrueWithSignedTypes

		public void ForceUnsignedTrueWithSignedTypes()
		{
			ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes,
			                                        TypeAttributes.Public, true);
			Type t = emitter.BuildType();
			Assert.IsFalse(StrongNameUtil.IsAssemblySigned(t.GetTypeInfo().Assembly));
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:7,代码来源:ClassEmitterTestCase.cs

示例3: ForceUnsignedFalseWithSignedTypes

		public void ForceUnsignedFalseWithSignedTypes()
		{
			const bool shouldBeSigned = true;
			ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes,
			                                        TypeAttributes.Public, false);
			Type t = emitter.BuildType();
			Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(t.GetTypeInfo().Assembly));
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:8,代码来源:ClassEmitterTestCase.cs

示例4: StaticMethodArguments

		public void StaticMethodArguments ()
		{
			ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (List<object>), Type.EmptyTypes);
			MethodEmitter methodEmitter = emitter.CreateMethod ("StaticMethod", MethodAttributes.Public | MethodAttributes.Static,
					typeof (string), typeof (string));
			methodEmitter.CodeBuilder.AddStatement (new ReturnStatement (methodEmitter.Arguments[0]));
			Type t = emitter.BuildType ();
			Assert.AreEqual ("five", t.GetMethod ("StaticMethod").Invoke (null, new object[] { "five" }));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:9,代码来源:ClassEmitterTestCase.cs

示例5: InstanceMethodArguments

		public void InstanceMethodArguments ()
		{
			ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (List<object>), Type.EmptyTypes);
			MethodEmitter methodEmitter = emitter.CreateMethod ("InstanceMethod", MethodAttributes.Public,
					typeof (string), typeof (string));
			methodEmitter.CodeBuilder.AddStatement (new ReturnStatement (methodEmitter.Arguments[0]));
			Type t = emitter.BuildType ();
			object instance = Activator.CreateInstance (t);
			Assert.AreEqual ("six", t.GetMethod ("InstanceMethod").Invoke (instance, new object[] { "six" }));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:10,代码来源:ClassEmitterTestCase.cs

示例6: ForceUnsignedFalseWithSignedTypes

		public void ForceUnsignedFalseWithSignedTypes()
		{
#if SILVERLIGHT // Silverlight does not allow us to sign generated assemblies
			const bool shouldBeSigned = false;
#else
			const bool shouldBeSigned = true;
#endif
			ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes,
			                                        TypeAttributes.Public, false);
			Type t = emitter.BuildType();
			Assert.AreEqual(shouldBeSigned, StrongNameUtil.IsAssemblySigned(t.Assembly));
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:12,代码来源:ClassEmitterTestCase.cs

示例7: 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

示例8: NestedInterface

		public void NestedInterface()
		{
			ClassEmitter outerEmitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "IOuter", null, Type.EmptyTypes, 
				TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Public, false);
			NestedClassEmitter innerEmitter = new NestedClassEmitter(outerEmitter, "IInner", 
				TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.NestedPublic, null, Type.EmptyTypes);
			innerEmitter.CreateMethod("MyMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual,
			                          typeof(void), Type.EmptyTypes);
			Type inner = innerEmitter.BuildType();
			Type outer = outerEmitter.BuildType();
			Assert.IsTrue(inner.IsInterface);
			MethodInfo method = inner.GetMethod("MyMethod");
			Assert.IsNotNull(method);
			Assert.AreSame(inner, outer.GetNestedType("IInner", BindingFlags.Public));
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:15,代码来源:ClassEmitterTestCase.cs

示例9: UsingClassEmitterForInterfaces

		public void UsingClassEmitterForInterfaces()
		{
			ClassEmitter emitter = new ClassEmitter(generator.ProxyBuilder.ModuleScope, "IFoo", null, Type.EmptyTypes, 
				TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Public, false);
			emitter.CreateMethod("MyMethod", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual,
			                     typeof(void), Type.EmptyTypes);
			Type t = emitter.BuildType();
			Assert.IsTrue(t.IsInterface);
			MethodInfo method = t.GetMethod("MyMethod");
			Assert.IsNotNull(method);
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:11,代码来源:ClassEmitterTestCase.cs

示例10: 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


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