- Adding fields list to part, has/get/weld methods for ContentPart.

- ContentPartDefinition.Field.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-06-10 14:58:49 -07:00
parent 1b97fa04d0
commit 3aa7683e3a
2 changed files with 31 additions and 4 deletions

View File

@@ -3,11 +3,14 @@ using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Utilities;
namespace Orchard.ContentManagement {
public class ContentField : IContent {
public virtual ContentItem ContentItem { get; set;}
public class ContentField : ContentPart {
public virtual ContentPart ContentPart { get; set; }
public string Name { get; set; }
public ContentFieldDefinition Definition { get; set; }
public IDictionary<string, string> Settings { get; private set; }
public new ContentPartDefinition PartDefinition { get { return ContentPart.PartDefinition; } }
public ContentPartDefinition.Field PartFieldDefinition { get; set; }
public ContentFieldDefinition FieldDefinition { get { return PartFieldDefinition.FieldDefinition; } }
}
public class ContentField<TRecord> : ContentField {

View File

@@ -1,15 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Utilities;
namespace Orchard.ContentManagement {
public abstract class ContentPart : IContent {
private readonly IList<ContentField> _fields;
public ContentPart() {
_fields = new List<ContentField>();
}
public virtual ContentItem ContentItem { get; set; }
public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } }
public ContentTypeDefinition.Part TypePartDefinition { get; set; }
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }
public IEnumerable<ContentField> ContentFields { get; set; }
public IEnumerable<ContentField> Fields { get { return _fields; } }
public bool Has(Type fieldType) {
return fieldType == typeof(ContentItem) || _fields.Any(field => fieldType.IsAssignableFrom(field.GetType()));
}
public IContent Get(Type fieldType) {
if (fieldType == typeof(ContentItem))
return this;
return _fields.FirstOrDefault(field => fieldType.IsAssignableFrom(field.GetType()));
}
public void Weld(ContentField field) {
field.ContentPart = this;
_fields.Add(field);
}
}
public class ContentPart<TRecord> : ContentPart {