Example #1
0
        public IBlock Write(BlockWritingContext context)
        {
            var type     = context.Token.Accessor.OwnerType;
            var settings = context.Registry.SettingsFor(type);
            var name     = settings.Collection(type, context.Token.Value);

            var collectionName = context.Registry.NameFor(new BlockToken(name));

            IEnumerable <object> items = new object[0];

            var rawValue = context.RawValue as IEnumerable;

            if (rawValue != null)
            {
                items = rawValue.Cast <object>();
            }

            return(new CollectionBlock(collectionName)
            {
                Blocks = items
                         .Select(value =>
                {
                    context.StartObject(value);
                    var block = context.Writer.BlockFor(value, context, context.Token.Value);

                    context.FinishObject();

                    return block;
                })
                         .ToList()
            });
        }
Example #2
0
        public IBlock Write(BlockWritingContext context)
        {
            var name     = context.GetBlockName();
            var rawValue = context.RawValue;

            var value = context.Formatter.GetDisplayForValue(context.Accessor, rawValue);

            return(new PropertyBlock(name)
            {
                Value = value
            });
        }
Example #3
0
        public static BlockWritingContext ContextFor <T>(Expression <Func <T, object> > expression, object subject = null)
        {
            var property = ReflectionHelper.GetProperty(expression);

            var services = new InMemoryServiceLocator();

            services.Add <IDisplayFormatter>(new DisplayFormatter(services, new Stringifier()));

            var context = new BlockWritingContext(services, ObjectBlockWriter.Basic(), BlockRegistry.Basic(), subject);

            context.StartProperty(property);

            return(context);
        }
Example #4
0
 public bool Matches(BlockWritingContext context)
 {
     return(context.MatchesAccessor(x => x.PropertyType.IsSimple() || x.PropertyType == typeof(decimal)));
 }
Example #5
0
 public bool Matches(BlockWritingContext context)
 {
     return(context.MatchesAccessor(x => x.PropertyType.IsGenericEnumerable()));
 }
Example #6
0
 public IBlockWriter WriterFor(BlockWritingContext context)
 {
     return(AllWriters().FirstOrDefault(x => x.Matches(context)));
 }
Example #7
0
 public bool Matches(BlockWritingContext context)
 {
     return(context.MatchesAccessor(x => x.HasAttribute <ImplicitValueAttribute>()));
 }