本文整理汇总了C#中DynamicMetaObject.GetRuntimeType方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicMetaObject.GetRuntimeType方法的具体用法?C# DynamicMetaObject.GetRuntimeType怎么用?C# DynamicMetaObject.GetRuntimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicMetaObject
的用法示例。
在下文中一共展示了DynamicMetaObject.GetRuntimeType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeConvertRuleForCall
private DynamicMetaObject/*!*/ MakeConvertRuleForCall(DynamicMetaObjectBinder/*!*/ convertToAction, Type toType, DynamicMetaObject/*!*/ self, string name, string returner, Func<DynamicMetaObject> fallback, Func<Expression, Expression> resultConverter) {
PythonType pt = ((IPythonObject)self.Value).PythonType;
PythonTypeSlot pts;
CodeContext context = PythonContext.GetPythonContext(convertToAction).SharedContext;
ValidationInfo valInfo = BindingHelpers.GetValidationInfo(this, pt);
if (pt.TryResolveSlot(context, name, out pts) && !IsBuiltinConversion(context, pts, name, pt)) {
ParameterExpression tmp = Ast.Variable(typeof(object), "func");
Expression callExpr = resultConverter(
Ast.Call(
PythonOps.GetConversionHelper(returner, GetResultKind(convertToAction)),
Ast.Dynamic(
PythonContext.GetPythonContext(convertToAction).InvokeNone,
typeof(object),
PythonContext.GetCodeContext(convertToAction),
tmp
)
)
);
if (typeof(Extensible<>).MakeGenericType(toType).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, toType, self, callExpr), typeof(object));
}
return BindingHelpers.AddDynamicTestAndDefer(
convertToAction,
new DynamicMetaObject(
Ast.Condition(
MakeTryGetTypeMember(
PythonContext.GetPythonContext(convertToAction),
pts,
self.Expression,
tmp
),
callExpr,
AstUtils.Convert(
ConversionFallback(convertToAction),
typeof(object)
)
),
self.Restrict(self.GetRuntimeType()).Restrictions
),
new DynamicMetaObject[] { this },
valInfo,
tmp
);
}
return fallback();
}
示例2: 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);
}