本文整理汇总了C#中DynamicMetaObject.GetLimitType方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicMetaObject.GetLimitType方法的具体用法?C# DynamicMetaObject.GetLimitType怎么用?C# DynamicMetaObject.GetLimitType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicMetaObject
的用法示例。
在下文中一共展示了DynamicMetaObject.GetLimitType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeHashOperation
private static DynamicMetaObject/*!*/ MakeHashOperation(PythonOperationBinder/*!*/ operation, DynamicMetaObject/*!*/ self) {
self = self.Restrict(self.GetLimitType());
PythonContext state = PythonContext.GetPythonContext(operation);
SlotOrFunction func = SlotOrFunction.GetSlotOrFunction(state, "__hash__", self);
DynamicMetaObject res = func.Target;
if (func.IsNull) {
// Python 2.6 setting __hash__ = None makes the type unhashable
res = new DynamicMetaObject(
operation.Throw(
Expression.Call(
typeof(PythonOps).GetMethod("TypeErrorForUnhashableObject"),
self.Expression
),
typeof(int)
),
res.Restrictions
);
} else if (func.ReturnType != typeof(int)) {
if (func.ReturnType == typeof(BigInteger)) {
// Python 2.5 defines the result of returning a long as hashing the long
res = new DynamicMetaObject(
HashBigInt(operation, res.Expression),
res.Restrictions
);
} else if (func.ReturnType == typeof(object)) {
// need to get the integer value here...
ParameterExpression tempVar = Ast.Parameter(typeof(object), "hashTemp");
res = new DynamicMetaObject(
Expression.Block(
new[] { tempVar },
Expression.Assign(tempVar, res.Expression),
Expression.Condition(
Expression.TypeIs(tempVar, typeof(int)),
Expression.Convert(tempVar, typeof(int)),
Expression.Condition(
Expression.TypeIs(tempVar, typeof(BigInteger)),
HashBigInt(operation, tempVar),
HashConvertToInt(state, tempVar)
)
)
),
res.Restrictions
);
} else {
// need to convert unknown value to object
res = new DynamicMetaObject(
HashConvertToInt(state, res.Expression),
res.Restrictions
);
}
}
return res;
}
示例2: MakeDictionaryCopy
/// <summary>
/// Called when the user is expanding a dictionary - we copy the user
/// dictionary and verify that it contains only valid string names.
/// </summary>
private DynamicMetaObject/*!*/ MakeDictionaryCopy(DynamicMetaObject/*!*/ userDict) {
Debug.Assert(_dict == null);
userDict = userDict.Restrict(userDict.GetLimitType());
_temps.Add(_dict = Ast.Variable(typeof(PythonDictionary), "$dict"));
EnsureInit();
string methodName;
if (typeof(PythonDictionary).IsAssignableFrom(userDict.GetLimitType())) {
methodName = "CopyAndVerifyPythonDictionary";
} else if (typeof(IDictionary).IsAssignableFrom(userDict.GetLimitType())) {
methodName = "CopyAndVerifyDictionary";
} else {
methodName = "CopyAndVerifyUserMapping";
}
_init.Add(
Ast.Assign(
_dict,
Ast.Call(
typeof(PythonOps).GetMethod(methodName),
GetFunctionParam(),
AstUtils.Convert(userDict.Expression, userDict.GetLimitType())
)
)
);
return userDict;
}
示例3: IsIndexType
private static bool IsIndexType(PythonContext/*!*/ state, DynamicMetaObject/*!*/ obj) {
bool numeric = true;
if (obj.GetLimitType() != typeof(MissingParameter) &&
!PythonOps.IsNumericType(obj.GetLimitType())) {
PythonType curType = MetaPythonObject.GetPythonType(obj);
PythonTypeSlot dummy;
if (!curType.TryResolveSlot(state.SharedContext, "__index__", out dummy)) {
numeric = false;
}
}
return numeric;
}
示例4: AddExtensibleSelfCheck
private static Expression/*!*/ AddExtensibleSelfCheck(DynamicMetaObjectBinder/*!*/ convertToAction, Type toType, DynamicMetaObject/*!*/ self, Expression/*!*/ callExpr) {
ParameterExpression tmp = Ast.Variable(callExpr.Type, "tmp");
ConversionResultKind resKind = GetResultKind(convertToAction);
Type retType = (resKind == ConversionResultKind.ExplicitTry || resKind == ConversionResultKind.ImplicitTry) ? typeof(object) : toType;
callExpr = Ast.Block(
new ParameterExpression[] { tmp },
Ast.Block(
Ast.Assign(tmp, callExpr),
Ast.Condition(
Ast.Equal(tmp, self.Expression),
AstUtils.Convert(
Ast.Property(
AstUtils.Convert(self.Expression, self.GetLimitType()),
self.GetLimitType().GetProperty("Value")
),
retType
),
Ast.Dynamic(
new PythonConversionBinder(
PythonContext.GetPythonContext(convertToAction),
toType,
GetResultKind(convertToAction)
),
retType,
tmp
)
)
)
);
return callExpr;
}
示例5: MakeUnaryOperation
private static DynamicMetaObject MakeUnaryOperation(DynamicMetaObjectBinder binder, DynamicMetaObject self, TotemOperationKind symbol, DynamicMetaObject errorSuggestion, Type retType)
{
self = self.Restrict(self.GetLimitType());
throw new NotImplementedException();
}
示例6: MakeUnaryNotOperation
private static DynamicMetaObject/*!*/ MakeUnaryNotOperation(DynamicMetaObjectBinder/*!*/ operation, DynamicMetaObject/*!*/ self, Type retType, DynamicMetaObject errorSuggestion) {
self = self.Restrict(self.GetLimitType());
SlotOrFunction nonzero = SlotOrFunction.GetSlotOrFunction(PythonContext.GetPythonContext(operation), "__nonzero__", self);
SlotOrFunction length = SlotOrFunction.GetSlotOrFunction(PythonContext.GetPythonContext(operation), "__len__", self);
Expression notExpr;
if (!nonzero.Success && !length.Success) {
// no __len__ or __nonzero__, for None this is always false, everything else is True. If we have
// an error suggestion though we'll go with that.
if (errorSuggestion == null) {
notExpr = (self.GetLimitType() == typeof(DynamicNull)) ? AstUtils.Constant(true) : AstUtils.Constant(false);
} else {
notExpr = errorSuggestion.Expression;
}
} else {
SlotOrFunction target = nonzero.Success ? nonzero : length;
notExpr = target.Target.Expression;
if (nonzero.Success) {
// call non-zero and negate it
if (notExpr.Type == typeof(bool)) {
notExpr = Ast.Equal(notExpr, AstUtils.Constant(false));
} else {
notExpr = Ast.Call(
typeof(PythonOps).GetMethod("Not"),
AstUtils.Convert(notExpr, typeof(object))
);
}
} else {
// call len, compare w/ zero
if (notExpr.Type == typeof(int)) {
notExpr = Ast.Equal(notExpr, AstUtils.Constant(0));
} else {
notExpr =
Ast.Equal(
DynamicExpression.Dynamic(
PythonContext.GetPythonContext(operation).Operation(
PythonOperationKind.Compare
),
typeof(int),
notExpr,
AstUtils.Constant(0)
),
AstUtils.Constant(0)
);
}
}
}
if (retType == typeof(object) && notExpr.Type == typeof(bool)) {
notExpr = BindingHelpers.AddPythonBoxing(notExpr);
}
return new DynamicMetaObject(
notExpr,
self.Restrictions.Merge(nonzero.Target.Restrictions.Merge(length.Target.Restrictions))
);
}
示例7: InvokeForeignObject
/// <summary>
/// Creates a nested dynamic site which uses the unpacked arguments.
/// </summary>
protected DynamicMetaObject InvokeForeignObject(DynamicMetaObject target, DynamicMetaObject[] args) {
// need to unpack any dict / list arguments...
List<ArgumentInfo> newArgs;
List<Expression> metaArgs;
Expression test;
BindingRestrictions restrictions;
TranslateArguments(target, args, out newArgs, out metaArgs, out test, out restrictions);
Debug.Assert(metaArgs.Count > 0);
return BindingHelpers.AddDynamicTestAndDefer(
this,
new DynamicMetaObject(
Expression.Dynamic(
new CompatibilityInvokeBinder(_state, newArgs.ToArray()),
typeof(object),
metaArgs.ToArray()
),
restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(target.Expression, target.GetLimitType()))
),
args,
new ValidationInfo(test, null)
);
}
示例8: MakeEnumeratorOperation
private static DynamicMetaObject MakeEnumeratorOperation(PythonOperationBinder operation, DynamicMetaObject self) {
if (self.GetLimitType() == typeof(string)) {
self = self.Restrict(self.GetLimitType());
return new DynamicMetaObject(
Expression.Call(
typeof(PythonOps).GetMethod("StringEnumerator"),
self.Expression
),
self.Restrictions
);
} else if (self.GetLimitType() == typeof(PythonDictionary)) {
self = self.Restrict(self.GetLimitType());
return new DynamicMetaObject(
Expression.Call(
typeof(PythonOps).GetMethod("MakeDictionaryKeyEnumerator"),
self.Expression
),
self.Restrictions
);
} else if (self.Value is IEnumerable ||
typeof(IEnumerable).IsAssignableFrom(self.GetLimitType())) {
self = self.Restrict(self.GetLimitType());
return new DynamicMetaObject(
Expression.Call(
Expression.Convert(
self.Expression,
typeof(IEnumerable)
),
typeof(IEnumerable).GetMethod("GetEnumerator")
),
self.Restrictions
);
} else if (self.Value is IEnumerator || // check for COM object (and fast check when we have values)
typeof(IEnumerator).IsAssignableFrom(self.GetLimitType())) { // check if we don't have a value
DynamicMetaObject ieres = self.Restrict(self.GetLimitType());
#if !SILVERLIGHT
if (ComOps.IsComObject(self.Value)) {
ieres = new DynamicMetaObject(
self.Expression,
ieres.Restrictions.Merge(
BindingRestrictions.GetExpressionRestriction(
Ast.TypeIs(self.Expression, typeof(IEnumerator))
)
)
);
}
#endif
return ieres;
}
ParameterExpression tmp = Ast.Parameter(typeof(IEnumerator), "enum");
DynamicMetaObject res = self.BindConvert(new ConversionBinder(BinderState.GetBinderState(operation), typeof(IEnumerator), ConversionResultKind.ExplicitTry));
return new DynamicMetaObject(
Expression.Block(
new[] { tmp },
Ast.Condition(
Ast.NotEqual(
Ast.Assign(tmp, res.Expression),
AstUtils.Constant(null)
),
tmp,
Ast.Call(
typeof(PythonOps).GetMethod("ThrowTypeErrorForBadIteration"),
BinderState.GetCodeContext(operation),
self.Expression
)
)
),
res.Restrictions
);
}
示例9: MakeUnaryNotOperation
private static DynamicMetaObject/*!*/ MakeUnaryNotOperation(DynamicMetaObjectBinder/*!*/ operation, DynamicMetaObject/*!*/ self, Type/*!*/ retType) {
self = self.Restrict(self.GetLimitType());
SlotOrFunction nonzero = SlotOrFunction.GetSlotOrFunction(PythonContext.GetPythonContext(operation), Symbols.NonZero, self);
SlotOrFunction length = SlotOrFunction.GetSlotOrFunction(PythonContext.GetPythonContext(operation), Symbols.Length, self);
Expression notExpr;
if (!nonzero.Success && !length.Success) {
// always False or True for None
notExpr = (self.GetLimitType() == typeof(DynamicNull)) ? AstUtils.Constant(true) : AstUtils.Constant(false);
} else {
SlotOrFunction target = nonzero.Success ? nonzero : length;
notExpr = target.Target.Expression;
if (nonzero.Success) {
// call non-zero and negate it
if (notExpr.Type == typeof(bool)) {
notExpr = Ast.Equal(notExpr, AstUtils.Constant(false));
} else {
notExpr = Ast.Call(
typeof(PythonOps).GetMethod("Not"),
AstUtils.Convert(notExpr, typeof(object))
);
}
} else {
// call len, compare w/ zero
if (notExpr.Type == typeof(int)) {
notExpr = Ast.Equal(notExpr, AstUtils.Constant(0));
} else {
notExpr =
Ast.Equal(
Ast.Dynamic(
PythonContext.GetPythonContext(operation).Operation(
PythonOperationKind.Compare
),
typeof(int),
notExpr,
AstUtils.Constant(0)
),
AstUtils.Constant(0)
);
}
}
}
Debug.Assert(notExpr.Type == typeof(bool));
if (retType == typeof(object)) {
notExpr = BindingHelpers.AddPythonBoxing(notExpr);
}
return new DynamicMetaObject(
notExpr,
self.Restrictions.Merge(nonzero.Target.Restrictions.Merge(length.Target.Restrictions))
);
}
示例10: MakeDictionaryCopy
///-------------------------------------------------------------------------------------------------
/// <summary>
/// Called when the user is expanding a dictionary - we copy the user
/// dictionary and verify that it contains only valid string names.
/// </summary>
///
/// <remarks> Aleksander, 19.05.2013. </remarks>
///
/// <param name="userDict"> Dictionary of users. </param>
///
/// <returns> . </returns>
///-------------------------------------------------------------------------------------------------
private DynamicMetaObject MakeDictionaryCopy(DynamicMetaObject userDict)
{
Debug.Assert(_dict == null);
userDict = userDict.Restrict(userDict.GetLimitType());
_temps.Add(_dict = Expression.Variable(typeof(TotemDictionary), "$dict"));
EnsureInit();
MethodInfo method;
if (typeof(TotemDictionary).IsAssignableFrom(userDict.GetLimitType()))
method = AstMethods.CopyAndVerifyTotemDictionary;
else if (typeof(IDictionary).IsAssignableFrom(userDict.GetLimitType()))
method = AstMethods.CopyAndVerifyDictionary;
else
method = AstMethods.CopyAndVerifyUserMapping;
_init.Add(
Expression.Assign(
_dict,
Expression.Call(
method,
GetFunctionParam(),
Utils.Convert(userDict.Expression, userDict.GetLimitType())
)
)
);
return userDict;
}
示例11: MakeHashOperation
private static DynamicMetaObject/*!*/ MakeHashOperation(PythonOperationBinder/*!*/ operation, DynamicMetaObject/*!*/ self) {
self = self.Restrict(self.GetLimitType());
BinderState state = BinderState.GetBinderState(operation);
SlotOrFunction func = SlotOrFunction.GetSlotOrFunction(state, Symbols.Hash, self);
DynamicMetaObject res = func.Target;
if (func.ReturnType != typeof(int)) {
if (func.ReturnType == typeof(BigInteger)) {
// Python 2.5 defines the result of returning a long as hashing the long
res = new DynamicMetaObject(
HashBigInt(operation, res.Expression),
res.Restrictions
);
} else if (func.ReturnType == typeof(object)) {
// need to get the integer value here...
ParameterExpression tempVar = Ast.Parameter(typeof(object), "hashTemp");
res = new DynamicMetaObject(
Expression.Block(
new [] { tempVar },
Expression.Assign(tempVar, res.Expression),
Expression.Condition(
Expression.TypeIs(tempVar, typeof(int)),
Expression.Convert(tempVar, typeof(int)),
Expression.Condition(
Expression.TypeIs(tempVar, typeof(BigInteger)),
HashBigInt(operation, tempVar),
HashConvertToInt(state, tempVar)
)
)
),
res.Restrictions
);
} else {
// need to convert unknown value to object
res = new DynamicMetaObject(
HashConvertToInt(state, res.Expression),
res.Restrictions
);
}
}
return res;
}
示例12: MakeUnaryOperation
private static DynamicMetaObject/*!*/ MakeUnaryOperation(OperationBinder/*!*/ operation, DynamicMetaObject/*!*/ self) {
self = self.Restrict(self.GetLimitType());
SlotOrFunction func = SlotOrFunction.GetSlotOrFunction(BinderState.GetBinderState(operation), Symbols.OperatorToSymbol(operation.Operation), self);
if (!func.Success) {
// we get the error message w/ {0} so that PythonBinderHelper.TypeError formats it correctly
return TypeError(operation, MakeUnaryOpErrorMessage(operation.Operation.ToString(), "{0}"), self);
}
return func.Target;
}
示例13: AddExtensibleSelfCheck
private static Expression/*!*/ AddExtensibleSelfCheck(ConvertBinder/*!*/ convertToAction, DynamicMetaObject/*!*/ self, Expression/*!*/ callExpr) {
ParameterExpression tmp = Ast.Variable(callExpr.Type, "tmp");
callExpr = Ast.Block(
new ParameterExpression[] { tmp },
Ast.Block(
Ast.Assign(tmp, callExpr),
Ast.Condition(
Ast.Equal(tmp, self.Expression),
Ast.Property(
AstUtils.Convert(self.Expression, self.GetLimitType()),
self.GetLimitType().GetProperty("Value")
),
Binders.Convert(
BinderState.GetBinderState(convertToAction),
convertToAction.Type,
ConversionResultKind.ExplicitCast,
tmp
)
)
)
);
return callExpr;
}
示例14: MakeConvertRuleForCall
private DynamicMetaObject/*!*/ MakeConvertRuleForCall(ConvertBinder/*!*/ convertToAction, DynamicMetaObject/*!*/ self, SymbolId symbolId, string returner) {
PythonType pt = ((IPythonObject)self.Value).PythonType;
PythonTypeSlot pts;
CodeContext context = BinderState.GetBinderState(convertToAction).Context;
if (pt.TryResolveSlot(context, symbolId, out pts) && !IsBuiltinConversion(context, pts, symbolId, pt)) {
ParameterExpression tmp = Ast.Variable(typeof(object), "func");
Expression callExpr = Ast.Call(
PythonOps.GetConversionHelper(returner, GetResultKind(convertToAction)),
Ast.Dynamic(
new PythonInvokeBinder(
BinderState.GetBinderState(convertToAction),
new CallSignature(0)
),
typeof(object),
BinderState.GetCodeContext(convertToAction),
tmp
)
);
if (typeof(Extensible<>).MakeGenericType(convertToAction.Type).IsAssignableFrom(self.GetLimitType())) {
// if we're doing a conversion to the underlying type and we're an
// Extensible<T> of that type:
// if an extensible type returns it's self in a conversion, then we need
// to actually return the underlying value. If an extensible just keeps
// returning more instances of it's self a stack overflow occurs - both
// behaviors match CPython.
callExpr = AstUtils.Convert(AddExtensibleSelfCheck(convertToAction, self, callExpr), typeof(object));
}
return new DynamicMetaObject(
Ast.Block(
new ParameterExpression[] { tmp },
Ast.Condition(
BindingHelpers.CheckTypeVersion(
self.Expression,
pt.Version
),
Ast.Condition(
MakeTryGetTypeMember(
BinderState.GetBinderState(convertToAction),
pts,
self.Expression,
tmp
),
callExpr,
AstUtils.Convert(
ConversionFallback(convertToAction),
typeof(object)
)
),
convertToAction.Defer(this).Expression
)
),
self.Restrict(self.GetRuntimeType()).Restrictions
);
}
return convertToAction.FallbackConvert(this);
}
示例15: MakeUnaryOperation
private static DynamicMetaObject MakeUnaryOperation(DynamicMetaObjectBinder binder, DynamicMetaObject self, string symbol, DynamicMetaObject errorSuggestion) {
self = self.Restrict(self.GetLimitType());
SlotOrFunction func = SlotOrFunction.GetSlotOrFunction(PythonContext.GetPythonContext(binder), symbol, self);
if (!func.Success) {
// we get the error message w/ {0} so that PythonBinderHelper.TypeError formats it correctly
return errorSuggestion ?? TypeError(binder, MakeUnaryOpErrorMessage(symbol, "{0}"), self);
}
return func.Target;
}