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


C# AST.EmitILToLoadEngine方法代码示例

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


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

示例1: Emit

      internal static void Emit(AST ast, ILGenerator il, Type source_type, Type target_type, bool truncationPermitted){
        if (source_type == target_type) return;
        if (target_type == Typeob.Void){
          il.Emit(OpCodes.Pop);
          return;
        }
        if (target_type.IsEnum){
          if (source_type == Typeob.String || source_type == Typeob.Object){
            il.Emit(OpCodes.Ldtoken, target_type);
            il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod);
            ConstantWrapper.TranslateToILInt(il, truncationPermitted ? 1 : 0);
            il.Emit(OpCodes.Call, CompilerGlobals.coerceTMethod);
            Convert.EmitUnbox(il, target_type, Type.GetTypeCode(Convert.GetUnderlyingType(target_type)));
          }else
            Convert.Emit(ast, il, source_type, Convert.GetUnderlyingType(target_type));
          return;
        }
        if (source_type.IsEnum){
          if (target_type.IsPrimitive){
            Convert.Emit(ast, il, Convert.GetUnderlyingType(source_type), target_type);
            return;
          }
          if (target_type == Typeob.Object || target_type == typeof(Enum)){
            il.Emit(OpCodes.Box, source_type);
            return;
          }
          if (target_type == Typeob.String){
            il.Emit(OpCodes.Box, source_type);
            ConstantWrapper.TranslateToILInt(il, 0);
            il.Emit(OpCodes.Call, CompilerGlobals.toStringMethod);
            return;
          }
        }

        while (source_type is TypeBuilder){
          source_type = source_type.BaseType;
          if (source_type == null) source_type = Typeob.Object; //It is an interface
          if (source_type == target_type) return;
        }

        if (source_type.IsArray && target_type.IsArray)
          //This should only be called if the two types are known to be compatible, so:
          return;

        TypeCode source = Type.GetTypeCode(source_type);
        TypeCode target = target_type is TypeBuilder ? TypeCode.Object : Type.GetTypeCode(target_type);
        switch (source){
          case TypeCode.Empty: //can never occur
            return;

          case TypeCode.Object:
            if (source_type == Typeob.Void){
              il.Emit(OpCodes.Ldnull);
              source_type = Typeob.Object;
            }
            switch (target){
              case TypeCode.Object:
                //The conversion from function object to delegate never happens here. ConstantWrapper takes care of it.
                //First check for array target type or TypeBuilder target type. These do not support IsAssignableFrom.
                if (target_type.IsArray || target_type == Typeob.Array){
                  if (source_type == Typeob.ArrayObject || source_type == Typeob.Object){
                    if (target_type.IsArray)
                      il.Emit(OpCodes.Ldtoken, target_type.GetElementType());
                    else
                      il.Emit(OpCodes.Ldtoken, Typeob.Object);
                    il.Emit(OpCodes.Call, CompilerGlobals.toNativeArrayMethod);
                  }
                  il.Emit(OpCodes.Castclass, target_type);
                  return;
                }else if (target_type is TypeBuilder){
                  il.Emit(OpCodes.Castclass, target_type);
                  return;
                }else if (target_type == typeof(Enum) && source_type.BaseType == typeof(Enum)){
                  il.Emit(OpCodes.Box, source_type);
                  return;
                }else if (target_type == Typeob.Object || target_type.IsAssignableFrom(source_type)){
                  if (source_type.IsValueType)
                    il.Emit(OpCodes.Box, source_type);
                  return;
                }

                if (Typeob.JSObject.IsAssignableFrom(target_type)){
                  if (source_type.IsValueType)
                    il.Emit(OpCodes.Box, source_type);
                  ast.EmitILToLoadEngine(il);
                  il.Emit(OpCodes.Call, CompilerGlobals.toObject2Method); //Do this here so that we need not pass engine to Coerce
                  il.Emit(OpCodes.Castclass, target_type);
                  return;
                }

                if (Convert.EmittedCallToConversionMethod(ast, il, source_type, target_type))
                  return;

                //Either no conversion is possible, or not enough information is available at compile time.
                //PartialEvaluator is supposed to give errors when conversions are known to be impossible.
                //Defer to run-time type checking
                if (target_type.IsValueType || target_type.IsArray){
                  il.Emit(OpCodes.Ldtoken, target_type);
                  il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod);
                  ConstantWrapper.TranslateToILInt(il, truncationPermitted ? 1 : 0);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:convert.cs

示例2: Emit


//.........这里部分代码省略.........
                    {
                        il.Emit(OpCodes.Ldnull);
                        source_type = Typeob.Object;
                    }
                    switch (target)
                    {
                        case TypeCode.Object:
                            if (!target_type.IsArray && !(target_type == Typeob.Array))
                            {
                                if (target_type is TypeBuilder)
                                {
                                    il.Emit(OpCodes.Castclass, target_type);
                                    return;
                                }
                                if ((target_type == Typeob.Enum) && (source_type.BaseType == Typeob.Enum))
                                {
                                    il.Emit(OpCodes.Box, source_type);
                                    return;
                                }
                                if ((target_type == Typeob.Object) || target_type.IsAssignableFrom(source_type))
                                {
                                    if (source_type.IsValueType)
                                    {
                                        il.Emit(OpCodes.Box, source_type);
                                    }
                                    return;
                                }
                                if (Typeob.JSObject.IsAssignableFrom(target_type))
                                {
                                    if (source_type.IsValueType)
                                    {
                                        il.Emit(OpCodes.Box, source_type);
                                    }
                                    ast.EmitILToLoadEngine(il);
                                    il.Emit(OpCodes.Call, CompilerGlobals.toObject2Method);
                                    il.Emit(OpCodes.Castclass, target_type);
                                    return;
                                }
                                if (!EmittedCallToConversionMethod(ast, il, source_type, target_type))
                                {
                                    if (target_type.IsValueType || target_type.IsArray)
                                    {
                                        il.Emit(OpCodes.Ldtoken, target_type);
                                        il.Emit(OpCodes.Call, CompilerGlobals.getTypeFromHandleMethod);
                                        ConstantWrapper.TranslateToILInt(il, truncationPermitted ? 1 : 0);
                                        il.Emit(OpCodes.Call, CompilerGlobals.coerceTMethod);
                                    }
                                    if (target_type.IsValueType)
                                    {
                                        EmitUnbox(il, target_type, target);
                                        return;
                                    }
                                    il.Emit(OpCodes.Castclass, target_type);
                                }
                                return;
                            }
                            if (!(source_type == Typeob.ArrayObject) && !(source_type == Typeob.Object))
                            {
                                goto Label_02A9;
                            }
                            if (!target_type.IsArray)
                            {
                                il.Emit(OpCodes.Ldtoken, Typeob.Object);
                            }
                            else
                            {
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:67,代码来源:Convert.cs


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