当前位置: 首页>>代码示例>>C#>>正文


C# IContentType.AddPropertyGroup方法代码示例

本文整理汇总了C#中IContentType.AddPropertyGroup方法的典型用法代码示例。如果您正苦于以下问题:C# IContentType.AddPropertyGroup方法的具体用法?C# IContentType.AddPropertyGroup怎么用?C# IContentType.AddPropertyGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContentType的用法示例。


在下文中一共展示了IContentType.AddPropertyGroup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerifyProperties

        /// <summary>
        /// Loop through all properties and remove existing ones if necessary
        /// </summary>
        /// <param name="contentType"></param>
        /// <param name="type"></param>
        /// <param name="dataTypeService"></param>
        private static void VerifyProperties(IContentType contentType, Type type, IDataTypeService dataTypeService)
        {
            var properties = type.GetProperties().Where(x => x.GetCustomAttribute<UmbracoTabAttribute>() != null).ToArray();
            List<string> propertiesThatShouldExist = new List<string>();

            foreach (var propertyTab in properties)
            {
                var tabAttribute = propertyTab.GetCustomAttribute<UmbracoTabAttribute>();
                if (!contentType.PropertyGroups.Any(x => x.Name == tabAttribute.Name))
                {
                    contentType.AddPropertyGroup(tabAttribute.Name);
                }

                propertiesThatShouldExist.AddRange(VerifyAllPropertiesOnTab(propertyTab, contentType, tabAttribute.Name, dataTypeService));
            }

            var propertiesOfRoot = type.GetProperties().Where(x => x.GetCustomAttribute<UmbracoPropertyAttribute>() != null);
            foreach (var item in propertiesOfRoot)
            {
                //TODO: check for correct name
                propertiesThatShouldExist.Add(VerifyExistingProperty(contentType, null, dataTypeService, item, true));
            }

            //loop through all the properties on the ContentType to see if they should be removed;
            var existingUmbracoProperties = contentType.PropertyTypes.ToArray();
            int length = contentType.PropertyTypes.Count();
            for (int i = 0; i < length; i++)
            {
                if (!propertiesThatShouldExist.Contains(existingUmbracoProperties[i].Alias))
                {
                    //remove the property
                    contentType.RemovePropertyType(existingUmbracoProperties[i].Alias);
                }
            }
        }
开发者ID:JimBobSquarePants,项目名称:Umbraco-Inception,代码行数:41,代码来源:UmbracoCodeFirstInitializer.cs

