コード例 #1
0
        /// <summary>
        /// Adds a PropertyGroup.
        /// This method will also check if a group already exists with the same name and link it to the parent.
        /// </summary>
        /// <param name="groupName">Name of the PropertyGroup to add</param>
        /// <returns>Returns <c>True</c> if a PropertyGroup with the passed in name was added, otherwise <c>False</c></returns>
        public override bool AddPropertyGroup(string groupName)
        {
            if (PropertyGroups.Any(x => x.Name == groupName))
            {
                return(false);
            }

            var propertyGroup = new PropertyGroup {
                Name = groupName, SortOrder = 0
            };

            if (CompositionPropertyGroups.Any(x => x.Name == groupName))
            {
                var firstGroup = CompositionPropertyGroups.First(x => x.Name == groupName && x.ParentId.HasValue == false);
                propertyGroup.SetLazyParentId(new Lazy <int?>(() => firstGroup.Id));
            }

            if (PropertyGroups.Any())
            {
                var last = PropertyGroups.Last();
                propertyGroup.SortOrder = last.SortOrder + 1;
            }

            PropertyGroups.Add(propertyGroup);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Adds a PropertyType to a specific PropertyGroup
        /// </summary>
        /// <param name="propertyType"><see cref="PropertyType"/> to add</param>
        /// <param name="propertyGroupName">Name of the PropertyGroup to add the PropertyType to</param>
        /// <returns>Returns <c>True</c> if PropertyType was added, otherwise <c>False</c></returns>
        public override bool AddPropertyType(PropertyType propertyType, string propertyGroupName)
        {
            if (propertyType.HasIdentity == false)
            {
                propertyType.Key = Guid.NewGuid();
            }

            if (PropertyTypeExists(propertyType.Alias) == false)
            {
                if (PropertyGroups.Contains(propertyGroupName))
                {
                    propertyType.PropertyGroupId = new Lazy <int>(() => PropertyGroups[propertyGroupName].Id);
                    PropertyGroups[propertyGroupName].PropertyTypes.Add(propertyType);
                }
                else
                {
                    //If the PropertyGroup doesn't already exist we create a new one
                    var propertyTypes = new List <PropertyType> {
                        propertyType
                    };
                    var propertyGroup = new PropertyGroup(new PropertyTypeCollection(propertyTypes))
                    {
                        Name = propertyGroupName, SortOrder = 1
                    };
                    //and check if its an inherited PropertyGroup, which exists in the composition
                    if (CompositionPropertyGroups.Any(x => x.Name == propertyGroupName))
                    {
                        var parentPropertyGroup = CompositionPropertyGroups.First(x => x.Name == propertyGroupName && x.ParentId.HasValue == false);
                        propertyGroup.SortOrder = parentPropertyGroup.SortOrder;
                        //propertyGroup.ParentId = parentPropertyGroup.Id;
                        propertyGroup.SetLazyParentId(new Lazy <int?>(() => parentPropertyGroup.Id));
                    }

                    PropertyGroups.Add(propertyGroup);
                }

                return(true);
            }

            return(false);
        }