protected bool Equals(ContentTypeSort other) { return(Id.Value.Equals(other.Id.Value) && string.Equals(Alias, other.Alias)); }
/// <summary> /// Gets the allowed children /// </summary> /// <param name="types"></param> /// <param name="contentTypeService"></param> /// <returns></returns> private static IEnumerable<ContentTypeSort> FetchAllowedContentTypes(Type[] types, IContentTypeService contentTypeService) { if (types == null) return new ContentTypeSort[0]; List<ContentTypeSort> contentTypeSorts = new List<ContentTypeSort>(); List<string> aliases = GetAliasesFromTypes(types); var contentTypes = contentTypeService.GetAllContentTypes().Where(x => aliases.Contains(x.Alias)).ToArray(); int length = contentTypes.Length; for (int i = 0; i < length; i++) { ContentTypeSort sort = new ContentTypeSort(); sort.Alias = contentTypes[i].Alias; int id = contentTypes[i].Id; sort.Id = new Lazy<int>(() => { return id; }); sort.SortOrder = i; contentTypeSorts.Add(sort); } return contentTypeSorts; }
/// <summary> /// Convention to resolve referenced child content types /// </summary> /// <param name="types"></param> /// <param name="currentType"> </param> /// <returns></returns> private static IEnumerable<ContentTypeSort> AllowedChildContentTypesConvention(IEnumerable<Type> types, Type currentType) { var contentTypeSorts = new List<ContentTypeSort>(); int order = 0; foreach (var type in types) { if(type == currentType) continue;//If the referenced type is equal to the current type we skip it to avoid a circular dependency var contentTypeSort = new ContentTypeSort(); var isResolved = _contentTypeCache.ContainsKey(type.FullName); var lazy = isResolved ? _contentTypeCache[type.FullName].ContentType : GetContentTypeDefinition(type); contentTypeSort.Id = new Lazy<int>(() => lazy.Value.Id); contentTypeSort.Alias = lazy.Value.Alias; contentTypeSort.SortOrder = order; contentTypeSorts.Add(contentTypeSort); order++; } return contentTypeSorts; }