Пример #1
0
        public static bool ClearValue(object target, IProperty propertyKey)
        {
            if (!InstanceBuilderOperations.IsSupported(propertyKey))
            {
                return(false);
            }
            DocumentCompositeNode documentCompositeNode = target as DocumentCompositeNode;

            if (documentCompositeNode != null)
            {
                documentCompositeNode.Properties[propertyKey] = null;
                return(true);
            }
            ReferenceStep referenceStep = propertyKey as ReferenceStep;

            if (referenceStep == null)
            {
                return(false);
            }
            referenceStep.ClearValue(target);
            return(true);
        }
        public override void ModifyValue(IInstanceBuilderContext context, ViewNode target, object onlyThisInstance, IProperty propertyKey, object value, PropertyModification modification)
        {
            IProperty shadowProperty;

            if (!context.IsSerializationScope)
            {
                IInstantiatedElementViewNode instantiatedElementViewNode = target as IInstantiatedElementViewNode;
                if (instantiatedElementViewNode != null && onlyThisInstance == null && instantiatedElementViewNode.InstantiatedElements.First != null)
                {
                    if (context.UseShadowProperties)
                    {
                        shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, target.DocumentNode.Type);
                    }
                    else
                    {
                        shadowProperty = null;
                    }
                    IProperty property = shadowProperty;
                    if (property != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(target.TypeResolver, property))
                    {
                        propertyKey = property;
                    }
                    ReferenceStep referenceStep = propertyKey as ReferenceStep;
                    if (referenceStep != null)
                    {
                        foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                        {
                            if (modification != PropertyModification.Set)
                            {
                                referenceStep.ClearValue(instantiatedElement);
                            }
                            else
                            {
                                InstanceBuilderOperations.SetValue(instantiatedElement, referenceStep, value);
                            }
                        }
                        return;
                    }
                }
            }
            if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey))
            {
                string valueAsString = null;
                if (context.IsSerializationScope)
                {
                    DocumentPrimitiveNode documentPrimitiveNode = value as DocumentPrimitiveNode;
                    if (documentPrimitiveNode != null)
                    {
                        valueAsString = DocumentPrimitiveNode.GetValueAsString(documentPrimitiveNode);
                    }
                }
                else
                {
                    valueAsString = value as string;
                    if (string.IsNullOrEmpty(valueAsString) && (ProjectNeutralTypes.VisualStateGroup.IsAssignableFrom(target.Type) || ProjectNeutralTypes.VisualState.IsAssignableFrom(target.Type)))
                    {
                        valueAsString = ((DocumentCompositeNode)target.DocumentNode).GetValueAsString(target.DocumentNode.NameProperty);
                    }
                }
                if (valueAsString != null && string.IsNullOrEmpty(valueAsString))
                {
                    CultureInfo currentCulture = CultureInfo.CurrentCulture;
                    string      instanceBuilderNamePropertyNotValid = ExceptionStringTable.InstanceBuilderNamePropertyNotValid;
                    object[]    objArray = new object[] { valueAsString };
                    throw new InstanceBuilderException(string.Format(currentCulture, instanceBuilderNamePropertyNotValid, objArray), target.DocumentNode);
                }
            }
            base.ModifyValue(context, target, onlyThisInstance, propertyKey, value, modification);
        }
        public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
        {
            string        instance;
            string        str;
            IPropertyId   shadowProperty;
            ReferenceStep referenceStep = propertyKey as ReferenceStep;
            ViewNode      item          = viewNode.Properties[propertyKey];

            if (item != null && DocumentNodeUtilities.IsBinding(item.DocumentNode) && referenceStep != null)
            {
                ReferenceStep referenceStep1 = referenceStep;
                if (context.UseShadowProperties)
                {
                    shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, viewNode.DocumentNode.Type);
                }
                else
                {
                    shadowProperty = null;
                }
                IPropertyId propertyId = shadowProperty;
                if (propertyId != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, propertyId))
                {
                    referenceStep1 = propertyId as ReferenceStep;
                }
                if (referenceStep1 != null)
                {
                    IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode;
                    if (instantiatedElementViewNode == null)
                    {
                        referenceStep1.ClearValue(viewNode.Instance);
                    }
                    else
                    {
                        foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                        {
                            referenceStep1.ClearValue(instantiatedElement);
                        }
                    }
                }
            }
            if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey) && InstanceBuilderOperations.GetIsInlinedResourceWithoutNamescope(viewNode))
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
                return;
            }
            INameScope nameScope = context.NameScope;
            bool       flag      = (nameScope == null ? false : propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey));

            if (flag)
            {
                ViewNode item1 = viewNode.Properties[propertyKey];
                if (item1 != null)
                {
                    str = item1.Instance as string;
                }
                else
                {
                    str = null;
                }
                string str1 = str;
                if (!string.IsNullOrEmpty(str1) && nameScope.FindName(str1) != null)
                {
                    context.NameScope.UnregisterName(str1);
                }
            }
            if ((!context.IsSerializationScope || !(propertyKey is Event)) && (context.IsSerializationScope || !DesignTimeProperties.IsDocumentOnlyDesignTimeProperty(propertyKey)))
            {
                base.UpdateProperty(context, viewNode, propertyKey, valueNode);
            }
            else
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
            }
            if (flag)
            {
                ViewNode viewNode1 = viewNode.Properties[propertyKey];
                if (viewNode1 != null)
                {
                    instance = viewNode1.Instance as string;
                }
                else
                {
                    instance = null;
                }
                string str2 = instance;
                if (!string.IsNullOrEmpty(str2))
                {
                    try
                    {
                        if (!str2.StartsWith("~", StringComparison.Ordinal) && !str2.Contains("."))
                        {
                            if (nameScope.FindName(str2) != null)
                            {
                                nameScope.UnregisterName(str2);
                            }
                            nameScope.RegisterName(str2, viewNode.Instance);
                        }
                    }
                    catch (ArgumentException argumentException1)
                    {
                        ArgumentException argumentException = argumentException1;
                        ViewNodeManager   viewNodeManager   = viewNode1.ViewNodeManager;
                        CultureInfo       currentCulture    = CultureInfo.CurrentCulture;
                        string            instanceBuilderUnableToRegisterName = ExceptionStringTable.InstanceBuilderUnableToRegisterName;
                        object[]          objArray = new object[] { str2 };
                        viewNodeManager.OnException(viewNode1, new InstanceBuilderException(string.Format(currentCulture, instanceBuilderUnableToRegisterName, objArray), argumentException, viewNode1.DocumentNode, viewNode), false);
                    }
                }
            }
        }