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