本文整理匯總了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());
}