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


C# TypeNode.GetRuntimeType方法代码示例

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


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

示例1: AddPlugin

 public void AddPlugin(TypeNode pluginType, TypeSystem typeSystem, Node offendingNode){
   if (pluginType == null || typeSystem == null || typeSystem.ErrorHandler == null || offendingNode == null){Debug.Assert(false); return;}
   Type pType = pluginType.GetRuntimeType();
   if (pType == null){
     ((ErrorHandler)typeSystem.ErrorHandler).HandleError(offendingNode, Error.CouldNotLoadPluginType, typeSystem.ErrorHandler.GetTypeName(pluginType));
     return;
   }
   this.AddPlugin(pType, typeSystem, offendingNode);
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:9,代码来源:Compiler.cs

示例2: GetConvertFromString

    Expression GetConvertFromString(TypeNode targetType, Expression src, bool always) {
      if (targetType == SystemTypes.String) 
        return src;// nothing to do!

      if (targetType is EnumNode) {
        // e.g. return (DayOfWeek)Enum.Parse(typeof(DayOfWeek),"Sunday");
        Method method = SystemTypes.Enum.GetMethod(Identifier.For("Parse"), new TypeNode[2]{ SystemTypes.Type, SystemTypes.String});
        UnaryExpression typeOfEnum = new UnaryExpression(new MemberBinding(null, targetType), NodeType.Typeof);
        MethodCall call = new MethodCall(new MemberBinding(new MemberBinding(null, targetType), method), 
          new ExpressionList(new Expression[2]{typeOfEnum, src }), NodeType.Call, SystemTypes.Object);
        return CastTo(call, targetType);
      }
      // See if it has a type converter.
      Class converterClass = Checker.GetTypeConverter(targetType);
      if (converterClass != null) {
        TypeConverter converter = TypeDescriptor.GetConverter(targetType.GetRuntimeType());
        if (converter != null) {
          Type converterType = converter.GetType();
          AssemblyNode converterAssembly = AssemblyNode.GetAssembly(converterType.Assembly, cache, false, true);
          converterClass = converterAssembly.GetType(Identifier.For(converterType.Namespace), Identifier.For(converterType.Name)) as Class;          
          Expression e = tempChecker.GetConverterFromString(converter, converterClass, SystemTypes.String, src, SystemTypes.Object);
          if (e != null) {
            //Do I need to add namespace and assembly reference for type converter?
            return CastTo(e, targetType);
          }
        }   
      }
      if (always) {
        // e.g. return PointArray.Parse("10,20 30,40 50,60");
        Method method = targetType.GetImplicitCoercionFromMethod(SystemTypes.String);
        if (method == null) {
          method = targetType.GetMethod(Identifier.For("Parse"), new TypeNode[1]{ SystemTypes.String});
        }
        if (method != null) {
          MemberBinding typeBinding  = new MemberBinding(null, targetType);
          MethodCall call = new MethodCall(new MemberBinding(typeBinding, method), 
            new ExpressionList(new Expression[1]{ src }), NodeType.Call, targetType );
          return call;
        }
      }
      return null;
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:42,代码来源:Serializer.cs

示例3: GetCoercedLiteralValue

 /// <summary>
 /// Gets the value of the literal coercing literals of TypeNode, EnumNode, TypeNode[], and EnumNode[] as needed.
 /// </summary>
 /// <param name="type">A TypeNode representing the type of the literal</param>
 /// <param name="value">The value of the literal</param>
 /// <returns>An object that has been coerced to the appropriate runtime type</returns>
 protected object GetCoercedLiteralValue(TypeNode type, object value)
 {
     if(type == null || value == null)
         return null;
     switch(type.typeCode)
     {
         case ElementType.Class:
             return ((TypeNode)value).GetRuntimeType();
         case ElementType.ValueType:
             return System.Enum.ToObject(type.GetRuntimeType(), value);
         case ElementType.SzArray:
             return this.GetCoercedArrayLiteral((ArrayType)type, (Array)value);
         default:
             Literal lit = value as Literal;
             if(lit != null && type == CoreSystemTypes.Object && lit.Type is EnumNode)
                 return this.GetCoercedLiteralValue(lit.Type, lit.Value);
             break;
     }
     return value;
 }
开发者ID:modulexcite,项目名称:SHFB-1,代码行数:26,代码来源:Nodes.cs


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