Example #1
0
        public ViewNode GetViewNode(ViewNodeId id)
        {
            ISerializationContext serializationContext;

            if (!this.serializationDictionary.TryGetValue(id.SerializationContextIndex, out serializationContext) || !serializationContext.IsValid(id))
            {
                return(null);
            }
            return(serializationContext.GetViewNode(id));
        }
Example #2
0
        public ISerializationContext GetSerializationContextById(ViewNodeId id)
        {
            ISerializationContext serializationContext;

            if (this.serializationDictionary.TryGetValue(id.SerializationContextIndex, out serializationContext) && serializationContext.IsValid(id))
            {
                return(serializationContext);
            }
            return(null);
        }
Example #3
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            ViewNodeId viewNodeId = value as ViewNodeId;

            if (viewNodeId == null)
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            string        str           = viewNodeId.ViewNodeIndex.ToString(CultureInfo.InvariantCulture);
            string        str1          = viewNodeId.SerializationContextIndex.ToString();
            StringBuilder stringBuilder = new StringBuilder(str.Length + str1.Length + 1);

            stringBuilder.Append(str1);
            stringBuilder.Append(',');
            stringBuilder.Append(str);
            return(stringBuilder.ToString());
        }
Example #4
0
        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);
        }