Skip to content

Commit

Permalink
fix: Null bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
bugrakosen committed Oct 31, 2024
1 parent edef1b5 commit fb922c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public DateEqualToTests()
public void GetExpressionDateTimeValueTest(string propertyName, object value, bool useUtcConversionInDateTypes)
{
Settings.UseUtcConversionInDateTypes = useUtcConversionInDateTypes;
var dateValue = DateTime.Parse(value.ToString());
var startDate = Settings.UseUtcConversionInDateTypes ? dateValue.ToUniversalTime() : dateValue;
var endDate = startDate.AddDays(1).AddTicks(-1);
DateTime? dateValue = null;
var startDate = Settings.UseUtcConversionInDateTypes ? dateValue : dateValue;
var endDate = startDate.Value.AddDays(1).AddTicks(-1);
var operation = new DateEqualTo();
var param = Expression.Parameter(typeof(Person), "x");
var member = Expression.Property(param, propertyName);
Expand Down
2 changes: 1 addition & 1 deletion ExpressionBuilder/ExpressionBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</Description>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.0.15</Version>
<Version>1.0.16</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageId>Milvasoft.ExpressionBuilder</PackageId>
</PropertyGroup>
Expand Down
12 changes: 6 additions & 6 deletions ExpressionBuilder/Operations/DateEqualTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public DateEqualTo() : base(nameof(DateEqualTo), ValueCount, TypeGroup.Date) { }
/// <inheritdoc />
public override Expression GetExpression(MemberExpression member, ConstantExpression constant1, ConstantExpression constant2)
{
if (!IsDateType(constant1))
throw new InvalidDataException("DateEqualTo can be used with only date types");
if (!IsDateType(member))
throw new InvalidDataException("DateEqualTo can be used with only date types!");

if (constant1.Value == null)
return Expression.Equal(member, constant1);
Expand Down Expand Up @@ -81,8 +81,8 @@ private static (ConstantExpression, ConstantExpression) GetStartAndEndDates(Cons
return (startDateExpression, endDateExpression);
}

private static bool IsDateType(ConstantExpression constant) => constant.Type == typeof(DateTime)
|| constant.Type == typeof(DateTime?)
|| constant.Type == typeof(DateTimeOffset)
|| constant.Type == typeof(DateTimeOffset?);
private static bool IsDateType(MemberExpression member) => member.Type == typeof(DateTime)
|| member.Type == typeof(DateTime?)
|| member.Type == typeof(DateTimeOffset)
|| member.Type == typeof(DateTimeOffset?);
}

0 comments on commit fb922c8

Please sign in to comment.