示例2: UpdateContentTypesTabs

        private void UpdateContentTypesTabs(IContentType contentType, XElement tabElement)
        {
            if (tabElement == null)
                return;

            var tabs = tabElement.Elements("Tab");
            foreach (var tab in tabs)
            {
                var id = tab.Element("Id").Value;//Do we need to use this for tracking?
                var caption = tab.Element("Caption").Value;
                if (contentType.PropertyGroups.Contains(caption) == false)
                {
                    contentType.AddPropertyGroup(caption);
                }
            }
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:16,代码来源:PackagingService.cs

示例3: CreateTabs

        /// <summary>
        /// Scans for properties on the model which have the UmbracoTab attribute
        /// </summary>
        /// <param name="newContentType"></param>
        /// <param name="model"></param>
        /// <param name="dataTypeService"></param>
        private static void CreateTabs(IContentType newContentType, Type model, IDataTypeService dataTypeService)
        {
            var properties = model.GetProperties().Where(x => x.DeclaringType == model && x.GetCustomAttribute<UmbracoTabAttribute>() != null).ToArray();
            int length = properties.Length;

            for (int i = 0; i < length; i++)
            {
                var tabAttribute = properties[i].GetCustomAttribute<UmbracoTabAttribute>();

                newContentType.AddPropertyGroup(tabAttribute.Name);

                CreateProperties(properties[i], newContentType, tabAttribute.Name, dataTypeService);
            }
        }
开发者ID:JimBobSquarePants,项目名称:Umbraco-Inception,代码行数:20,代码来源:UmbracoCodeFirstInitializer.cs

示例4: SynchronizeContentTypeProperties

        //#region [Document type properties synchronization]
        /// <summary>
        /// Synchronizes content type properties
        /// </summary>
        /// <param name="typeContentType">ContentType type</param>
        /// <param name="contentType">Umbraco content type</param>
        /// <param name="hadDefaultValues">set to true if some of properties has default values</param>
        protected void SynchronizeContentTypeProperties(Type typeContentType, IContentType contentType, DocumentTypeAttribute documentTypeAttribute, out bool hadDefaultValues, bool updateMixins)
        {
            // sync the mixins first so that any properties are overwritten by the specific properties on the class
            if ((documentTypeAttribute.Mixins != null) && (updateMixins == false))
            {
                foreach (Type mixinType in documentTypeAttribute.Mixins)
                {
                    SynchronizeContentTypeProperties(mixinType, contentType, documentTypeAttribute, out hadDefaultValues, true);
                }
            }

            hadDefaultValues = false;

            int propertySortOrder = 0;
            foreach (PropertyInfo propInfo in typeContentType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                DocumentTypePropertyAttribute propAttr = Util.GetAttribute<DocumentTypePropertyAttribute>(propInfo);
                if (propAttr == null)
                {
                    continue; // skip this property - not part of a document type
                }

                // Getting name and alias
                string propertyName;
                string propertyAlias;
                DocumentTypeManager.ReadPropertyNameAndAlias(propInfo, propAttr, out propertyName, out propertyAlias);

                // Remove property if it has Obsolete attribute
                if (this.RemoveIfObsolete(contentType, propInfo, propertyAlias))
                {
                    continue;
                }

                if (propAttr.DefaultValue != null)
                {
                    hadDefaultValues = true; // at least one property has a default value
                }

                DataTypeDefinition dataTypeDefinition = GetDataTypeDefinition(typeContentType, propAttr, propInfo);

                // getting property if already exists, or creating new if it not exists
                Umbraco.Core.Models.PropertyType propertyType = contentType.PropertyTypes.FirstOrDefault(p => p.Alias == propertyAlias);
                if (propertyType == null) // if not exists, create it
                {
                    Util.AddPropertyType(contentType, dataTypeDefinition, propertyAlias, propertyName, propAttr.TabAsString);
                    propertyType = contentType.PropertyTypes.FirstOrDefault(p => p.Alias == propertyAlias);
                }
                else
                {
                    if (propertyType.DataTypeDefinitionId != dataTypeDefinition.Id)
                    {
                        propertyType.DataTypeDefinitionId = dataTypeDefinition.Id;
                    }
                }

                // Setting up the tab of this property. If tab doesn't exists, create it.
                if (!string.IsNullOrEmpty(propAttr.TabAsString) && propAttr.TabAsString.ToLower() != DocumentTypeDefaultValues.TabGenericProperties.ToLower())
                {
                    // try to find this tab
                    PropertyGroup pg = contentType.PropertyGroups.FirstOrDefault(x => x.Name == propAttr.TabAsString);
                    if (pg == null) // if found
                    {
                        contentType.AddPropertyGroup(propAttr.TabAsString);
                        pg = contentType.PropertyGroups.FirstOrDefault(x => x.Name == propAttr.TabAsString);
                    }

                    if (propAttr.TabOrder.HasValue)
                    {
                        pg.SortOrder = propAttr.TabOrder.Value;
                    }

                    if (!pg.PropertyTypes.Any(x => x.Alias == propertyType.Alias))
                    {
                        contentType.MovePropertyType(propertyType.Alias, propAttr.TabAsString);
                    }
                }
                else if ((propAttr.TabAsString == string.Empty) || (propAttr.TabAsString.ToLower() == "generic properties"))
                {
                    // In case when some property exists and needs to be moved to "Generic Properties" tab
                    contentType.MovePropertyType(propertyType.Alias, null);
                }

                propertyType.Name = propertyName;
                propertyType.Mandatory = propAttr.Mandatory;
                propertyType.ValidationRegExp = propAttr.ValidationRegExp;
                propertyType.Description = propAttr.Description;
                propertyType.SortOrder = propertySortOrder;

                propertySortOrder++;
            }
        }
开发者ID:Tronhus,项目名称:uSiteBuilder,代码行数:98,代码来源:ManagerBase.cs


注:本文中的IContentType.AddPropertyGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。