Skip to content

Commit 49368ca

Browse files
Rename option to "UseObjectCreationOfGenericTypeParameter"
1 parent 47eeacd commit 49368ca

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void ProcessInvocationExpression(InvocationExpression invocationExpression)
138138
break;
139139
*/
140140
case "System.Activator.CreateInstance":
141-
if (context.Settings.GenericTypeInstantiation &&
141+
if (context.Settings.UseObjectCreationOfGenericTypeParameter &&
142142
arguments.Length == 0 &&
143143
method.TypeArguments.Count == 1 &&
144144
IsInstantiableTypeParameter(method.TypeArguments[0]))

ICSharpCode.Decompiler/DecompilerSettings.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void SetLanguageVersion(CSharp.LanguageVersion languageVersion)
6363
liftNullables = false;
6464
yieldReturn = false;
6565
useImplicitMethodGroupConversion = false;
66-
genericTypeInstantiation = false;
66+
useObjectCreationOfGenericTypeParameter = false;
6767
}
6868
if (languageVersion < CSharp.LanguageVersion.CSharp3)
6969
{
@@ -211,7 +211,7 @@ public CSharp.LanguageVersion GetMinimumRequiredVersion()
211211
if (anonymousTypes || objectCollectionInitializers || automaticProperties
212212
|| queryExpressions || expressionTrees)
213213
return CSharp.LanguageVersion.CSharp3;
214-
if (anonymousMethods || liftNullables || yieldReturn || useImplicitMethodGroupConversion || genericTypeInstantiation)
214+
if (anonymousMethods || liftNullables || yieldReturn || useImplicitMethodGroupConversion || useObjectCreationOfGenericTypeParameter)
215215
return CSharp.LanguageVersion.CSharp2;
216216
return CSharp.LanguageVersion.CSharp1;
217217
}
@@ -987,21 +987,21 @@ public bool UseImplicitMethodGroupConversion {
987987
}
988988
}
989989

990-
bool genericTypeInstantiation = true;
990+
bool useObjectCreationOfGenericTypeParameter = true;
991991

992992
/// <summary>
993-
/// Gets/Sets whether to use generic type instantiation for generic types with <c>new()</c> constraint.
993+
/// Gets/Sets whether to use object creation expressions for generic types with <c>new()</c> constraint.
994994
/// true: <c>T t = new T();</c>
995995
/// false: <c>T t = Activator.CreateInstance&lt;T&gt;()</c>
996996
/// </summary>
997997
[Category("C# 2.0 / VS 2005")]
998-
[Description("DecompilerSettings.GenericTypeInstantiation")]
999-
public bool GenericTypeInstantiation {
1000-
get { return genericTypeInstantiation; }
998+
[Description("DecompilerSettings.UseObjectCreationOfGenericTypeParameter")]
999+
public bool UseObjectCreationOfGenericTypeParameter {
1000+
get { return useObjectCreationOfGenericTypeParameter; }
10011001
set {
1002-
if (genericTypeInstantiation != value)
1002+
if (useObjectCreationOfGenericTypeParameter != value)
10031003
{
1004-
genericTypeInstantiation = value;
1004+
useObjectCreationOfGenericTypeParameter = value;
10051005
OnPropertyChanged();
10061006
}
10071007
}

ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,10 @@ protected internal override void VisitIfInstruction(IfInstruction inst)
532532
inst.Condition.AcceptVisitor(this);
533533

534534
if (new NullableLiftingTransform(context).Run(inst))
535+
{
536+
context.Step("NullableLiftingTransform", inst);
535537
return;
538+
}
536539

537540
if (TransformDynamicAddAssignOrRemoveAssign(inst))
538541
return;

ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ void IStatementTransform.Run(Block block, int pos, StatementTransformContext con
7676
instType = defaultVal.Type;
7777
break;
7878
case Call c when c.Method.FullNameIs("System.Activator", "CreateInstance") && c.Method.TypeArguments.Count == 1:
79+
if (!context.Settings.UseObjectCreationOfGenericTypeParameter)
80+
{
81+
return;
82+
}
7983
instType = c.Method.TypeArguments[0];
8084
blockKind = BlockKind.ObjectInitializer;
8185
break;

0 commit comments

Comments
 (0)