Example #1
0
 internal override void RenderField(Field field, PropertyInfo property, object host, PaperContext ctx)
 {
     field.AddAllowMany(Allow);
 }
Example #2
0
        private static Field CreateField(object graph, string key, PaperContext ctx)
        {
            var field    = new Field();
            var property = graph._GetPropertyInfo(key);

            //
            // Propriedades padrĂ£o
            //
            field.Name     = Conventions.MakeName(property);
            field.Title    = Conventions.MakeTitle(property);
            field.DataType = Conventions.MakeDataType(property);

            var isReadOnly = !property.CanWrite;

            if (isReadOnly)
            {
                field.AddReadOnly();
            }
            else
            {
                var isPrimitive =
                    property.PropertyType.IsValueType &&
                    (Nullable.GetUnderlyingType(property.PropertyType) == null);
                if (isPrimitive)
                {
                    field.AddRequired();
                }

                var isVar = typeof(Var).IsAssignableFrom(property.PropertyType);
                if (isVar)
                {
                    field.AddAllowMany();
                    field.AddAllowRange();
                }

                var isList = typeof(IList).IsAssignableFrom(property.PropertyType);
                if (isList)
                {
                    field.AddAllowMany();
                }
            }

            //
            // Propriedades personalizadas
            //
            var attributes = property._GetAttributes <FieldAttribute>();

            foreach (var attribute in attributes)
            {
                attribute.RenderField(field, property, graph, ctx);
            }

            //
            // Propriedades obrigatorias
            //
            field.Value = graph._Get(key);

            if (field.Name.StartsWith("_"))
            {
                field.AddHidden();
            }

            return(field);
        }