本文整理汇总了C#中IContentType.MovePropertyType方法的典型用法代码示例。如果您正苦于以下问题:C# IContentType.MovePropertyType方法的具体用法?C# IContentType.MovePropertyType怎么用?C# IContentType.MovePropertyType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContentType
的用法示例。
在下文中一共展示了IContentType.MovePropertyType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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++;
}
}