Skip to content

Commit

Permalink
Added missing datatypes to GetDefaultColumnDefinitionsForType
Browse files Browse the repository at this point in the history
  • Loading branch information
John GEFFERS committed Sep 13, 2023
1 parent 6c67c2c commit 5943bb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 9 additions & 2 deletions Castle.DynamicLinqQueryBuilder.Tests/Rules/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4187,11 +4187,18 @@ public class ColumnBuilderTestClass
{
public int Age { get; set; }
public int? FavoriteNumber { get; set; }
public long NumberOfShoes { get; set; }
public long? NumberOfSocks { get; set; }
public string Name { get; set; }
public DateTime Birthday { get; set; }
public DateTime? FavoriteBirthday { get; set; }
public double DollarsInWallet { get; set; }
public double? DesiredDollarsInWallet { get; set; }
public float DollarsInSavings { get; set; }
public float? DesiredDollarsInSavings { get; set; }
public decimal DollarsInRetirement { get; set; }
public decimal? DesiredDollarsInRetirement { get; set; }

#pragma warning disable IDE1006 // Naming Styles
public string camelCaseField { get; set; }
#pragma warning restore IDE1006 // Naming Styles
Expand All @@ -4207,11 +4214,11 @@ public void ColumnBuilderTest()
{
var result = typeof(ColumnBuilderTestClass).GetDefaultColumnDefinitionsForType();

Assert.IsTrue(result.Count == 10);
Assert.IsTrue(result.Count == 16);

result = typeof(ColumnBuilderTestClass).GetDefaultColumnDefinitionsForType(true);

Assert.IsTrue(result.Count == 10);
Assert.IsTrue(result.Count == 16);

}

Expand Down
11 changes: 7 additions & 4 deletions Castle.DynamicLinqQueryBuilder/ColumnBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ public static List<ColumnDefinition> GetDefaultColumnDefinitionsForType(this Typ
var id = 1;
foreach (var prop in dataType.GetProperties())
{
if (prop.GetCustomAttribute(typeof (IgnoreDataMemberAttribute)) != null) continue;
if (prop.GetCustomAttribute(typeof(IgnoreDataMemberAttribute)) != null) continue;

var name = camelCase ? prop.Name.ToCamelCase() : prop.Name;

var title = prop.Name.ToFriendlySpacedString();

var type = string.Empty;

if ((prop.PropertyType == typeof (double)) || (prop.PropertyType == typeof (double?)))
if ((prop.PropertyType == typeof(double)) || (prop.PropertyType == typeof(double?))
|| (prop.PropertyType == typeof(float)) || (prop.PropertyType == typeof(float?))
|| (prop.PropertyType == typeof(decimal)) || (prop.PropertyType == typeof(decimal?)))
{
type = "double";
}
else if ((prop.PropertyType == typeof (int)) || (prop.PropertyType == typeof (int?)))
else if ((prop.PropertyType == typeof(int)) || (prop.PropertyType == typeof(int?))
|| (prop.PropertyType == typeof(long)) || (prop.PropertyType == typeof(long?)))
{
type = "integer";
}
Expand Down Expand Up @@ -90,7 +93,7 @@ public static List<ColumnDefinition> GetDefaultColumnDefinitionsForType(this Typ
Type = type,
Id = id.ToString()
});
break;
break;
case "boolean":
itemBankColumnDefinitions.Add(new ColumnDefinition()
{
Expand Down

0 comments on commit 5943bb7

Please sign in to comment.