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

Method optimize #580

Merged
merged 2 commits into from
Nov 15, 2024
Merged
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
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;
}
}
}
}
Loading