public static ViewNode UpdateChildWithoutApply(IInstanceBuilderContext context, ViewNode viewNode, int childIndex, DocumentNodeChangeAction action, DocumentNode childNode) { ViewNode viewNode1 = null; if (action == DocumentNodeChangeAction.Remove) { ViewNode item = viewNode.Children[childIndex]; viewNode.Children.Remove(item); } if (action == DocumentNodeChangeAction.Add || action == DocumentNodeChangeAction.Replace) { IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(childNode.TargetType); viewNode1 = builder.GetViewNode(context, childNode); if (action != DocumentNodeChangeAction.Replace) { viewNode.Children.Insert(childIndex, viewNode1); } else { viewNode.Children[childIndex] = viewNode1; } context.ViewNodeManager.Instantiate(viewNode1); } return(viewNode1); }
public void DelayInstanceBuilding(IInstanceBuilderContext context, ViewNode viewNode) { if (this.IsDelaying && this.contexts != null) { this.GetContextInfo(context, true).AddDelayedNode(viewNode); } }
public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { TemplateBindingInstanceBuilderBase.CheckForInvalidBinding(viewNode); bool flag = base.Instantiate(context, viewNode); if (context.RootTargetTypeReplacement != null && context.IsSerializationScope) { ViewNode viewNode1 = StyleControlTemplateHelper.FindContainingControlTemplate(viewNode); if (viewNode1 != null) { ViewNode viewNode2 = StyleControlTemplateHelper.FindStyleTemplateOwningViewNode(viewNode1); if (viewNode2 == null || viewNode2 == context.ViewNodeManager.Root) { DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode; if (documentNode != null && DocumentNodeUtilities.IsTemplateBinding(documentNode)) { IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember(documentNode, KnownProperties.TemplateBindingPropertyProperty); if (valueAsMember != null) { IProperty replacementProperty = context.RootTargetTypeReplacement.GetReplacementProperty(valueAsMember as IProperty); if (replacementProperty != null && replacementProperty is DependencyPropertyReferenceStep && replacementProperty != valueAsMember) { DocumentCompositeNode instance = (DocumentCompositeNode)viewNode.Instance; instance.Properties[KnownProperties.TemplateBindingPropertyProperty] = context.DocumentContext.CreateNode(PlatformTypes.DependencyProperty, new DocumentNodeMemberValue(replacementProperty)); } } } } } } return(flag); }
public override bool AllowPostponedResourceUpdate(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNodePath evaluatedResource) { if (viewNode.Type.Metadata.NameProperty == propertyKey) { return(false); } DocumentNodePath editingContainer = context.ViewNodeManager.EditingContainer; if (editingContainer != null && DependencyObjectInstanceBuilderBase <T> .IsEvaluatedResourceWithinNodePath(editingContainer, viewNode, propertyKey, evaluatedResource)) { return(false); } if (context.IsSerializationScope && !PlatformTypes.UIElement.IsAssignableFrom(viewNode.Type)) { return(false); } if (evaluatedResource.Node != null && PlatformTypes.Visual.IsAssignableFrom(evaluatedResource.Node.Type)) { return(false); } DocumentCompositeNode node = evaluatedResource.Node as DocumentCompositeNode; if (node != null && node.PlatformMetadata.IsCapabilitySet(PlatformCapability.SupportNonSharedResources) && node.Properties[DesignTimeProperties.SharedProperty] != null && !node.GetValue <bool>(DesignTimeProperties.SharedProperty)) { return(false); } return(true); }
public override void Initialize(IInstanceBuilderContext context, ViewNode viewNode, bool isNewInstance) { if (context.IsSerializationScope || viewNode.Instance == null || viewNode.InstanceState != InstanceState.Uninitialized) { base.Initialize(context, viewNode, isNewInstance); return; } DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode; DocumentCompositeNode documentCompositeNode = documentNode; if (documentNode != null) { this.InstantiateProperties(context, viewNode, documentCompositeNode); if (documentCompositeNode.SupportsChildren) { for (int i = 0; i < documentCompositeNode.Children.Count; i++) { DocumentNode item = documentCompositeNode.Children[i]; IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(item.TargetType); ViewNode viewNode1 = builder.GetViewNode(context, item); viewNode.Children.Add(viewNode1); this.InstantiateChild(context, viewNode, viewNode1); } } } viewNode.InstanceState = InstanceState.Valid; this.OnInitialized(context, viewNode, viewNode.Instance); }
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); }
protected override object InstantiateTargetType(IInstanceBuilderContext context, ViewNode viewNode) { DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode; if (documentNode == null) { return(base.InstantiateTargetType(context, viewNode)); } object obj = null; Type targetType = documentNode.TargetType; if (targetType.IsArray) { Type elementType = targetType.GetElementType(); if (elementType != null) { try { obj = Array.CreateInstance(elementType, documentNode.Children.Count); } catch { } } } return(obj); }
public static bool ShouldInstantiatePreviewControl(IInstanceBuilderContext context, ViewNode viewNode, out XamlDocument sourceDocument, out string sourcePath) { sourceDocument = null; sourcePath = null; if (!PlatformTypes.UserControl.Equals(viewNode.Type)) { DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode; IProperty property = documentNode.TypeResolver.ResolveProperty(DesignTimeProperties.ClassProperty); if (documentNode != null && !documentNode.Properties.Contains(property)) { sourcePath = viewNode.Type.XamlSourcePath; if (!string.IsNullOrEmpty(sourcePath)) { if (context.CurrentlyInstantiatingUserControlPreviews.Contains(sourcePath)) { return(false); } try { sourceDocument = (XamlDocument)context.DocumentRootResolver.GetDocumentRoot(sourcePath); } catch (FileNotFoundException fileNotFoundException) { } if (sourceDocument != null && UserControlInstanceBuilderHelper.ShouldUseDocumentForPreview(context, sourceDocument)) { return(true); } } } } return(false); }
private static bool ShouldUseDocumentForPreview(IInstanceBuilderContext context, XamlDocument xamlDocument) { if (!PlatformTypes.PlatformsCompatible(context.Platform.Metadata, xamlDocument.TypeResolver.PlatformMetadata)) { return(false); } return(context.ShouldInstantiatePreviewControl(xamlDocument)); }
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 ViewNode GetViewNode(IInstanceBuilderContext context, DocumentNode documentNode) { if (context.IsSerializationScope) { return(new InstantiatedElementViewNode(context.ViewNodeManager, documentNode)); } return(base.GetViewNode(context, documentNode)); }
public static object FalseValue(IInstanceBuilderContext context) { if (!context.IsSerializationScope) { return(false); } return(context.DocumentContext.CreateNode(PlatformTypes.Boolean, new DocumentNodeStringValue(bool.FalseString))); }
private void EnsureInstanceBuilderContext() { if (this.context != null) { return; } this.context = (IInstanceBuilderContext) new StandaloneInstanceBuilderContext(this.DocumentContext, this.designerContext); }
public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { if (viewNode != null && viewNode.DocumentNode != null && viewNode.DocumentNode.Parent != null) { BindingInstanceBuilderBase.CheckForInvalidBinding(viewNode); } return(base.Instantiate(context, viewNode)); }
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 void SetInvalid(IInstanceBuilderContext context, ViewNode target, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots) { target.MergeState(InstanceState.Invalid); if (!doesInvalidRootsContainTarget) { invalidRoots.Add(target); doesInvalidRootsContainTarget = true; } }
public static T InstantiateTargetType <T>(IAssembly projectAssembly, IInstanceBuilderContext context, Type type) where T : class { if (!(type != null) || type.IsInterface) { return(Activator.CreateInstance <T>()); } return((T)ViewContentProvider.InstantiateTargetType(projectAssembly, context, type)); }
public void Initialize(IInstanceBuilderContext context, ViewNode viewNode, bool isNewInstance) { this.builder.Initialize(context, viewNode, isNewInstance); if (context.IsSerializationScope) { return; } this.OnInitialized(context, viewNode, viewNode.Instance); }
private CrossDocumentUpdateContext.ContextInfo GetContextInfo(IInstanceBuilderContext context, bool createIfMissing) { CrossDocumentUpdateContext.ContextInfo contextInfo = this.contexts.Find((CrossDocumentUpdateContext.ContextInfo info) => info.Context == context); if (contextInfo == null && createIfMissing) { contextInfo = new CrossDocumentUpdateContext.ContextInfo(context); this.contexts.Add(contextInfo); } return(contextInfo); }
private static object MinSize(IInstanceBuilderContext context) { object obj = 50; if (context.IsSerializationScope) { obj = context.DocumentContext.CreateNode(typeof(double), 50); } return(obj); }
public override void OnViewNodeInvalidating(IInstanceBuilderContext context, ViewNode target, ViewNode child, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots) { base.OnViewNodeInvalidating(context, target, child, ref doesInvalidRootsContainTarget, invalidRoots); DocumentCompositeNode fromXamlDocument = SampleDataSet.SampleDataSetFromType(target.DocumentNode.Type.RuntimeType).ValidRootNodeFromXamlDocument; if (fromXamlDocument == null || !this.IsSampleDataXamlContext(context, fromXamlDocument.DocumentRoot)) { return; } InstanceBuilderOperations.SetInvalid(context, target, ref doesInvalidRootsContainTarget, invalidRoots); }
protected virtual void InstantiateChild(IInstanceBuilderContext context, ViewNode dictionaryNode, ViewNode childNode) { context.ViewNodeManager.Instantiate(childNode); DictionaryEntry instance = (DictionaryEntry)childNode.Instance; object dictionaryKey = this.GetDictionaryKey(childNode.TypeResolver, instance); if (dictionaryKey != null) { this.AddEntry(dictionaryNode, dictionaryKey, instance.Value); } }
public void OnViewNodeRemoving(IInstanceBuilderContext context, ViewNode viewNode) { if (this.contexts != null) { CrossDocumentUpdateContext.ContextInfo contextInfo = this.GetContextInfo(context, false); if (contextInfo != null && contextInfo.DelayedNodes != null) { contextInfo.DelayedNodes.Remove(viewNode); } } }
public static object InstantiateTargetType(IAssembly projectAssembly, IInstanceBuilderContext context, Type type) { bool flag = (projectAssembly == null ? false : projectAssembly.CompareTo(type.Assembly)); IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(type); if (builder.ReplacementType == null) { return(InstanceBuilderOperations.InstantiateType(type, flag)); } return(InstanceBuilderOperations.InstantiateType(builder.ReplacementType, true)); }
public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { if (context.IsSerializationScope) { return(base.Instantiate(context, viewNode)); } if (viewNode.Instance != null) { return(false); } viewNode.Instance = this.InstantiateTargetType(context, viewNode); return(true); }
private static bool HasInvalidAncestor(IInstanceBuilderContext context, ViewNode source, out bool hitRoot) { ViewNode parent = source; hitRoot = false; while (parent != null) { if (parent.InstanceState == InstanceState.Invalid) { return(true); } hitRoot = parent == context.ViewNodeManager.Root; parent = parent.Parent; } return(false); }
public void OnInitialized(IInstanceBuilderContext context, ViewNode target, object instance) { if (instance != null && this.targetType.IsAssignableFrom(instance.GetType())) { ITypeResolver typeResolver = target.DocumentNode.TypeResolver; IPlatform platform = context.Platform; platform.ViewObjectFactory.Instantiate(instance).SetValue(typeResolver, typeResolver.ResolveProperty(DesignTimeProperties.InstanceBuilderContextProperty), (object)new WeakReference((object)context)); IDesignModeValueProviderContext valueProviderContext = context as IDesignModeValueProviderContext; if (valueProviderContext != null) { ValueTranslationService valueTranslationService = valueProviderContext.ValueTranslationService; foreach (PropertyIdentifier identifier in valueTranslationService.GetProperties(this.targetType)) { if (valueTranslationService.HasValueTranslation(this.targetType, identifier)) { ReferenceStep referenceStep = target.Type.GetMember(MemberType.Property, identifier.Name, MemberAccessTypes.All) as ReferenceStep; if (referenceStep != null) { if (!target.Properties.ContainsKey((IProperty)referenceStep)) { ReferenceStep referenceStep1 = (ReferenceStep)DesignTimeProperties.GetShadowProperty((IProperty)referenceStep, (ITypeId)target.Type); object valueToSet = referenceStep.GetValue(instance); if (typeResolver.IsCapabilitySet(PlatformCapability.IsWpf) || valueToSet != null) { referenceStep1.SetValue(instance, valueToSet); } } PropertyIdentifier localProperty = identifier; UIThreadDispatcherHelper.BeginInvoke(DispatcherPriority.Send, (Delegate)(o => { if (target.Parent != null) { DesignModeValueProviderService.RunDesignModeValueProvider(instance, platform, valueTranslationService, target.Type, this.targetType, localProperty, referenceStep, true); } return((object)null); }), (object)null); } } } } } if (!context.IsSerializationScope) { return; } this.builder.OnInitialized(context, target, instance); }
public static bool UseDesignTimeSize(object target, IInstanceBuilderContext context) { bool documentNode = false; if (context != null && context.ContainerRoot != null && context.ContainerRoot.DocumentNode != null && context.ContainerRoot.DocumentNode.DocumentRoot != null && context.ViewNodeManager != null && context.ViewNodeManager.Root != null) { ViewNode viewNode = context.InstanceDictionary.GetViewNode(target, true); if ((viewNode == null ? true : viewNode.Parent != null)) { documentNode = context.ViewNodeManager.Root.DocumentNode != context.ContainerRoot.DocumentNode.DocumentRoot.RootNode; IInstantiatedElementViewNode root = context.ViewNodeManager.Root as IInstantiatedElementViewNode; if (documentNode && root != null) { object first = root.InstantiatedElements.First; if (first != null && (bool)(context.DocumentContext.TypeResolver.ResolveProperty(DesignTimeProperties.IsEnhancedOutOfPlaceRootProperty) as DependencyPropertyReferenceStep).GetValue(first)) { documentNode = false; } } if (documentNode && viewNode != null) { DocumentNodePath containerNodePath = context.ViewNodeManager.GetCorrespondingNodePath(viewNode).GetContainerNodePath(); if (PlatformTypes.ControlTemplate.Equals(containerNodePath.Node.Type) && containerNodePath.Node != context.ViewNodeManager.Root.DocumentNode) { DocumentNodePath parent = containerNodePath.GetParent(); if (parent.Node.Type.Equals(PlatformTypes.Setter) && parent.Node is DocumentCompositeNode) { IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember((DocumentCompositeNode)parent.Node, Microsoft.Expression.DesignModel.Metadata.KnownProperties.SetterPropertyProperty); if (valueAsMember.Equals(Microsoft.Expression.DesignModel.Metadata.KnownProperties.ControlTemplateProperty) || valueAsMember.Equals(Microsoft.Expression.DesignModel.Metadata.KnownProperties.PageTemplateProperty)) { containerNodePath = parent.GetContainerNodePath(); } } } if (containerNodePath.Node != context.ViewNodeManager.Root.DocumentNode) { documentNode = false; } } } else { documentNode = true; } } return(documentNode); }
public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { IPropertyId sitePropertyKey; DocumentPrimitiveNode documentNode = viewNode.DocumentNode as DocumentPrimitiveNode; if (documentNode != null) { DocumentNodeStringValue value = documentNode.Value as DocumentNodeStringValue; if (value != null) { if (viewNode.Parent == null || !viewNode.IsProperty) { sitePropertyKey = null; } else { sitePropertyKey = viewNode.SitePropertyKey; } IPropertyId propertyProperty = sitePropertyKey; if (viewNode.Parent != null) { IPropertyValueTypeMetadata metadata = viewNode.Parent.DocumentNode.Type.Metadata as IPropertyValueTypeMetadata; IPropertyValueTypeMetadata propertyValueTypeMetadatum = metadata; if (metadata != null) { propertyProperty = propertyValueTypeMetadatum.PropertyProperty; } } if (this.ShouldUseDesignTimeUri(propertyProperty)) { Uri uri = new Uri(value.Value, UriKind.RelativeOrAbsolute); Uri uri1 = viewNode.DocumentNode.Context.MakeDesignTimeUri(uri); if (!context.IsSerializationScope) { viewNode.Instance = uri1; } else { viewNode.Instance = DocumentNodeUtilities.NewUriDocumentNode(context.DocumentContext, uri1); } viewNode.InstanceState = InstanceState.Valid; } } } return(base.Instantiate(context, viewNode)); }
public static ViewNode UpdatePropertyWithoutApply(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) { ViewNode item = viewNode.Properties[propertyKey]; ViewNode viewNode1 = null; if (item != null) { viewNode.Properties[propertyKey] = null; } if (valueNode != null) { IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(valueNode.TargetType); viewNode1 = builder.GetViewNode(context, valueNode); viewNode.Properties[propertyKey] = viewNode1; context.ViewNodeManager.Instantiate(viewNode1); } return(viewNode1); }