Пример #1
0
            private void InternalRemoveElementPropertyAttributes <TPropertyDescriptor>(ProcessPropertyType propertyType, Guid ownerDomainPropertyInfoId,
                                                                                       Func <TPropertyDescriptor, Attribute, bool> predicate)
                where TPropertyDescriptor : PropertyDescriptor
            {
                PropertyDescriptorItem propertyDescriptorItem = GetDescriptorItem(propertyType, ownerDomainPropertyInfoId);

                propertyDescriptorItem.Attributes.RemoveAll(
                    attribute =>
                    predicate(propertyDescriptorItem.PropertyDescriptorToReplace as TPropertyDescriptor, attribute));
            }
Пример #2
0
            private void InternalReplacePropertyAttribute <TAttribute, TPropertyDescriptor>(ProcessPropertyType propertyType, Guid ownerDomainPropertyInfoId,
                                                                                            Func <TPropertyDescriptor, TAttribute> instantiateAttribute)
                where TAttribute : Attribute
                where TPropertyDescriptor : PropertyDescriptor
            {
                PropertyDescriptorItem propertyDescriptorItem = GetDescriptorItem(propertyType, ownerDomainPropertyInfoId);
                Attribute newAttr = instantiateAttribute(propertyDescriptorItem.PropertyDescriptorToReplace as TPropertyDescriptor);

                if (newAttr == null)
                {
                    throw new ArgumentNullException("Cannot replace with null attribute!");
                }

                propertyDescriptorItem.Attributes.RemoveAll(attribute => attribute is TAttribute);
                propertyDescriptorItem.Attributes.Add(newAttr);
            }
Пример #3
0
            internal PropertyDescriptorItem Create(ProcessPropertyType propertyType, Guid forDomainPropertyInfoId)
            {
                PropertyDescriptorItem result = new PropertyDescriptorItem();

                PropertyDescriptor propertyDescriptorToReplace;

                if (propertyType == ProcessPropertyType.Element)
                {
                    var elementPropertyDescriptors = this.processingPropertyDescriptors[ProcessPropertyType.Element].Cast <ElementPropertyDescriptor>();
                    propertyDescriptorToReplace = elementPropertyDescriptors.SingleOrDefault(
                        item => item.DomainPropertyInfo.Id == forDomainPropertyInfoId);
                }
                else
                {
                    var playerPropertyDescriptors = this.processingPropertyDescriptors[ProcessPropertyType.RolePlayer].Cast <RolePlayerPropertyDescriptor>();
                    propertyDescriptorToReplace = playerPropertyDescriptors.SingleOrDefault(
                        item => item.DomainRoleInfo.Id == forDomainPropertyInfoId);
                }

                result.PropertyDescriptorToReplace = propertyDescriptorToReplace;

                if (result.PropertyDescriptorToReplace == null)
                {
                    throw new ArgumentOutOfRangeException(
                              string.Format("Could not find domain property with id '{0}' on element '{1}'",
                                            forDomainPropertyInfoId, this.Element.ToString()));
                }

                if (outerAttributes != null)
                {
                    result.Attributes.AddRange(outerAttributes);
                }

                if (result.PropertyDescriptorToReplace.Attributes != null)
                {
                    result.Attributes.AddRange(result.PropertyDescriptorToReplace.Attributes.OfType <Attribute>());
                }

                return(result);
            }