Code cleanup in System.ComponentModel.TypeConverter#14154
Code cleanup in System.ComponentModel.TypeConverter#14154stephentoub merged 17 commits intodotnet:masterfrom
Conversation
|
Hi @bmeverett, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; |
|
@bmeverett, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
|
@bmeverett thanks for your contribution! I am going to take a closer look at this next week when I get back in the office! |
| // | ||
|
|
||
| Attribute[] attributes = null; | ||
| Attribute[] attributes = Array.Empty<Attribute>(); |
There was a problem hiding this comment.
Does this need to be assigned at all? It's set in both the subsequent if/else branch, so it should be definitely assigned without needing this initializer.
| _onListChanged -= value; | ||
| } | ||
| } | ||
| public event ListChangedEventHandler ListChanged; |
There was a problem hiding this comment.
This doesn't look like a safe change. The _onListChanged field was annotated as [NonSerialized], but the backing field generated for this event won't have such an attribute on it.
| _dataSource = null; | ||
| _dataMember = null; | ||
| DataSource = null; | ||
| DataMember = null; |
There was a problem hiding this comment.
Are these lines necessary at all? null is the default value.
| _dataSource = dataSource; | ||
| _dataMember = null; | ||
| DataSource = dataSource; | ||
| DataMember = null; |
There was a problem hiding this comment.
Is this line necessary? null is the default value.
| foreach (var val in GetStandardValues(context)) | ||
| { | ||
| CultureInfo info = (CultureInfo)e.Current; | ||
| CultureInfo info = (CultureInfo)val; |
There was a problem hiding this comment.
This can be changed to just:
foreach (CultureInfo info in GetStandardValues(context))| foreach (var val in _values) | ||
| { | ||
| CultureInfo info = (CultureInfo)e.Current; | ||
| CultureInfo info = (CultureInfo)val; |
| else | ||
| { | ||
| format = formatInfo.ShortDatePattern + " " + formatInfo.ShortTimePattern; | ||
| format = $"{formatInfo.ShortDatePattern} {formatInfo.ShortTimePattern}"; |
There was a problem hiding this comment.
This should be reverted. It's less expensive the way it was originally.
| get | ||
| { | ||
| // ComCtl32.dll V6 (WindowsXP) provides a nice black circle but we don't want to attempt to simulate it | ||
| // here to avoid hard coding values. MaskedTextBox picks up the right value at run time from comctl32. |
There was a problem hiding this comment.
Why was this comment deleted?
| _nameHash = _name.GetHashCode(); | ||
|
|
||
| ArrayList newArray = new ArrayList(); | ||
| List<Attribute> newArray = new List<Attribute>(); |
There was a problem hiding this comment.
Nit: extra space before the =
| } | ||
|
|
||
| return obj; | ||
| return obj ?? (obj = Activator.CreateInstance(objectType, args)); |
There was a problem hiding this comment.
Why does obj need to be assigned? e.g. why not just:
return obj ?? Activator.CreateInstance(objectType, args);?
| } | ||
|
|
||
| return instance; | ||
| return instance ?? (instance = NodeFor(objectType).CreateInstance(provider, objectType, argTypes, args)); |
There was a problem hiding this comment.
Why does instance need to be assigned?
stephentoub
left a comment
There was a problem hiding this comment.
Thanks. Overall the changes look good, but there are some issues that will need to be addressed.
|
@stephentoub Thanks for the feedback! Especially about string interpolation. I will keep that in mind. I will fix up your comments and make another commit. |
AlexGhiondea
left a comment
There was a problem hiding this comment.
Thanks for all this work @bmeverett!!!
Overall it looks great! I had a couple of minor comments that we should consider doing before taking this change.
Again -- thanks for doing this!!
| return typeof(Byte); | ||
| } | ||
| } | ||
| internal override Type TargetType => typeof(Byte); |
| { | ||
| return s_cultureInfoNameMap[cultureInfoDisplayName]; | ||
| } | ||
| private static readonly Dictionary<string, string> s_cultureInfoNameMap = CreateMap(); |
There was a problem hiding this comment.
Was the removal of volatile intentional?
There was a problem hiding this comment.
I used the example from the issue and you had it removed there. Should it be added back in?
There was a problem hiding this comment.
With this change, volatile isn't necessary anymore... it's almost the opposite of readonly, where readonly effectively says "this will never change so feel free to cache it as long as you like" and volatile kind of says "this can change at any moment and it's important you use the absolute latest".
| return typeof(Decimal); | ||
| } | ||
| } | ||
| internal override Type TargetType => typeof(Decimal); |
| public DefaultBindingPropertyAttribute() | ||
| { | ||
| _name = null; | ||
| Name = null; |
| return _name; | ||
| } | ||
| } | ||
| public string Name => _name; |
| return typeof(SByte); | ||
| } | ||
| } | ||
| internal override Type TargetType => typeof(SByte); |
| return typeof(Single); | ||
| } | ||
| } | ||
| internal override Type TargetType => typeof(Single); |
| return typeof(UInt16); | ||
| } | ||
| } | ||
| internal override Type TargetType => typeof(UInt16); |
| return typeof(UInt32); | ||
| } | ||
| } | ||
| internal override Type TargetType => typeof(UInt32); |
| return typeof(UInt64); | ||
| } | ||
| } | ||
| internal override Type TargetType => typeof(UInt64); |
safern
left a comment
There was a problem hiding this comment.
I left some comments.
Thanks for doing this!
| private class Site : ISite | ||
| { | ||
| private IComponent _component; | ||
| private Container _container; |
There was a problem hiding this comment.
Nit: Just such as you did it with _component we should delete _container and just use the property Container with it's default get.
| return _commandID; | ||
| } | ||
| } | ||
| public virtual int ID => _commandID; |
There was a problem hiding this comment.
Why are we here not using the same approach as in the other classes that you deleted the private fields and used the property only with a public get?
| return _oldDesigner; | ||
| } | ||
| } | ||
| public IDesignerHost OldDesigner => _oldDesigner; |
There was a problem hiding this comment.
Same here, can we remove _oldDesigner and _newDesigner?
| return invalidIndex; | ||
| } | ||
| } | ||
| public static int InvalidIndex => invalidIndex; |
There was a problem hiding this comment.
Should we update all constants from this class to be uppercase? e.g invalidIndex to INVALID_INDEX ?
| return _container; | ||
| } | ||
| } | ||
| public IContainer Container => _container; |
There was a problem hiding this comment.
Can we delete _container and just use Container ?
| @@ -69,49 +67,27 @@ public ToolboxItemFilterAttribute(string filterString, ToolboxItemFilterType fil | |||
| { | |||
| if (filterString == null) filterString = String.Empty; | |||
There was a problem hiding this comment.
Instead of doing
if (filterString == null) filterString = String.Emptywe could simplify this to one line when initializing FilterString :
FilterString = filterString ?? string.Empty;| } | ||
| else | ||
| { | ||
| return site.Name; |
There was a problem hiding this comment.
We could simplify this to:
return nestedSite != null ? nestedSite.FullName : site.Name;Or I think we could use ?? operator as well:
return (nestedSite?.FullName) ?? site.Name;converted remaining properties to auto properties
|
I think the tests may have gotten stuck. Not sure if it was something I did. |
|
The details of Innerloop CentOS7.1 are not found on the link provided. |
|
@safern I beleive this is because the lab is being moved. Please ignore. |
|
Ok then I'm going to go ahead and restart both tests with failures. test Innerloop CentOS7.1 Debug Build and Test please |
safern
left a comment
There was a problem hiding this comment.
Looks good to me! Thanks for doing this.
|
@dotnet-bot test this please |
|
Thanks guys! |
* remove explicit base calls * auto implemented properties * use expression body members * use ? for null checking * use string interpolation * remove unnecessary initialization * replace empty arrays with array.empty * simplify event handler declarations * readonly modifier for sync objects * use foreach * cache char[] into static readonly field * simplify CultureInfoMapper * reaplce non generic collections with generic collections * fix code review comments a lot dealing with string interpolation. * add space to datetimeconverter and datetimeoffsetconverter to fix tests * additional modifications converting types * uppercase constants in MaskedTextProvider converted remaining properties to auto properties
) * remove explicit base calls * auto implemented properties * use expression body members * use ? for null checking * use string interpolation * remove unnecessary initialization * replace empty arrays with array.empty * simplify event handler declarations * readonly modifier for sync objects * use foreach * cache char[] into static readonly field * simplify CultureInfoMapper * reaplce non generic collections with generic collections * fix code review comments a lot dealing with string interpolation. * add space to datetimeconverter and datetimeoffsetconverter to fix tests * additional modifications converting types * uppercase constants in MaskedTextProvider converted remaining properties to auto properties Commit migrated from dotnet/corefx@6f48f19
Commit migrated from dotnet/corefx@9c18f4b
Resolves #12160 to clean up code in System.ComponentModel.TypeConverter
cc @AlexGhiondea
I created an individual commit for each improvement, didn't know if that would make review any easier. I tried to search the project and make sure everything was accounted for. This is a decent size project so something may have been missed. Feel free to comment and I'll be glad to fix it.