Browse Source

Add support for static local function

pull/1797/head
SilverFox 6 years ago
parent
commit
6409fe945c
  1. 3
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  2. 20
      ICSharpCode.Decompiler/DecompilerSettings.cs
  3. 9
      ILSpy/Properties/Resources.Designer.cs
  4. 3
      ILSpy/Properties/Resources.resx

3
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -1001,6 +1001,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1001,6 +1001,9 @@ namespace ICSharpCode.Decompiler.CSharp
if (function.IsAsync) {
stmt.Modifiers |= Modifiers.Async;
}
if (settings.StaticLocalFunctions && function.Method.IsStatic && function.ReducedMethod.NumberOfCompilerGeneratedParameters == 0) {
stmt.Modifiers |= Modifiers.Static;
}
stmt.AddAnnotation(new MemberResolveResult(null, function.ReducedMethod));
return stmt;
}

20
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -110,12 +110,13 @@ namespace ICSharpCode.Decompiler @@ -110,12 +110,13 @@ namespace ICSharpCode.Decompiler
readOnlyMethods = false;
asyncUsingAndForEachStatement = false;
asyncEnumerator = false;
staticLocalFunctions = false;
}
}
public CSharp.LanguageVersion GetMinimumRequiredVersion()
{
if (nullableReferenceTypes || readOnlyMethods || asyncEnumerator || asyncUsingAndForEachStatement)
if (nullableReferenceTypes || readOnlyMethods || asyncEnumerator || asyncUsingAndForEachStatement || staticLocalFunctions)
return CSharp.LanguageVersion.CSharp8_0;
if (introduceUnmanagedConstraint || tupleComparisons || stackAllocInitializers)
return CSharp.LanguageVersion.CSharp7_3;
@ -1064,6 +1065,23 @@ namespace ICSharpCode.Decompiler @@ -1064,6 +1065,23 @@ namespace ICSharpCode.Decompiler
}
}
bool staticLocalFunctions = true;
/// <summary>
/// Gets/Sets whether C# 8.0 static local functions should be transformed.
/// </summary>
[Category("C# 8.0 / VS 2019")]
[Description("DecompilerSettings.IntroduceStaticLocalFunctions")]
public bool StaticLocalFunctions {
get { return staticLocalFunctions; }
set {
if (staticLocalFunctions != value) {
staticLocalFunctions = value;
OnPropertyChanged();
}
}
}
bool nullableReferenceTypes = true;
/// <summary>

9
ILSpy/Properties/Resources.Designer.cs generated

@ -772,6 +772,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -772,6 +772,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Introduce static local functions.
/// </summary>
public static string DecompilerSettings_IntroduceStaticLocalFunctions {
get {
return ResourceManager.GetString("DecompilerSettings.IntroduceStaticLocalFunctions", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to IsByRefLikeAttribute should be replaced with &apos;ref&apos; modifiers on structs.
/// </summary>

3
ILSpy/Properties/Resources.resx

@ -775,4 +775,7 @@ Are you sure you want to continue?</value> @@ -775,4 +775,7 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.DetectAsyncUsingAndForeachStatements" xml:space="preserve">
<value>Detect awaited using and foreach statements</value>
</data>
<data name="DecompilerSettings.IntroduceStaticLocalFunctions" xml:space="preserve">
<value>Introduce static local functions</value>
</data>
</root>
Loading…
Cancel
Save