本文整理汇总了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);
}
示例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));
}
示例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));
}
示例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" }));
}
示例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" }));
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}
示例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();
}