本文整理汇总了C#中System.Reflection.Emit.TypeBuilder.AsType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.AsType方法的具体用法?C# TypeBuilder.AsType怎么用?C# TypeBuilder.AsType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.AsType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OrElse_NoMethod_TrueOperatorIncorrectMethod_ThrowsArgumentException
public static void OrElse_NoMethod_TrueOperatorIncorrectMethod_ThrowsArgumentException(TypeBuilder builder, Type returnType, Type[] parameterTypes)
{
MethodBuilder opTrue = builder.DefineMethod("op_True", MethodAttributes.SpecialName | MethodAttributes.Static, returnType, parameterTypes);
opTrue.GetILGenerator().Emit(OpCodes.Ret);
MethodBuilder opFalse = builder.DefineMethod("op_False", MethodAttributes.SpecialName | MethodAttributes.Static, typeof(bool), new Type[] { builder.AsType() });
opFalse.GetILGenerator().Emit(OpCodes.Ret);
MethodBuilder method = builder.DefineMethod("op_BitwiseOr", MethodAttributes.Public | MethodAttributes.Static, builder.AsType(), new Type[] { builder.AsType(), builder.AsType() });
method.GetILGenerator().Emit(OpCodes.Ret);
TypeInfo createdType = builder.CreateTypeInfo();
object obj = Activator.CreateInstance(createdType.AsType());
Assert.Throws<ArgumentException>(null, () => Expression.OrElse(Expression.Constant(obj), Expression.Constant(obj)));
}
示例2: DefineTypeHelper
public DefineTypeHelper(Parser parser, ModuleBuilder module, TypeDefinitionAst typeDefinitionAst, string typeName)
{
_moduleBuilder = module;
_parser = parser;
_typeDefinitionAst = typeDefinitionAst;
List<Type> interfaces;
var baseClass = this.GetBaseTypes(parser, typeDefinitionAst, out interfaces);
_typeBuilder = module.DefineType(typeName, Reflection.TypeAttributes.Class | Reflection.TypeAttributes.Public, baseClass, interfaces.ToArray());
_staticHelpersTypeBuilder = module.DefineType(string.Format(CultureInfo.InvariantCulture, "{0}_<staticHelpers>", typeName), Reflection.TypeAttributes.Class);
DefineCustomAttributes(_typeBuilder, typeDefinitionAst.Attributes, _parser, AttributeTargets.Class);
_typeDefinitionAst.Type = _typeBuilder.AsType();
_fieldsToInitForMemberFunctions = new List<Tuple<string, object>>();
_definedMethods = new Dictionary<string, List<Tuple<FunctionMemberAst, Type[]>>>(StringComparer.OrdinalIgnoreCase);
_definedProperties = new Dictionary<string, PropertyMemberAst>(StringComparer.OrdinalIgnoreCase);
_sessionStateField = _typeBuilder.DefineField(SessionStateFieldName, typeof(SessionStateInternal), FieldAttributes.Private);
_sessionStateKeeperField = _staticHelpersTypeBuilder.DefineField(s_sessionStateKeeperFieldName, typeof(SessionStateKeeper), FieldAttributes.Assembly | FieldAttributes.Static);
}