Exemplo n.º 1
0
        private static RenderFragment GetValue(CrudeProperty property, RenderContext context)
        {
            if (property.Type != CrudePropertyType.Field)
            {
                throw new ArgumentException($"This method can not be called for {property.Type} fragments");
            }

            string value;

            switch (property.GetValue())
            {
            case IFormattable formattable:
                value = formattable.ToString(null, context.Formatter);
                break;

            case string stringValue:
                value = stringValue.ToString(context.Formatter);
                break;

            default:
                value = RenderContext.EmptyPlaceholder;
                break;
            }

            var fragment = new ActionDecoratorFragment(value, property.OnClick);

            return(fragment.Render(context));
        }
Exemplo n.º 2
0
        private static FieldGroupFragment CreateFieldFragment(CrudeProperty property)
        {
            if (property.Type != CrudePropertyType.Field)
            {
                throw new ArgumentException($"This method can not be called for {property.Type} fragments");
            }

            return(new FieldGroupFragment(property));
        }
Exemplo n.º 3
0
        private static FieldFragment CreateGeneric(Type outerType, Type innerType, CrudeProperty property)
        {
            var type = outerType.MakeGenericType(innerType);

            var ctor = type
                       .GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)
                       .First();

            return((FieldFragment)ctor.Invoke(new object?[] { property }));
        }
Exemplo n.º 4
0
        private static IFragment?CreateTableFragment(CrudeProperty property)
        {
            if (property.Type != CrudePropertyType.Table)
            {
                throw new ArgumentException($"This method can not be called for {property.Type} fragments");
            }

            var viewModelType = property.Info.PropertyType.BaseType?.GetGenericArguments()[0];

            if (viewModelType == null)
            {
                throw new ArgumentException($"Could not resolve view model type for property {property.Name}");
            }

            var type = typeof(TableFragment <>).MakeGenericType(viewModelType);

            var fragment = Activator.CreateInstance(type, property.GetValue());

            return((IFragment?)fragment);
        }
Exemplo n.º 5
0
        private static FieldFragment Create(CrudeProperty property)
        {
            if (property.Type != CrudePropertyType.Field)
            {
                throw new ArgumentException($"This method can not be called for {property.Type} fragments");
            }

            var type = property.Info.PropertyType;

            var unwrappedType = type.UnwrapNullable();

            FieldFragment?fragment = null;

            if (IsNumeric(unwrappedType))
            {
                fragment = CreateGeneric(typeof(NumberFragment <>), type, property);
            }

            if (IsDate(unwrappedType))
            {
                fragment = CreateGeneric(typeof(DateFragment <>), type, property);
            }

            if (unwrappedType == typeof(bool))
            {
                fragment = new BooleanFragment(property);
            }

            if (unwrappedType == typeof(string))
            {
                fragment = new StringFragment(property);
            }

            if (unwrappedType.IsEnum)
            {
                fragment = new EnumFragment(property);
            }

            return(fragment ??= new NotRenderedFragment(property));
        }
Exemplo n.º 6
0
 internal BooleanFragment(CrudeProperty property) : base(property)
 {
 }
Exemplo n.º 7
0
 internal StringFragment(CrudeProperty property) : base(property)
 {
 }
Exemplo n.º 8
0
 internal NumberFragment(CrudeProperty property) : base(property)
 {
 }
Exemplo n.º 9
0
 internal NotRenderedFragment(CrudeProperty property) : base(property)
 {
 }
Exemplo n.º 10
0
 protected FieldFragment(CrudeProperty property)
 {
     Property   = property;
     Identifier = $"{Guid.NewGuid()}";
 }
Exemplo n.º 11
0
 internal EnumFragment(CrudeProperty property) : base(property)
 {
 }
Exemplo n.º 12
0
 public FieldGroupFragment(CrudeProperty property)
 {
     _property = property;
 }
Exemplo n.º 13
0
 internal DateFragment(CrudeProperty property) : base(property)
 {
 }