private static bool IsPropertyBindableAsTarget(SceneNode sceneNode, ReferenceStep referenceStep, bool isDeclaringTypeBindable)
        {
            if (referenceStep.Equals((object)referenceStep.DeclaringType.Metadata.NameProperty) || (referenceStep.WriteAccess & (MemberAccessType)14) == MemberAccessType.None)
            {
                return(false);
            }
            SceneNode[] selection = new SceneNode[1]
            {
                sceneNode
            };
            TargetedReferenceStep targetedReferenceStep = new TargetedReferenceStep(referenceStep, sceneNode.Type);

            if ((!PropertyInspectorModel.IsPropertyBrowsable(selection, targetedReferenceStep) || !PropertyInspectorModel.IsAttachedPropertyBrowsable(selection, sceneNode.Type, targetedReferenceStep, (ITypeResolver)sceneNode.ProjectContext)) && !referenceStep.Equals((object)ContentControlElement.ContentProperty))
            {
                return(false);
            }
            if (referenceStep.PropertyType.IsBinding)
            {
                return(true);
            }
            object[] customAttributes = referenceStep.GetCustomAttributes(typeof(BindableAttribute), false);
            if (customAttributes != null && customAttributes.Length > 0)
            {
                return(((BindableAttribute)customAttributes[0]).Bindable);
            }
            return(isDeclaringTypeBindable && referenceStep is DependencyPropertyReferenceStep);
        }
Esempio n. 2
0
        public void ProcessType(IType type)
        {
            Type runtimeType = type.RuntimeType;

            if (!Enumerable.Any <FeatureProvider>(this.featureManager.CreateFeatureProviders(typeof(DesignModeValueProvider), runtimeType)))
            {
                return;
            }
            IInstanceBuilder builder = this.platform.InstanceBuilderFactory.GetBuilder(runtimeType);

            if (!builder.BaseType.Equals(runtimeType))
            {
                ++DesignModeValueProviderService.uniqueId;
                TypeBuilder typeBuilder = RuntimeGeneratedTypesHelper.RuntimeGeneratedTypesAssembly.DefineType(runtimeType.Name + (object)".CustomDesignTimeProperties" + (string)(object)DesignModeValueProviderService.uniqueId, TypeAttributes.Public);
                foreach (PropertyIdentifier propertyIdentifier in this.ValueTranslationService.GetProperties(runtimeType))
                {
                    ReferenceStep referenceStep = type.GetMember(MemberType.Property, propertyIdentifier.Name, MemberAccessTypes.All) as ReferenceStep;
                    if (referenceStep != null)
                    {
                        string        str1          = "Runtime" + (object)referenceStep.Name + (string)(object)DesignModeValueProviderService.uniqueId;
                        MethodBuilder methodBuilder = typeBuilder.DefineMethod("Get" + str1, MethodAttributes.Public | MethodAttributes.Static, referenceStep.PropertyType.RuntimeType, new Type[1]
                        {
                            typeof(object)
                        });
                        methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
                        CustomAttributeBuilder customBuilder1 = new CustomAttributeBuilder(typeof(DesignerSerializationVisibilityAttribute).GetConstructor(new Type[1]
                        {
                            typeof(DesignerSerializationVisibility)
                        }), new object[1]
                        {
                            (object)DesignerSerializationVisibility.Hidden
                        });
                        methodBuilder.SetCustomAttribute(customBuilder1);
                        typeBuilder.DefineMethod("Set" + str1, MethodAttributes.Public | MethodAttributes.Static, (Type)null, new Type[2]
                        {
                            typeof(object),
                            referenceStep.PropertyType.RuntimeType
                        }).GetILGenerator().Emit(OpCodes.Ret);
                        IType         type1 = type.PlatformMetadata.ResolveType(PlatformTypes.TypeConverterAttribute);
                        List <string> results;
                        if (PlatformNeutralAttributeHelper.TryGetAttributeValues <string>((IEnumerable)referenceStep.GetCustomAttributes(type1.RuntimeType, false), (ITypeId)type1, "ConverterTypeName", out results))
                        {
                            foreach (string str2 in results)
                            {
                                CustomAttributeBuilder customBuilder2 = new CustomAttributeBuilder(type1.RuntimeType.GetConstructor(new Type[1]
                                {
                                    typeof(string)
                                }), new object[1]
                                {
                                    (object)str2
                                });
                                methodBuilder.SetCustomAttribute(customBuilder2);
                            }
                        }
                        typeBuilder.DefineField(str1 + "Property", this.platform.Metadata.ResolveType(PlatformTypes.DependencyProperty).RuntimeType, FieldAttributes.Public | FieldAttributes.Static);
                    }
                }
                IType shadowSourceDeclaringType = (IType) new DesignModeValueProviderService.ShadowPropertyType((IPlatformMetadata)this.platform.Metadata, typeBuilder.CreateType());
                foreach (PropertyIdentifier propertyIdentifier in this.ValueTranslationService.GetProperties(runtimeType))
                {
                    ReferenceStep referenceStep = type.GetMember(MemberType.Property, propertyIdentifier.Name, MemberAccessTypes.All) as ReferenceStep;
                    if (referenceStep != null)
                    {
                        string                  propertyName            = "Runtime" + (object)referenceStep.Name + (string)(object)DesignModeValueProviderService.uniqueId;
                        PropertyIdentifier      localProperty           = propertyIdentifier;
                        ValueTranslationService valueTranslationService = this.ValueTranslationService;
                        object                  obj = this.platform.Metadata.DesignTimeProperties.ExternalRegisterShadow(propertyName, shadowSourceDeclaringType, (IProperty)referenceStep, DesignerSerializationVisibility.Hidden, true, (DesignTimeProperties.PropertyChangeCallback)(o => DesignModeValueProviderService.RunDesignModeValueProvider(o, this.platform, valueTranslationService, type, runtimeType, localProperty, referenceStep, false)));
                        shadowSourceDeclaringType.RuntimeType.GetField(propertyName + "Property", BindingFlags.Static | BindingFlags.Public).SetValue((object)null, obj);
                    }
                }
                DesignModeValueProviderService.DesignModeValueProviderBuilder valueProviderBuilder = new DesignModeValueProviderService.DesignModeValueProviderBuilder(runtimeType, builder);
                this.instanceBuilders.Add(valueProviderBuilder);
                this.platform.InstanceBuilderFactory.Register((IInstanceBuilder)valueProviderBuilder);
            }
            else
            {
                DesignModeValueProviderService.DesignModeValueProviderBuilder valueProviderBuilder = builder as DesignModeValueProviderService.DesignModeValueProviderBuilder;
                if (valueProviderBuilder == null)
                {
                    return;
                }
                valueProviderBuilder.AddReference();
            }
        }