Files
Orchard/src/Orchard/ContentManagement/ContentPart.cs
Suha Can a5833533f9 - Handler for content fields.
- Relies on the Activated event to weld fields to parts.
- New event Initializing added to the content management lifecycle, old Activated event is now Initializing.
- Unifying part and field template result classes.
- Refactoring.

--HG--
branch : dev
2010-06-14 13:12:41 -07:00

43 lines
1.6 KiB
C#

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> Fields { get { return _fields; } }
public bool Has(Type fieldType, string fieldName) {
return _fields.Any(field => fieldType.IsAssignableFrom(field.GetType()) && field.Name == fieldName);
}
public ContentField Get(Type fieldType, string fieldName) {
return _fields.FirstOrDefault(field => fieldType.IsAssignableFrom(field.GetType()) && field.Name == fieldName);
}
public void Weld(ContentField field) {
field.ContentPart = this;
_fields.Add(field);
}
}
public class ContentPart<TRecord> : ContentPart {
public readonly LazyField<TRecord> _record = new LazyField<TRecord>();
public TRecord Record { get { return _record.Value; } set { _record.Value = value; } }
}
}