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)); }
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)); }
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 })); }
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); }
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)); }
internal BooleanFragment(CrudeProperty property) : base(property) { }
internal StringFragment(CrudeProperty property) : base(property) { }
internal NumberFragment(CrudeProperty property) : base(property) { }
internal NotRenderedFragment(CrudeProperty property) : base(property) { }
protected FieldFragment(CrudeProperty property) { Property = property; Identifier = $"{Guid.NewGuid()}"; }
internal EnumFragment(CrudeProperty property) : base(property) { }
public FieldGroupFragment(CrudeProperty property) { _property = property; }
internal DateFragment(CrudeProperty property) : base(property) { }