예제 #1
0
        public dynamic Render(PropertyContext context, ContentItem contentItem, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field)
        {
            var p = contentItem.Parts.FirstOrDefault(x => x.PartDefinition.Name == part.Name);

            if (p == null)
            {
                return(String.Empty);
            }

            var f = p.Fields.FirstOrDefault(x => x.Name == field.Name);

            if (f == null)
            {
                return(String.Empty);
            }

            var value = f.Storage.Get <object>(storageName);

            if (value == null)
            {
                return(null);
            }

            // call specific formatter rendering
            return(_propertyFormater.Format(storageType, value, context.State));
        }
예제 #2
0
        public dynamic Render(PropertyContext context, PropertyInfo property, ContentItem contentItem)
        {
            // creating type for ContentPart<TRecord>, where TRecord is the type of the property
            var partRecordType = typeof(ContentPart <>).MakeGenericType(new [] { property.DeclaringType });

            // get the part for this ContentPart<TRecord>
            var part   = contentItem.Parts.FirstOrDefault(p => partRecordType.IsAssignableFrom(p.GetType()));
            var record = partRecordType.GetProperty("Record").GetValue(part, null);
            var value  = property.GetValue(record, null);

            if (value == null)
            {
                return(null);
            }

            // call specific formatter rendering
            return(_propertyFormater.Format(property.PropertyType, value, context.State));
        }