Add an option to not transform Activator.CreateInstance<T>() to new T()#3497
Add an option to not transform Activator.CreateInstance<T>() to new T()#3497siegfriedpammer merged 4 commits intoicsharpcode:masterfrom DoctorKrolic:no-new-T
Activator.CreateInstance<T>() to new T()#3497Conversation
|
I think that extra logic you found is used when dealing with |
Why not? If both collection initializer syntax and static T Test<T>()
where T : IList<int>, new()
{
return new T()
{
1, 2, 3
};
}After: static T Test<T>()
where T : IList<int>, new()
{
T t = Activator.CreateInstance<T>();
t.Add(1);
t.Add(2);
t.Add(3);
return t;
} |
|
I am not a fan of the setting name Copilot says:
System.Reflection.Metadata uses the term to refer to construction of generic type instances, see We should probably use something like
It's sufficient to add the check here: just like we already do for Then, if the setting is disabled, the initializer transform won't be applied in this specific case only. |
|
Upon reading the code referenced above again, I think this should be implemented by adding |
|
Thank you for your contribution! |
Closes #3495
This is my first contribution to this project, so to found places in code I needed I used full text search on the solution. Besides the place I changed there is also this piece:
ILSpy/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
Lines 3420 to 3426 in 0bfe222
I was never able to hit this code path when I debugged added test case. Does this logic also need to be changed and if so, what test should I add to cover it?