private static object InstantiateConstructorArgument(IInstanceBuilderContext context, ViewNode viewNode, IParameter constructorArgument, IProperty constructorArgumentProperty, DocumentNode constructorArgumentNode) { object defaultValue; if (constructorArgumentProperty != null) { return(InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, constructorArgumentProperty, constructorArgumentNode).Instance); } if (constructorArgumentNode != null) { ViewNode viewNode1 = InstanceBuilderOperations.UpdateChildWithoutApply(context, viewNode, viewNode.Children.Count, DocumentNodeChangeAction.Add, constructorArgumentNode); return(viewNode1.Instance); } IDocumentContext documentContext = viewNode.DocumentNode.Context; Type targetType = viewNode.TargetType; Type runtimeType = constructorArgument.ParameterType.RuntimeType; ReferenceStep referenceStep = constructorArgumentProperty as ReferenceStep; if (referenceStep == null || !referenceStep.HasDefaultValue(targetType)) { bool flag = documentContext.TypeResolver.InTargetAssembly(constructorArgument.ParameterType); defaultValue = InstanceBuilderOperations.InstantiateType(runtimeType, flag); } else { defaultValue = referenceStep.GetDefaultValue(targetType); } if (context.IsSerializationScope) { defaultValue = documentContext.CreateNode(runtimeType, defaultValue); } return(defaultValue); }
public override void OnViewNodeInvalidating(IInstanceBuilderContext context, ViewNode target, ViewNode child, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots) { if (target.InstanceState.IsPropertyOrChildInvalid) { InstanceBuilderOperations.SetInvalid(context, target, ref doesInvalidRootsContainTarget, invalidRoots); } base.OnViewNodeInvalidating(context, target, child, ref doesInvalidRootsContainTarget, invalidRoots); }
public override void OnViewNodeInvalidating(IInstanceBuilderContext context, ViewNode target, ViewNode child, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots) { InstanceState instanceState = target.InstanceState; if (target.Instance is DocumentNode && instanceState.IsPropertyInvalid && !instanceState.IsChildInvalid && !instanceState.IsDescendantInvalid) { IInstantiatedElementViewNode instantiatedElementViewNode = target as IInstantiatedElementViewNode; if (instantiatedElementViewNode != null && instantiatedElementViewNode.InstantiatedElements.First != null) { bool flag = true; using (IEnumerator <IProperty> enumerator = instanceState.InvalidProperties.GetEnumerator()) { do { if (!enumerator.MoveNext()) { break; } flag = this.IsIncrementalChange(context, target, enumerator.Current); }while (flag); } if (flag) { return; } } } bool flag1 = false; if (instanceState != InstanceState.Valid) { T instance = (T)(target.Instance as T); if (instance != null && this.IsSealed(instance)) { flag1 = true; } IInstantiatedElementViewNode instantiatedElementViewNode1 = target as IInstantiatedElementViewNode; if (instantiatedElementViewNode1 != null && instantiatedElementViewNode1.InstantiatedElements.First != null) { foreach (object instantiatedElement in instantiatedElementViewNode1.InstantiatedElements) { instance = (T)(instantiatedElement as T); if (instance == null || !this.IsSealed(instance)) { continue; } flag1 = true; break; } } } if (flag1) { InstanceBuilderOperations.SetInvalid(context, target, ref doesInvalidRootsContainTarget, invalidRoots); } base.OnViewNodeInvalidating(context, target, child, ref doesInvalidRootsContainTarget, invalidRoots); }
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 bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { DocumentNode documentNode = viewNode.DocumentNode; DocumentCompositeNode documentCompositeNode = documentNode as DocumentCompositeNode; bool flag = false; if (!PlatformTypes.FrameworkElement.IsAssignableFrom(viewNode.Type)) { if (documentCompositeNode != null && documentCompositeNode.SupportsChildren && documentCompositeNode.Children.Count > 0) { IList listAdapter = InstanceBuilderOperations.GetListAdapter(viewNode.Instance); if (listAdapter != null) { listAdapter.Clear(); } } flag = true; viewNode.Instance = null; } else { IPlatformMetadata platformMetadata = documentNode.TypeResolver.PlatformMetadata; if (!context.IsSerializationScope) { try { ViewNode viewNode1 = viewNode; FallbackControlType fallbackControlType = default(FallbackControlType); viewNode1.Instance = (fallbackControlType == null ? Activator.CreateInstance <FallbackControlType>() : default(FallbackControlType)); } catch (Exception exception) { viewNode.Instance = null; flag = true; } } else { DocumentCompositeNode documentCompositeNode1 = context.DocumentContext.CreateNode(typeof(FallbackControlType)); ViewNodeId id = context.SerializationContext.GetId(viewNode); documentCompositeNode1.Properties[DesignTimeProperties.ViewNodeIdProperty] = context.DocumentContext.CreateNode(typeof(string), ViewNodeManager.ViewNodeIdConverter.ConvertToInvariantString(id)); viewNode.Instance = documentCompositeNode1; } if (viewNode.Instance != null && documentCompositeNode != null) { if (documentCompositeNode != null) { DocumentNode exceptionSource = context.ExceptionDictionary.GetExceptionSource(viewNode); Type runtimeType = documentNode.TypeResolver.ResolveType(PlatformTypes.FrameworkElement).RuntimeType; foreach (IProperty property in context.GetProperties(viewNode)) { try { ViewNode viewNode2 = InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, property, documentCompositeNode.Properties[property]); if (viewNode2 != null && viewNode2.Instance != null && viewNode2.DocumentNode != exceptionSource) { Type type = (context.IsSerializationScope ? ((DocumentNode)viewNode2.Instance).TargetType : viewNode2.Instance.GetType()); ReferenceStep referenceStep = property as ReferenceStep; if (referenceStep != null && referenceStep.TargetType.IsAssignableFrom(runtimeType) && PlatformTypeHelper.GetPropertyType(referenceStep).IsAssignableFrom(type)) { InstanceBuilderOperations.SetValue(viewNode.Instance, referenceStep, viewNode2.Instance); } } } catch { } } } IProperty property1 = platformMetadata.ResolveProperty(KnownProperties.FrameworkElementMinWidthProperty); InstanceBuilderOperations.SetValue(viewNode.Instance, property1, FallbackInstanceBuilder <FallbackControlType> .MinSize(context)); IProperty property2 = platformMetadata.ResolveProperty(KnownProperties.FrameworkElementMinHeightProperty); InstanceBuilderOperations.SetValue(viewNode.Instance, property2, FallbackInstanceBuilder <FallbackControlType> .MinSize(context)); } } if (flag) { viewNode.Instance = ClrObjectInstanceBuilder.InvalidObjectSentinel; } viewNode.InstanceState = InstanceState.Valid; return(true); }
public override void OnViewNodeInvalidating(IInstanceBuilderContext context, ViewNode target, ViewNode child, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots) { InstanceBuilderOperations.SetInvalid(context, target, ref doesInvalidRootsContainTarget, invalidRoots); }
public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) { InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode); }
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); } } } }
public static bool SetValue(object target, IProperty propertyKey, object value) { if (!InstanceBuilderOperations.IsSupported((IMember)propertyKey)) { return(false); } if (DesignTimeProperties.InlineXmlProperty.Equals((object)propertyKey)) { IXmlSerializable serializable = target as IXmlSerializable; if (serializable == null) { return(false); } InstanceBuilderOperations.SetXmlContent(serializable, (string)value); return(true); } DocumentCompositeNode documentCompositeNode = target as DocumentCompositeNode; if (documentCompositeNode != null) { IProperty property = (IProperty)propertyKey.Clone(documentCompositeNode.TypeResolver); documentCompositeNode.Properties[(IPropertyId)property] = (DocumentNode)value; return(true); } ReferenceStep referenceStep = propertyKey as ReferenceStep; if (referenceStep != null) { object obj = value; MarkupExtension markupExtension; if ((markupExtension = obj as MarkupExtension) != null) { if (markupExtension is TemplateBindingExtension) { throw new InstanceBuilderException(ExceptionStringTable.InvalidTemplateBindingInstanceBuilderException); } DependencyPropertyReferenceStep propertyReferenceStep1; object property; if ((propertyReferenceStep1 = referenceStep as DependencyPropertyReferenceStep) != null) { property = propertyReferenceStep1.DependencyProperty; } else { ClrPropertyReferenceStep propertyReferenceStep2; if ((propertyReferenceStep2 = referenceStep as ClrPropertyReferenceStep) == null) { return(false); } property = (object)propertyReferenceStep2.PropertyInfo; } DynamicResourceExtension resourceExtension = markupExtension as DynamicResourceExtension; FrameworkElement frameworkElement = target as FrameworkElement; FrameworkContentElement frameworkContentElement = target as FrameworkContentElement; if (resourceExtension != null && resourceExtension.ResourceKey != null && propertyReferenceStep1 != null && (frameworkElement != null || frameworkContentElement != null)) { if (frameworkElement != null) { propertyReferenceStep1.SetResourceReference((object)frameworkElement, resourceExtension.ResourceKey); } else if (frameworkContentElement != null) { propertyReferenceStep1.SetResourceReference((object)frameworkContentElement, resourceExtension.ResourceKey); } } else { if (Microsoft.Expression.DesignModel.Metadata.KnownProperties.SetterValueProperty.Equals((object)referenceStep)) { referenceStep.SetValue(target, obj); return(true); } bool flag = false; try { obj = markupExtension.ProvideValue((IServiceProvider) new InstanceBuilderOperations.InstanceBuilderServiceProvider(target, property, (IMetadataResolver)referenceStep.DeclaringType.PlatformMetadata)); flag = true; } catch (InvalidOperationException ex) { } if (flag) { if (!(obj is MarkupExtension)) { return(InstanceBuilderOperations.SetValue(target, (IProperty)referenceStep, obj)); } referenceStep.SetValue(target, obj); return(true); } } } else { //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //if (obj is Expression) //{ // referenceStep.SetValue(target, obj); // return true; //} if (obj != null) { bool flag = false; DependencyPropertyReferenceStep propertyReferenceStep = referenceStep as DependencyPropertyReferenceStep; if (propertyReferenceStep != null) { ITypeId type = (ITypeId)propertyReferenceStep.PlatformTypes.GetType(obj.GetType()); if (PlatformTypes.Binding.IsAssignableFrom(type)) { flag = true; } } if (flag) { propertyReferenceStep.SetBinding(target, value); return(true); } if (!PlatformTypeHelper.GetPropertyType((IProperty)referenceStep).IsInstanceOfType(obj)) { return(false); } } referenceStep.SetValue(target, obj); return(true); } } return(false); }