コード例 #1
0
 void IDataSchemaNodeDelayLoader.ProcessChildren(DataSchemaNode node)
 {
     if ((node.NodeType | SchemaNodeTypes.Method) == SchemaNodeTypes.Method)
     {
         return;
     }
     if (ClrObjectSchema.IsCollection(node.Type))
     {
         Type type = CollectionAdapterDescription.GetGenericCollectionType(node.Type);
         if (type == (Type)null)
         {
             type = typeof(object);
         }
         SchemaNodeTypes nodeType = SchemaNodeTypes.CollectionItem;
         if (ClrObjectSchema.IsCollection(type))
         {
             nodeType |= SchemaNodeTypes.CollectionItem;
         }
         DataSchemaNode dataSchemaNode = new DataSchemaNode(node.PathName, DataSchemaNode.IndexNodePath, nodeType, string.Empty, type, (IDataSchemaNodeDelayLoader)this);
         node.CollectionItem = dataSchemaNode;
     }
     else
     {
         this.AddMethodBasedChildren(node);
     }
     this.AddPropertyBasedChildren(node);
     node.Children.Sort((IComparer <DataSchemaNode>) new DataSchemaNode.PathNameComparer());
 }
コード例 #2
0
        public virtual Type GetChildType(Type instanceType)
        {
            CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(instanceType);

            if (adapterDescription == null)
            {
                return(CollectionAdapterDescription.GetGenericCollectionType(instanceType));
            }
            return(adapterDescription.ItemType);
        }
コード例 #3
0
        public static bool IsCollection(Type type)
        {
            bool flag = typeof(ICollection).IsAssignableFrom(type) || typeof(IListSource).IsAssignableFrom(type);

            if (CollectionAdapterDescription.GetGenericCollectionType(type) != (Type)null)
            {
                flag = true;
            }
            return(flag);
        }
コード例 #4
0
 public static IList GetListAdapter(object instance)
 {
     if (instance != null)
     {
         CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(instance.GetType());
         if (adapterDescription != null)
         {
             return(adapterDescription.GetCollectionAdapter(instance) as IList);
         }
     }
     return(null);
 }
コード例 #5
0
 protected override IDocumentNodeChildBuilder GetDefaultHandler(Type type)
 {
     base.InitializeIfNecessary();
     if (type.IsArray)
     {
         return(this.arrayChildBuilder);
     }
     if (CollectionAdapterDescription.GetAdapterDescription(type) == null)
     {
         return(null);
     }
     return(this.collectionChildBuilder);
 }
コード例 #6
0
            public override void ShowDialog(Microsoft.Windows.Design.PropertyEditing.PropertyValue propertyValue, IInputElement commandSource)
            {
                this.activeDialog = (Dialog) new DialogValueEditorHost(propertyValue, this.template);
                ValueEditorUtils.SetHandlesCommitKeys((DependencyObject)this.activeDialog, true);
                Type   genericCollectionType = CollectionAdapterDescription.GetGenericCollectionType(propertyValue.ParentProperty.PropertyType);
                string str = "";

                if (genericCollectionType != (Type)null)
                {
                    str = genericCollectionType.Name + " ";
                }
                this.activeDialog.Title = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.CollectionEditorDialogTitle, new object[2]
                {
                    (object)str,
                    (object)propertyValue.ParentProperty.PropertyName
                });
                this.activeDialog.ResizeMode    = ResizeMode.CanResize;
                this.activeDialog.Width         = 600.0;
                this.activeDialog.Height        = 600.0;
                this.activeDialog.SizeToContent = SizeToContent.Manual;
                this.activeDialog.CommandBindings.Add(new CommandBinding((ICommand)PropertyValueEditorCommands.FinishEditing, new ExecutedRoutedEventHandler(this.OnPropertyValueFinishEditingCommand)));
                PropertyValueEditorCommands.BeginTransaction.Execute((object)new PropertyTransactionParameters()
                {
                    TransactionDescription = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertyChangeUndoDescription, new object[1]
                    {
                        (object)propertyValue.ParentProperty.PropertyName
                    }),
                    TransactionType = SceneEditTransactionType.Normal
                }, commandSource);
                bool?nullable = new bool?();

                try
                {
                    nullable = this.activeDialog.ShowDialog();
                }
                catch
                {
                    this.messageDisplayService.ShowError(StringTable.CollectionEditorErrorMessage);
                    this.activeDialog.Close();
                }
                if (nullable.HasValue && nullable.Value)
                {
                    PropertyValueEditorCommands.CommitTransaction.Execute((object)null, commandSource);
                }
                else
                {
                    PropertyValueEditorCommands.AbortTransaction.Execute((object)null, commandSource);
                }
            }
