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


C# DynamicMetaObject.CastOrConvert方法代码示例

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


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

示例1: BinaryMultiply

 private DynamicMetaObject BinaryMultiply(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
 {
     Expression expression;
     Expression expression1;
     if (target.Value != null)
     {
         if (target.LimitType.IsNumeric())
         {
             DynamicMetaObject argAsNumericOrPrimitive = PSBinaryOperationBinder.GetArgAsNumericOrPrimitive(arg, target.LimitType);
             if (argAsNumericOrPrimitive == null)
             {
                 if (arg.LimitType.Equals(typeof(string)))
                 {
                     return this.BinaryNumericStringOp(target, arg);
                 }
             }
             else
             {
                 return this.BinaryNumericOp("Multiply", target, argAsNumericOrPrimitive);
             }
         }
         if (!target.LimitType.Equals(typeof(string)))
         {
             DynamicMetaObject dynamicMetaObject = PSEnumerableBinder.IsEnumerable(target);
             if (dynamicMetaObject == null)
             {
                 return PSBinaryOperationBinder.CallImplicitOp("op_Multiply", target, arg, "*", errorSuggestion);
             }
             else
             {
                 if (arg.LimitType.Equals(typeof(string)))
                 {
                     expression = PSBinaryOperationBinder.ConvertStringToNumber(arg.Expression, typeof(int)).Convert(typeof(int));
                 }
                 else
                 {
                     expression = arg.CastOrConvert(typeof(int));
                 }
                 Expression expression2 = expression;
                 if (!target.LimitType.IsArray)
                 {
                     DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
                     dynamicMetaObjectArray[0] = arg;
                     return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_Multiply, dynamicMetaObject.Expression, expression2), target.CombineRestrictions(dynamicMetaObjectArray));
                 }
                 else
                 {
                     Type elementType = target.LimitType.GetElementType();
                     Type[] typeArray = new Type[1];
                     typeArray[0] = elementType;
                     DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1];
                     dynamicMetaObjectArray1[0] = arg;
                     return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_Multiply.MakeGenericMethod(typeArray), target.Expression.Cast(elementType.MakeArrayType()), expression2), target.CombineRestrictions(dynamicMetaObjectArray1));
                 }
             }
         }
         else
         {
             if (arg.LimitType.Equals(typeof(string)))
             {
                 expression1 = PSBinaryOperationBinder.ConvertStringToNumber(arg.Expression, typeof(int)).Convert(typeof(int));
             }
             else
             {
                 expression1 = arg.CastOrConvert(typeof(int));
             }
             Expression expression3 = expression1;
             DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1];
             dynamicMetaObjectArray2[0] = arg;
             return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.StringOps_Multiply, target.Expression.Cast(typeof(string)), expression3), target.CombineRestrictions(dynamicMetaObjectArray2));
         }
     }
     else
     {
         return new DynamicMetaObject(ExpressionCache.NullConstant, target.PSGetTypeRestriction());
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:77,代码来源:PSBinaryOperationBinder.cs

示例2: Not

 internal DynamicMetaObject Not(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
 {
     if (!target.HasValue)
     {
         return base.Defer(target, new DynamicMetaObject[0]);
     }
     return new DynamicMetaObject(Expression.Not(target.CastOrConvert(typeof(bool))).Cast(typeof(object)), target.PSGetTypeRestriction());
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:PSUnaryOperationBinder.cs


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