public void Does_resolve_properties() { AssertProp(InspectUtils.PropertyFromExpression <MultiTypes>(x => x.Id), typeof(int), nameof(MultiTypes.Id)); AssertProp(InspectUtils.PropertyFromExpression <MultiTypes>(x => x.Date), typeof(DateTime), nameof(MultiTypes.Date)); AssertProp(InspectUtils.PropertyFromExpression <MultiTypes>(x => x.NDate), typeof(DateTime?), nameof(MultiTypes.NDate)); AssertProp(InspectUtils.PropertyFromExpression <MultiTypes>(x => x.Bool), typeof(bool), nameof(MultiTypes.Bool)); AssertProp(InspectUtils.PropertyFromExpression <MultiTypes>(x => x.String), typeof(String), nameof(MultiTypes.String)); }
public void Does_resolve_property_names() { Assert.That(InspectUtils.GetFieldNames <MultiTypes>(x => x.Id), Is.EquivalentTo(new[] { nameof(MultiTypes.Id) })); Assert.That(InspectUtils.GetFieldNames <MultiTypes>(x => x.Date), Is.EquivalentTo(new[] { nameof(MultiTypes.Date) })); Assert.That(InspectUtils.GetFieldNames <MultiTypes>(x => x.NDate), Is.EquivalentTo(new[] { nameof(MultiTypes.NDate) })); Assert.That(InspectUtils.GetFieldNames <MultiTypes>(x => x.String), Is.EquivalentTo(new[] { nameof(MultiTypes.String) })); Assert.That(InspectUtils.GetFieldNames <MultiTypes>(x => new { x.String }), Is.EquivalentTo(new[] { nameof(MultiTypes.String) })); Assert.That(InspectUtils.GetFieldNames <MultiTypes>(x => new { x.Id, x.Date, x.NDate, x.String }), Is.EquivalentTo(new[] { nameof(MultiTypes.Id), nameof(MultiTypes.Date), nameof(MultiTypes.NDate), nameof(MultiTypes.String), })); }
public static InputInfo For <TModel>(Expression <Func <TModel, object?> > expr) { var pi = InspectUtils.PropertyFromExpression(expr) ?? throw new Exception($"Could not resolve property expression from {expr}"); var useType = Nullable.GetUnderlyingType(pi.PropertyType) ?? pi.PropertyType; if (useType.IsNumericType()) { return(new InputInfo(pi.Name, Types.Number)); } if (useType == typeof(bool)) { return(new InputInfo(pi.Name, Types.Checkbox)); } if (useType == typeof(DateTime) || useType == typeof(DateTimeOffset) || useType.Name == "DateOnly") { return(new InputInfo(pi.Name, Types.Date)); } if (useType == typeof(TimeSpan) || useType.Name == "TimeOnly") { return(new InputInfo(pi.Name, Types.Time)); } if (useType.IsEnum) { return(GetEnumEntries(useType, out var entries) ? new InputInfo(pi.Name, Types.Select) { AllowableEntries = entries } : new InputInfo(pi.Name, Types.Select) { AllowableValues = entries.Select(x => x.Value).ToArray() }); } return(new InputInfo(pi.Name)); }