Пример #1
0
        public static bool CanConvertValue(this ValueNode node, ILContext context, TypeReference targetTypeRef, IEnumerable <ICustomAttributeProvider> attributeProviders)
        {
            TypeReference typeConverter = null;

            foreach (var attributeProvider in attributeProviders)
            {
                CustomAttribute typeConverterAttribute;
                if (
                    (typeConverterAttribute =
                         attributeProvider.CustomAttributes.FirstOrDefault(
                             cad => TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName))) != null)
                {
                    typeConverter = typeConverterAttribute.ConstructorArguments[0].Value as TypeReference;
                    break;
                }
            }

            if (typeConverter == null)
            {
                foreach (var(t, tc) in TypeConverterAttribute.KnownConverters)
                {
                    if (TypeRefComparer.Default.Equals(context.Module.ImportReference(t), targetTypeRef))
                    {
                        typeConverter = context.Module.ImportReference(tc);
                        break;
                    }
                }
            }

            return(node.CanConvertValue(context, targetTypeRef, typeConverter));
        }
Пример #2
0
        public static bool CanConvertValue(this ValueNode node, ILContext context, FieldReference bpRef)
        {
            var module        = context.Body.Method.Module;
            var targetTypeRef = bpRef.GetBindablePropertyType(node, module);
            var typeConverter = bpRef.GetBindablePropertyTypeConverter(module);

            return(node.CanConvertValue(context, targetTypeRef, typeConverter));
        }
        public static bool CanConvertValue(this ValueNode node, ILContext context, TypeReference targetTypeRef, IEnumerable <ICustomAttributeProvider> attributeProviders)
        {
            TypeReference typeConverter = null;

            foreach (var attributeProvider in attributeProviders)
            {
                CustomAttribute typeConverterAttribute;
                if (
                    (typeConverterAttribute =
                         attributeProvider.CustomAttributes.FirstOrDefault(
                             cad => TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName))) != null)
                {
                    typeConverter = typeConverterAttribute.ConstructorArguments[0].Value as TypeReference;
                    break;
                }
            }

            return(node.CanConvertValue(context, targetTypeRef, typeConverter));
        }