mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
- 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
43 lines
1.6 KiB
C#
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; } }
|
|
}
|
|
|
|
}
|