Skip to content

Commit

Permalink
Method optimize (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhanbalaRashidov authored Nov 15, 2024
1 parent 7f4746f commit 830b9eb
Showing 1 changed file with 35 additions and 44 deletions.
79 changes: 35 additions & 44 deletions src/YesSql.Core/Data/DapperDataHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,77 +14,68 @@ class DateTimeOffsetHandler : DapperTypeHandler<DateTimeOffset>
{
public override DateTimeOffset Parse(object value)
{
if (value is null)
switch (value)
{
return DateTimeOffset.MinValue;
}
case null:
return DateTimeOffset.MinValue;

if (value is string s)
{
return DateTimeOffset.Parse(s);
}
case string s:
return DateTimeOffset.Parse(s);

if (value is DateTime dt)
{
return dt;
}
case DateTime dt:
return new DateTimeOffset(dt);

if (value is DateTimeOffset d)
{
return d;
}
case DateTimeOffset d:
return d;

return DateTimeOffset.MinValue;
default:
return DateTimeOffset.MinValue;
}
}
}

class GuidHandler : DapperTypeHandler<Guid>
{
public override Guid Parse(object value)
{
if (value is null)
switch (value)
{
return Guid.Empty;
}
case null:
return Guid.Empty;

if (value is string s)
{
return Guid.Parse(s);
}
else if (value is Guid g)
{
return g;
}
case string s:
return Guid.Parse(s);

case Guid g:
return g;

return Guid.Empty;
default:
return Guid.Empty;
}
}
}

class TimeSpanHandler : DapperTypeHandler<TimeSpan>
{
public override TimeSpan Parse(object value)
{
if (value is null)
switch (value)
{
return TimeSpan.Zero;
}
case null:
return TimeSpan.Zero;

if (value is string s)
{
return TimeSpan.Parse(s);
}
case string s:
return TimeSpan.Parse(s);

if (value is long l)
{
return new TimeSpan(l);
}
case long l:
return TimeSpan.FromTicks(l);

if (value is TimeSpan t)
{
return t;
}
case TimeSpan t:
return t;

return TimeSpan.Zero;
default:
return TimeSpan.Zero;
}
}
}
}

0 comments on commit 830b9eb

Please sign in to comment.