コード例 #7
0
        public static bool IsTypeCompatible(SceneNode sceneNode, IType typeToInsert, IProperty property)
        {
            if (typeToInsert.RuntimeType == (Type)null || !sceneNode.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)sceneNode.ProjectContext, (ITypeId)typeToInsert) || PlatformTypes.UserControl.IsAssignableFrom((ITypeId)sceneNode.Type) && PropertySceneInsertionPoint.ContentProperty.Equals((object)property) && sceneNode.ViewModel.RootNode != sceneNode || (PlatformTypes.Window.IsAssignableFrom((ITypeId)typeToInsert) || PlatformTypes.Page.IsAssignableFrom((ITypeId)typeToInsert) || !property.TargetType.IsAssignableFrom(sceneNode.TargetType) || PlatformTypes.IsEffectType((ITypeId)typeToInsert) && property.PropertyType.Equals((object)PlatformTypes.Object)))
            {
                return(false);
            }
            if (property.PropertyType.IsAssignableFrom((ITypeId)typeToInsert))
            {
                return(true);
            }
            if (!sceneNode.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsAutoTabItemWrapping) && ProjectNeutralTypes.TabControl.IsAssignableFrom((ITypeId)sceneNode.TrueTargetTypeId) && (PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)typeToInsert) && !ProjectNeutralTypes.TabItem.IsAssignableFrom((ITypeId)typeToInsert)))
            {
                return(false);
            }
            if (property.Equals((object)BehaviorHelper.BehaviorsProperty) && ProjectNeutralTypes.Behavior.IsAssignableFrom((ITypeId)typeToInsert) || property.Equals((object)BehaviorHelper.BehaviorTriggersProperty) && (ProjectNeutralTypes.BehaviorTriggerAction.IsAssignableFrom((ITypeId)typeToInsert) || ProjectNeutralTypes.BehaviorTriggerBase.IsAssignableFrom((ITypeId)typeToInsert)))
            {
                return(BehaviorHelper.IsSceneNodeValidHost(sceneNode, typeToInsert));
            }
            Type genericCollectionType = CollectionAdapterDescription.GetGenericCollectionType(PlatformTypeHelper.GetPropertyType(property));

            return(genericCollectionType != (Type)null && sceneNode.ProjectContext.GetType(genericCollectionType).IsAssignableFrom((ITypeId)typeToInsert) || PlatformTypes.UIElementCollection.Equals((object)property.PropertyType) && PlatformTypes.UIElement.IsAssignableFrom((ITypeId)typeToInsert) || (PlatformTypes.FlowDocument.IsAssignableFrom((ITypeId)property.PropertyType) || PlatformTypes.InlineCollection.IsAssignableFrom((ITypeId)property.PropertyType) || PlatformTypes.BlockCollection.IsAssignableFrom((ITypeId)property.PropertyType)) && (PlatformTypes.UIElement.IsAssignableFrom((ITypeId)typeToInsert) && (bool)sceneNode.ViewModel.ProjectContext.GetCapabilityValue(PlatformCapability.SupportsInlineUIContainer)) || (PlatformTypes.ItemCollection.Equals((object)property.PropertyType) || ItemsControlElement.ItemsProperty.Equals((object)property)));
        }
コード例 #8
0
 public override object CreateType(Type type)
 {
     if (type == (Type)null)
     {
         SceneNodeProperty sceneNodeProperty = this.Host.PropertyValue.get_ParentProperty() as SceneNodeProperty;
         if (sceneNodeProperty != null)
         {
             SceneViewModel viewModel             = sceneNodeProperty.SceneNodeObjectSet.ViewModel;
             ReferenceStep  step                  = (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)viewModel.ProjectContext, ((PropertyEntry)sceneNodeProperty).get_PropertyType(), 0);
             Type           propertyType          = sceneNodeProperty.Reference.Append(step).ValueType;
             Type           genericCollectionType = CollectionAdapterDescription.GetGenericCollectionType(((PropertyEntry)sceneNodeProperty).get_PropertyType());
             if (genericCollectionType != (Type)null && propertyType.IsAssignableFrom(genericCollectionType))
             {
                 propertyType = genericCollectionType;
             }
             SceneNode typeForProperty = this.CreateTypeForProperty(viewModel, propertyType);
             if (typeForProperty != null)
             {
                 return((object)typeForProperty.DocumentNode);
             }
         }
     }
     return(null);
 }
