Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing datatypes to GetDefaultColumnDefinitionsForType #127

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading