コード例 #1
0
ファイル: DynamicTypeDescriptor.cs プロジェクト: psulek/doemd
            public PropertyDescriptorCollection Build()
            {
                foreach (var propertyDescriptorItem in updatedAttributes.Values)
                {
                    var newAttributes = propertyDescriptorItem.Attributes.ToArray();
                    var propertyDescriptorToReplace = propertyDescriptorItem.PropertyDescriptorToReplace;
                    if (propertyDescriptorToReplace != null)
                    {
                        PropertyDescriptor newDescriptor;
                        if (propertyDescriptorToReplace is ElementPropertyDescriptor)
                        {
                            ElementPropertyDescriptor elementPropertyDescriptor = propertyDescriptorToReplace as ElementPropertyDescriptor;
                            newDescriptor = new ElementPropertyDescriptor(Element, elementPropertyDescriptor.DomainPropertyInfo, newAttributes);
                        }
                        else
                        {
                            RolePlayerPropertyDescriptor rolePlayerPropertyDescriptor = propertyDescriptorToReplace as RolePlayerPropertyDescriptor;
                            newDescriptor = new RolePlayerPropertyDescriptor(Element, rolePlayerPropertyDescriptor.DomainRoleInfo, newAttributes);
                        }

                        propertyDescriptors.Remove(propertyDescriptorToReplace);
                        propertyDescriptors.Add(newDescriptor);
                    }
                }

                return(propertyDescriptors);
            }
コード例 #2
0
 private static PropertyDescriptor FindRolePlayerPropertyDescriptorInternal(PropertyDescriptorCollection propertyDescriptors, Type propertyType, string propertyName, Guid oppositeDomainRoleId)
 {
     foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors)
     {
         RolePlayerPropertyDescriptor rolePlayerPropertyDescriptor = propertyDescriptor as RolePlayerPropertyDescriptor;
         if ((rolePlayerPropertyDescriptor != null && rolePlayerPropertyDescriptor.DomainRoleInfo.Id == oppositeDomainRoleId) ||
             (propertyDescriptor.PropertyType == propertyType && propertyDescriptor.Name == propertyName))
         {
             return(propertyDescriptor);
         }
     }
     return(null);
 }
コード例 #3
0
        /// <summary>
        /// Replaces <see cref="ElementTypeDescriptor.GetProperties(Attribute[])"/>.
        /// </summary>
        /// <seealso cref="ElementTypeDescriptor.GetProperties(Attribute[])"/>
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection propertyDescriptors = new PropertyDescriptorCollection(null);
            TModelElement requestor = this.ModelElement;

            if (!requestor.IsDeleted && !requestor.IsDeleting)
            {
                // Get the property descriptors for our DomainProperties.
                foreach (DomainPropertyInfo domainPropertyInfo in requestor.GetDomainClass().AllDomainProperties)
                {
                    // Give derived types an opportunity to skip the current property.
                    if (!this.ShouldCreatePropertyDescriptor(requestor, domainPropertyInfo))
                    {
                        continue;
                    }
                    ElementPropertyDescriptor propertyDescriptor =
                        this.CreatePropertyDescriptor(requestor, domainPropertyInfo, this.GetDomainPropertyAttributes(domainPropertyInfo));
                    if (propertyDescriptor != null)
                    {
                        propertyDescriptors.Add(propertyDescriptor);
                    }
                }

                bool includeOppositeRolePlayerProperties    = this.IncludeOppositeRolePlayerProperties(requestor);
                bool includeEmbeddingRelationshipProperties = this.IncludeEmbeddingRelationshipProperties(requestor);

                // Get the property descriptors for the DomainRoles we play.
                if (includeOppositeRolePlayerProperties || includeEmbeddingRelationshipProperties)
                {
                    HashSet <string, string> oppositePropertyNames =
                        new HashSet <string, string>(KeyProvider <string, string> .Default, StringComparer.Ordinal, StringComparer.Ordinal);

                    foreach (DomainRoleInfo playedRole in requestor.GetDomainClass().AllDomainRolesPlayed)
                    {
                        // We only want to get property descriptors for DomainRoles when any derived types
                        // have opted in, and the current property has at most one value.
                        if (includeOppositeRolePlayerProperties && playedRole.IsOne)
                        {
                            string         playedRolePropertyName = playedRole.PropertyName;
                            DomainRoleInfo oppositeRole           = playedRole.OppositeDomainRole;

                            // Make sure that the opposite role player has a name (so that we have something to display),
                            // that we don't already have an opposite role player property with this name, and that any
                            // derived types approve of creating a property descriptor for this DomainRole.
                            if (oppositeRole.RolePlayer.NameDomainProperty != null &&
                                !oppositePropertyNames.Contains(playedRolePropertyName) &&
                                this.ShouldCreateRolePlayerPropertyDescriptor(requestor, playedRole))
                            {
                                RolePlayerPropertyDescriptor propertyDescriptor =
                                    this.CreateRolePlayerPropertyDescriptor(requestor, oppositeRole, this.GetRolePlayerPropertyAttributes(playedRole));
                                if (propertyDescriptor != null)
                                {
                                    propertyDescriptors.Add(propertyDescriptor);
                                    oppositePropertyNames.Add(playedRolePropertyName);
                                }
                            }
                        }

                        // If any derived types have opted in, and this relationship embeds us within another ModelElement,
                        // we'll include all of the properties from the instances of this relationship.
                        if (includeEmbeddingRelationshipProperties &&
                            playedRole.DomainRelationship.IsEmbedding &&
                            !playedRole.DomainRelationship.AllowsDuplicates &&
                            !playedRole.IsEmbedding)
                        {
                            // We exclude any ElementLinks attached to derived role players, since they'll be picked up separately.
                            foreach (ElementLink elementLink in playedRole.GetElementLinks <ElementLink>(requestor, true))
                            {
                                foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(elementLink))
                                {
                                    propertyDescriptors.Add(propertyDescriptor);
                                }
                            }
                        }
                    }
                }

                // Add any extension properties
                ((IFrameworkServices)requestor.Store).PropertyProviderService.GetProvidedProperties(requestor, propertyDescriptors);
            }
            return(propertyDescriptors);
        }