本文整理汇总了C#中ConversionResultKind类的典型用法代码示例。如果您正苦于以下问题:C# ConversionResultKind类的具体用法?C# ConversionResultKind怎么用?C# ConversionResultKind使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConversionResultKind类属于命名空间,在下文中一共展示了ConversionResultKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// Backwards compatible Convert for the old sites that need to flow CodeContext
/// </summary>
public static Expression/*!*/ Convert(Expression/*!*/ codeContext, PythonContext/*!*/ binder, Type/*!*/ type, ConversionResultKind resultKind, Expression/*!*/ target) {
return Ast.Dynamic(
binder.Convert(type, resultKind),
type,
target
);
}
示例2: ConvertExpression
public override Ast ConvertExpression(Ast expr, Type toType, ConversionResultKind kind, OverloadResolverFactory resolverFactory)
{
Type exprType = expr.Type;
Type visType = CompilerHelpers.GetVisibleType(toType);
if (typeof(IFn).IsAssignableFrom(exprType) && typeof(Delegate).IsAssignableFrom(visType))
return Ast.Call(typeof(Converter).GetMethod("ConvertToDelegate"), Ast.Convert(expr, typeof(IFn)), Expression.Constant(visType));
// Follow through on our promise to convert IEnumerable<Object> or IEnumerable to IEnumerable<T> for any T
if (toType.IsGenericType && ! toType.IsAssignableFrom(expr.Type))
{
// The following is inspired by IronPython.Runtime.Binding.Python.ConversionBinder.FallbackConvert
Type genTo = toType.GetGenericTypeDefinition();
if ( genTo == typeof(IList<>))
{
return MakeToGenericConversion(expr,toType,typeof(IList<object>),typeof(ListGenericWrapper<>));
}
else if (genTo == typeof(IDictionary<,>))
{
return MakeToGenericConversion(expr,toType,typeof(IDictionary<object,object>),typeof(DictionaryGenericWrapper<,>));
}
else if (genTo == typeof(IEnumerable<>))
{
return MakeToGenericConversion(expr, toType, typeof(IEnumerable),typeof(IEnumerableOfTWrapper<>));
}
}
return base.ConvertExpression(expr, toType, kind, resolverFactory);
}
示例3: ConversionBinder
public ConversionBinder(BinderState/*!*/ state, Type/*!*/ type, ConversionResultKind resultKind)
: base(type, resultKind == ConversionResultKind.ExplicitCast || resultKind == ConversionResultKind.ExplicitTry) {
Assert.NotNull(state, type);
_state = state;
_kind = resultKind;
}
示例4: ConvertExpression
public override Expression ConvertExpression(Expression expr, Type toType, ConversionResultKind kind, OverloadResolverFactory resolverFactory)
{
ContractUtils.RequiresNotNull(expr, "expr");
ContractUtils.RequiresNotNull(toType, "toType");
Type exprType = expr.Type;
if (toType == typeof(object))
{
if (exprType.IsValueType())
return Utils.Convert(expr, toType);
else
return expr;
}
if (toType.IsAssignableFrom(exprType))
return expr;
Type visType = Context.Binder.PrivateBinding ? toType : CompilerHelpers.GetVisibleType(toType);
return Binders.Convert(
_context,
visType,
kind,
expr
);
}
示例5: ConvertTo
public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, DynamicMetaObject arg, OverloadResolverFactory resolverFactory, DynamicMetaObject errorSuggestion) {
ContractUtils.RequiresNotNull(toType, "toType");
ContractUtils.RequiresNotNull(arg, "arg");
Type knownType = arg.GetLimitType();
// try all the conversions - first look for conversions against the expression type,
// these can be done w/o any additional tests. Then look for conversions against the
// restricted type.
BindingRestrictions typeRestrictions = arg.Restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(arg.Expression, arg.GetLimitType()));
DynamicMetaObject res =
TryConvertToObject(toType, arg.Expression.Type, arg, typeRestrictions) ??
TryAllConversions(resolverFactory, toType, kind, arg.Expression.Type, typeRestrictions, arg) ??
TryAllConversions(resolverFactory, toType, kind, arg.GetLimitType(), typeRestrictions, arg) ??
errorSuggestion ??
MakeErrorTarget(toType, kind, typeRestrictions, arg);
if ((kind == ConversionResultKind.ExplicitTry || kind == ConversionResultKind.ImplicitTry) && toType.IsValueType) {
res = new DynamicMetaObject(
AstUtils.Convert(
res.Expression,
typeof(object)
),
res.Restrictions
);
}
return res;
}
示例6: ConvertWorker
public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type toType, ConversionResultKind kind) {
if (toType.IsSubclassOf(typeof(Delegate))) {
return MakeDelegateTarget(binder, toType, Restrict(typeof(Method)));
}
return FallbackConvert(binder);
}
示例7: ConvertExpression
public override Expression/*!*/ ConvertExpression(Expression/*!*/ expr, Type/*!*/ toType, ConversionResultKind kind, Expression context) {
ContractUtils.RequiresNotNull(expr, "expr");
ContractUtils.RequiresNotNull(toType, "toType");
Type exprType = expr.Type;
if (toType == typeof(object)) {
if (exprType.IsValueType) {
return AstUtils.Convert(expr, toType);
} else {
return expr;
}
}
if (toType.IsAssignableFrom(exprType)) {
return expr;
}
Type visType = CompilerHelpers.GetVisibleType(toType);
if (exprType == typeof(PythonType) && visType == typeof(Type)) {
return AstUtils.Convert(expr, visType); // use the implicit conversion
}
return Binders.Convert(
context,
_context.DefaultBinderState,
visType,
visType == typeof(char) ? ConversionResultKind.ImplicitCast : kind,
expr
);
}
示例8: Convert
public static Expression Convert(TotemContext state, Type type, ConversionResultKind kind, Expression target)
{
return DynamicExpression.Dynamic(
state.Convert(type, kind),
type,
target
);
}
示例9: TryAllConversions
/// <summary>
/// Checks if any conversions are available and if so builds the target for that conversion.
/// </summary>
private DynamicMetaObject TryAllConversions(Type toType, ConversionResultKind kind, Type knownType, BindingRestrictions restrictions, DynamicMetaObject arg) {
return
TryAssignableConversion(toType, knownType, restrictions, arg) ?? // known type -> known type
TryExtensibleConversion(toType, knownType, restrictions, arg) ?? // Extensible<T> -> Extensible<T>.Value
TryUserDefinedConversion(kind, toType, knownType, restrictions, arg) ?? // op_Implicit
TryImplicitNumericConversion(toType, knownType, restrictions, arg) ?? // op_Implicit
TryNullableConversion(toType, kind, knownType, restrictions, arg) ?? // null -> Nullable<T> or T -> Nullable<T>
TryNullConversion(toType, knownType, restrictions); // null -> reference type
}
示例10: TotemConversionBinder
public TotemConversionBinder(TotemContext/*!*/ context, Type/*!*/ type, ConversionResultKind resultKind, bool retObj)
: base(retObj ? typeof(object) : type, resultKind == ConversionResultKind.ExplicitCast || resultKind == ConversionResultKind.ExplicitTry)
{
Assert.NotNull(context);
_context = context;
_kind = resultKind;
_retObject = retObj;
_type = type;
}
示例11: ConvertExpression
public override Ast ConvertExpression(Ast expr, Type toType, ConversionResultKind kind, OverloadResolverFactory resolverFactory)
{
Type exprType = expr.Type;
Type visType = CompilerHelpers.GetVisibleType(toType);
if (typeof(IFn).IsAssignableFrom(exprType) && typeof(Delegate).IsAssignableFrom(visType))
return Ast.Call(typeof(Converter).GetMethod("ConvertToDelegate"), Ast.Convert(expr, typeof(IFn)), Expression.Constant(visType));
return base.ConvertExpression(expr, toType, kind, resolverFactory);
}
示例12: ConvertWorker
public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type toType, ConversionResultKind kind) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "BuiltinFunc Convert " + toType);
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "BuiltinFunc Convert");
if (toType.IsSubclassOf(typeof(Delegate))) {
return MakeDelegateTarget(binder, toType, Restrict(LimitType));
}
return FallbackConvert(binder);
}
示例13: Convert
/// <summary>
/// Backwards compatible Convert for the old sites that need to flow CodeContext
/// </summary>
public static Expression/*!*/ Convert(Expression/*!*/ codeContext, BinderState/*!*/ binder, Type/*!*/ type, ConversionResultKind resultKind, Expression/*!*/ target) {
return Ast.Dynamic(
new ConversionBinder(
binder,
type,
resultKind
),
type,
target
);
}
示例14: ConvertWorker
public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type, Type retType, ConversionResultKind kind) {
PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Conversion " + type.FullName);
PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "Conversion");
ValidationInfo typeTest = BindingHelpers.GetValidationInfo(this, Value.PythonType);
return BindingHelpers.AddDynamicTestAndDefer(
binder,
TryPythonConversion(binder, type) ?? FallbackConvert(binder),
new DynamicMetaObject[] { this },
typeTest,
retType
);
}
示例15: ConvertTo
public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, DynamicMetaObject arg) {
ContractUtils.RequiresNotNull(toType, "toType");
ContractUtils.RequiresNotNull(arg, "arg");
Type knownType = arg.GetLimitType();
// try all the conversions - first look for conversions against the expression type,
// these can be done w/o any additional tests. Then look for conversions against the
// restricted type.
BindingRestrictions typeRestrictions = arg.Restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(arg.Expression, arg.GetLimitType()));
return
TryConvertToObject(toType, arg.Expression.Type, arg) ??
TryAllConversions(toType, kind, arg.Expression.Type, arg.Restrictions, arg) ??
TryAllConversions(toType, kind, arg.GetLimitType(), typeRestrictions, arg) ??
MakeErrorTarget(toType, kind, typeRestrictions, arg);
}