예제 #1
0
 public static DuckValueBindingOption Get(Type fromType, Type toType)
 {
     return(IdentityValueBinding.TryBind(fromType, toType)
            ?? ImplicitNumericValueBinding.TryBind(fromType, toType)
            ?? ImplicitNullableValueBinding.TryBind(fromType, toType)
            ?? ImplicitReferenceValueBinding.TryBind(fromType, toType)
            ?? ImplicitUserConversionValueBinding.TryBind(fromType, toType)
            ?? DuckCastValueBinding.TryBind(fromType, toType)
            ?? NotBindable);
 }
        public static DuckValueBindingOption TryBind(Type fromType, Type toType)
        {
            if (!IsNullable(toType))
            {
                return(null);
            }
            bool fromTypeNullable  = IsNullable(fromType);
            Type coreFromType      = fromTypeNullable ? fromType.GetGenericArguments()[0] : fromType;
            Type coreToType        = toType.GetGenericArguments()[0];
            var  coreBindingOption = IdentityValueBinding.TryBind(coreFromType, coreToType) ??
                                     ImplicitNumericValueBinding.TryBind(coreFromType, coreToType);

            return(coreBindingOption != null
                ? new ImplicitNullableValueBinding(fromTypeNullable, fromType, toType, coreToType, coreBindingOption)
                : null);
        }