private static BindingPropertyMatchInfo GetBetterProperty(BindingPropertyMatchInfo bestProperty, BindingPropertyMatchInfo newProperty)
 {
     if (newProperty.Compatibility == BindingPropertyCompatibility.None || bestProperty.Property != null && (bestProperty.Compatibility == BindingPropertyCompatibility.DataContext && PlatformTypes.Object.Equals((object)newProperty.PropertyType) || newProperty.Compatibility - bestProperty.Compatibility >= 0 && (newProperty.NullableNormalizedPropertyType == bestProperty.NullableNormalizedPropertyType || newProperty.NullableNormalizedPropertyType.IsAssignableFrom((ITypeId)bestProperty.NullableNormalizedPropertyType) || !bestProperty.NullableNormalizedPropertyType.IsAssignableFrom((ITypeId)newProperty.NullableNormalizedPropertyType))))
     {
         return(bestProperty);
     }
     return(newProperty);
 }
        public static BindingPropertyMatchInfo GetDefaultBindingPropertyInfo(SceneNode sceneNode, IType dataType)
        {
            BindingPropertyMatchInfo bestProperty = new BindingPropertyMatchInfo((IProperty)null);
            IProperty property = sceneNode.ProjectContext.ResolveProperty(BaseFrameworkElement.DataContextProperty);

            for (IType type = sceneNode.Type; type != null; type = type.BaseType)
            {
                ReferenceStep propertyInternal = BindingPropertyHelper.GetDefaultBindingPropertyInternal(type.NearestResolvedType, sceneNode.ProjectContext);
                if (propertyInternal != null && BindingPropertyHelper.IsPropertyBindable(sceneNode, new PropertyReference(propertyInternal), BindingPropertyHelper.BindingType.Target))
                {
                    BindingPropertyMatchInfo propertyMatchInfo = new BindingPropertyMatchInfo((IProperty)propertyInternal);
                    propertyMatchInfo.Compatibility = propertyInternal != property?BindingPropertyHelper.GetPropertyCompatibility(propertyMatchInfo, dataType, (ITypeResolver)sceneNode.ProjectContext) : BindingPropertyCompatibility.DataContext;

                    bestProperty = BindingPropertyHelper.GetBetterProperty(bestProperty, propertyMatchInfo);
                }
            }
            return(bestProperty);
        }
        private static BindingPropertyCompatibility GetPropertyCompatibility(BindingPropertyMatchInfo propertyInfo, IType dataType, ITypeResolver typeResolver)
        {
            IType sourceType = DesignDataHelper.GetSourceType(dataType, typeResolver);

            if (PlatformTypes.String.IsAssignableFrom((ITypeId)sourceType) && !PlatformTypes.String.IsAssignableFrom((ITypeId)propertyInfo.PropertyType) && PlatformTypes.IEnumerable.IsAssignableFrom((ITypeId)propertyInfo.PropertyType))
            {
                return(BindingPropertyCompatibility.None);
            }
            if (propertyInfo.NullableNormalizedPropertyType.IsAssignableFrom((ITypeId)sourceType) || propertyInfo.PropertyType.IsAssignableFrom((ITypeId)sourceType) || propertyInfo.PropertyType.IsBinding)
            {
                return(BindingPropertyCompatibility.Assignable);
            }
            TypeConverter typeConverter = propertyInfo.Property.TypeConverter ?? propertyInfo.Property.PropertyType.TypeConverter;

            if (typeConverter != null && typeConverter.CanConvertFrom(sourceType.RuntimeType) && (!PlatformTypes.String.IsAssignableFrom((ITypeId)sourceType) || !PlatformTypes.IConvertible.IsAssignableFrom((ITypeId)propertyInfo.NullableNormalizedPropertyType)))
            {
                return(BindingPropertyCompatibility.Convertible);
            }
            return(PlatformTypes.String.IsAssignableFrom((ITypeId)propertyInfo.PropertyType) ? BindingPropertyCompatibility.StringSpecial : BindingPropertyCompatibility.None);
        }
Exemple #4
0
        protected override IPropertyId GetDefaultPropertySelection()
        {
            BindingPropertyMatchInfo bindingPropertyInfo = BindingPropertyHelper.GetDefaultBindingPropertyInfo(this.TargetElement, this.targetPropertyType);

            if (bindingPropertyInfo.Compatibility != BindingPropertyCompatibility.None)
            {
                ReferenceStep referenceStep = (ReferenceStep)bindingPropertyInfo.Property;
                if (this.sourceBindingProperties.Contains(referenceStep))
                {
                    return((IPropertyId)referenceStep);
                }
            }
            foreach (ReferenceStep referenceStep in (IEnumerable <ReferenceStep>) this.sourceBindingProperties)
            {
                if (this.targetPropertyType != null && this.targetPropertyType.IsAssignableFrom((ITypeId)referenceStep.PropertyType))
                {
                    return((IPropertyId)referenceStep);
                }
            }
            return((IPropertyId)null);
        }