-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Cleanup TypeConverter replacements #203
Conversation
@@ -64,11 +60,13 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul | |||
intType, | |||
intType, | |||
typeof(TimeSpan) | |||
}); | |||
|
|||
if (constructor == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is dead code. This API has existed basically forever and we'll always be able to get it right? https://apisof.net/catalog/System.DateTimeOffset..ctor(Int32,Int32,Int32,Int32,Int32,Int32,TimeSpan)
I say remove it but please confirm :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dipeshmsft what do you reckon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will take a look at this PR as well. I will ping you back once reviewed.
dfa9b3c
to
1acb2db
Compare
1acb2db
to
d7386ad
Compare
@dipeshmsft I will try to break this up to some more commits to provide more context :) |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@hughbe can you take a look at the build failure for this PR ? |
types[i] = (Type)typeTypeConverter.ConvertFrom(context, TypeConverterHelper.InvariantEnglishUS, tl[i]); | ||
} | ||
return types; | ||
throw new NullReferenceException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code may be controversial, why throw a null exception when the variable is not null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - basically this always used to throw NullReferenceException
, because StringHelpers.SplitTypeList
always returns null and then tl.Length
would throw NullReferenceException
.
Welcome comments here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @hughbe ,
We are considering merging this PR. I'd like to offer a suggestion: rather than removing the code and returning null
, we could set it up like this:
public static string[] SplitTypeList(string typeList) => Array.Empty<string>();
With this approach, StringHelpers.SplitTypeList
will return an empty string, allowing the code to proceed. This setup also leaves the door open for us to potentially utilize this feature in the future.
Thank you for your consideration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - have changed this to return Array.Empty()
|
||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) | ||
{ | ||
if (destinationType != null && value is DateTime) | ||
{ | ||
_dateTimeValueSerializer.ConvertToString( value as string, _valueSerializerContext ); | ||
_dateTimeValueSerializer.ConvertToString(value as string, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 this doesn't return the actual value?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hughbe My apologies for missing this while reviewing. It appears that this should return:
return _dateTimeValueSerializer.ConvertToString(value as string, null);
Regarding the build failure, we cannot define StringHelpers
as private.
If you would like, I can add a commit with the above changes, as they are very small.
{ | ||
return _dateTimeValueSerializer.ConvertFromString( value as string, _valueSerializerContext ); | ||
} | ||
=> _dateTimeValueSerializer.ConvertFromString(value as string, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since DateTimeValueSerializerContext
doesn't have any functionality, we can just pass null and remove the class here and in the other DateTimeConverter2
{ | ||
// Use the year, month, day, hour, minute, second, millisecond, offset constructor | ||
ConstructorInfo constructor = typeof(DateTimeOffset).GetConstructor(new Type[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor will always exist, remove null check
5e3f333
to
c11682f
Compare
2064e14
to
8b55ab8
Compare
Update DateTimeConverter2.cs
- Remove dead `if (constructor != null)` check - this ctor will always be there. - Cleanup code
- Code cleanup
8b55ab8
to
ced5cdd
Compare
Thanks @hughbe for your contribution. |
DateTimeValueSerializerContext
as it is a) unused in theDateTimeValueSerializer
base class and it has b) absolutely no functionality - passingnull
will suffice!DateTimeOffsetConverter2
in the right namespacexref with #200