Is your feature request related to a problem? Please describe.
new() generic constraint was introduced in the same C# version as generics themselves (C# 2). Its implementation under the hood requres to call Activator.CreateInstance<T>() for what user writes as new T() in the source code. ILSpy always decompiles Activator.CreateInstance<T>() into new T() and there is no setting to disable that. Low-level C# viewers like sharplab, .NET Lab or Compiler developer SDK would benifit is there was an option to disable such transformation to be able to present as low-level C# decompilation view as possible
Describe the solution you'd like
New API like:
namespace ICSharpCode.Decompiler;
class DecompilerSettings
{
+ public bool GenericTypeInstantiation { get; set; }
}
The name is obviously not final here, maybe you can suggest something better. By default the setting is true for C# 2 and above, which represents current behavior, but can be set to false, in which case Activator.CreateInstance<T>() are not transformed to new T() even for a generic T with new() constraint
Additional context
The use case here seems very specific, but I believe implementation and maintaining this option is very straight-forward, this is probably a matter of 1 if somewhere in the codebase
Is your feature request related to a problem? Please describe.
new()generic constraint was introduced in the same C# version as generics themselves (C# 2). Its implementation under the hood requres to callActivator.CreateInstance<T>()for what user writes asnew T()in the source code. ILSpy always decompilesActivator.CreateInstance<T>()intonew T()and there is no setting to disable that. Low-level C# viewers like sharplab, .NET Lab or Compiler developer SDK would benifit is there was an option to disable such transformation to be able to present as low-level C# decompilation view as possibleDescribe the solution you'd like
New API like:
namespace ICSharpCode.Decompiler; class DecompilerSettings { + public bool GenericTypeInstantiation { get; set; } }The name is obviously not final here, maybe you can suggest something better. By default the setting is
truefor C# 2 and above, which represents current behavior, but can be set tofalse, in which caseActivator.CreateInstance<T>()are not transformed tonew T()even for a genericTwithnew()constraintAdditional context
The use case here seems very specific, but I believe implementation and maintaining this option is very straight-forward, this is probably a matter of 1
ifsomewhere in the codebase