コード例 #9
0
        private static object CreateClrDataContext(DataSourceInfo dataSource, SceneViewModel viewModel)
        {
            DocumentNode sourceNode = dataSource.SourceNode;

            if (PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)sourceNode.Type))
            {
                return((object)null);
            }
            object obj1 = (object)null;

            using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(viewModel.Document.DocumentContext, viewModel.DesignerContext))
            {
                try
                {
                    IInstanceBuilder builder  = instanceBuilderContext.InstanceBuilderFactory.GetBuilder(sourceNode.TargetType);
                    ViewNode         viewNode = builder.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, sourceNode);
                    if (builder.Instantiate((IInstanceBuilderContext)instanceBuilderContext, viewNode))
                    {
                        obj1 = DataContextEvaluator.GetEvaluatedValue(viewNode.Instance);
                    }
                }
                catch
                {
                }
            }
            if (obj1 == null || string.IsNullOrEmpty(dataSource.Path))
            {
                return(obj1);
            }
            object instance = obj1;

            try
            {
                IList <ClrPathPart> list1 = ClrPropertyPathHelper.SplitPath(dataSource.Path);
                if (list1 == null)
                {
                    return((object)null);
                }
                for (int index = 0; index < list1.Count; ++index)
                {
                    if (instance != null)
                    {
                        Type        type        = instance.GetType();
                        object      obj2        = (object)null;
                        ClrPathPart clrPathPart = list1[index];
                        if (clrPathPart.Category == ClrPathPartCategory.PropertyName)
                        {
                            PropertyInfo property = type.GetProperty(clrPathPart.Path);
                            if (property != (PropertyInfo)null)
                            {
                                obj2 = property.GetValue(instance, (object[])null);
                            }
                        }
                        else
                        {
                            CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type);
                            if (adapterDescription != null)
                            {
                                IList list2 = adapterDescription.GetCollectionAdapter(instance) as IList;
                                if (list2 != null)
                                {
                                    int result = 0;
                                    if (clrPathPart.Category == ClrPathPartCategory.IndexStep)
                                    {
                                        if (!int.TryParse(clrPathPart.Path.Trim('[', ']'), out result))
                                        {
                                            goto label_23;
                                        }
                                    }
                                    obj2 = list2[result];
                                }
                            }
                        }
label_23:
                        instance = obj2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch
            {
                instance = (object)null;
            }
            return(instance);
        }
コード例 #10
0
        private object ConvertInternalFast(object value, ITypeResolver sourceTypeResolver, ITypeResolver targetTypeResolver)
        {
            if (value == null)
            {
                return(value);
            }
            Type   type         = value.GetType();
            IType  platformType = ((IPlatformTypes)targetTypeResolver.PlatformMetadata).GetPlatformType(type.FullName);
            Type   runtimeType  = platformType.RuntimeType;
            object obj1;

            if (type.IsPrimitive || type.IsEnum)
            {
                if (runtimeType == (Type)null)
                {
                    return((object)null);
                }
                if (runtimeType.Equals(type))
                {
                    obj1 = value;
                }
                else
                {
                    TypeConverter typeConverter = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type);
                    obj1 = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(runtimeType).ConvertFromInvariantString(typeConverter.ConvertToInvariantString(value));
                }
            }
            else
            {
                if (runtimeType == (Type)null)
                {
                    return((object)null);
                }
                obj1 = InstanceBuilderOperations.InstantiateType(runtimeType, true);
                if (obj1 != null && PlatformTypes.ImageBrush.IsAssignableFrom((ITypeId)platformType))
                {
                    return(this.ConvertImageBrush(value, obj1, sourceTypeResolver, targetTypeResolver));
                }
                if (!type.IsValueType)
                {
                    CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type);
                    if (adapterDescription != null)
                    {
                        IList list = CollectionAdapterDescription.GetAdapterDescription(runtimeType).GetCollectionAdapter(obj1) as IList;
                        foreach (object obj2 in (IEnumerable)adapterDescription.GetCollectionAdapter(value))
                        {
                            object obj3 = this.ConvertInternalFast(obj2, sourceTypeResolver, targetTypeResolver);
                            list.Add(obj3);
                        }
                    }
                }
                foreach (IProperty property in ((IPlatformTypes)sourceTypeResolver.PlatformMetadata).GetType(type).GetProperties(MemberAccessTypes.Public))
                {
                    ReferenceStep referenceStep1 = property as ReferenceStep;
                    if (referenceStep1 != null && referenceStep1.ReadAccess == MemberAccessType.Public && referenceStep1.WriteAccess == MemberAccessType.Public)
                    {
                        ReferenceStep referenceStep2 = platformType.GetMember(MemberType.Property, referenceStep1.Name, MemberAccessTypes.Public) as ReferenceStep;
                        if (referenceStep2 != null && referenceStep2.ReadAccess == MemberAccessType.Public && referenceStep2.WriteAccess == MemberAccessType.Public)
                        {
                            object valueToSet = this.ConvertInternalFast(referenceStep1.GetValue(value), sourceTypeResolver, targetTypeResolver);
                            referenceStep2.SetValue(obj1, valueToSet);
                        }
                    }
                }
            }
            return(obj1);
        }