Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMin Huang <huangmin@microsoft.com>2022-03-09 13:22:42 +0300
committerGitHub <noreply@github.com>2022-03-09 13:22:42 +0300
commit4cf39bde45ffdeddec87aad9edce7f2c0f78b9ee (patch)
treeaa41f601b5aadc83e716b7aacc34c6e384ab8ea3
parentc27c019e5a52d897dbb54e15bd645ef693e8bc57 (diff)
Support .NET language features: init only setter (#619)
-rw-r--r--mdoc/Consts.cs1
-rw-r--r--mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs9
-rw-r--r--mdoc/mdoc.Test/FormatterTests.cs11
-rw-r--r--mdoc/mdoc.Test/SampleClasses/InitOnlySetter.cs20
-rw-r--r--mdoc/mdoc.Test/SampleClasses/IsExternalInit.cs7
5 files changed, 47 insertions, 1 deletions
diff --git a/mdoc/Consts.cs b/mdoc/Consts.cs
index 4d2ef7c3..e047f2af 100644
--- a/mdoc/Consts.cs
+++ b/mdoc/Consts.cs
@@ -50,5 +50,6 @@ namespace Mono.Documentation
public const string IsReadOnlyAttribute = "System.Runtime.CompilerServices.IsReadOnlyAttribute";
public const string InAttribute = "System.Runtime.InteropServices.InAttribute";
public const string TupleElementNamesAttribute = "System.Runtime.CompilerServices.TupleElementNamesAttribute";
+ public const string IsExternalInit = "System.Runtime.CompilerServices.IsExternalInit";
}
}
diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs
index e885df57..3a36a5e7 100644
--- a/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs
+++ b/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs
@@ -725,7 +725,14 @@ namespace Mono.Documentation.Updater.Formatters
{
if (set_visible != visibility)
buf.Append (' ').Append (set_visible);
- buf.Append (" set;");
+ if (property.SetMethod.ReturnType is RequiredModifierType returnType && returnType.ModifierType.FullName == Consts.IsExternalInit)
+ {
+ buf.Append(" init;");
+ }
+ else
+ {
+ buf.Append(" set;");
+ }
}
buf.Append (" }");
diff --git a/mdoc/mdoc.Test/FormatterTests.cs b/mdoc/mdoc.Test/FormatterTests.cs
index 868def32..fd987dec 100644
--- a/mdoc/mdoc.Test/FormatterTests.cs
+++ b/mdoc/mdoc.Test/FormatterTests.cs
@@ -453,6 +453,17 @@ namespace mdoc.Test
Assert.AreEqual(expectedSignature, methodSignature);
}
+ [TestCase("Property1", "public int Property1 { get; set; }")]
+ [TestCase("Property2", "public int Property2 { get; init; }")]
+ [TestCase("Property3", "public int Property3 { get; protected init; }")]
+ [TestCase("Item", "public int this[int index] { get; init; }")]
+ public void CSharpInitOnlySetterTest(string propertyName, string expectedSignature)
+ {
+ var property = GetProperty(typeof(SampleClasses.InitOnlySetter), p => p.Name == propertyName);
+ var propertySignature = formatter.GetDeclaration(property);
+ Assert.AreEqual(expectedSignature, propertySignature);
+ }
+
#region Helper Methods
string RealTypeName(string name){
switch (name) {
diff --git a/mdoc/mdoc.Test/SampleClasses/InitOnlySetter.cs b/mdoc/mdoc.Test/SampleClasses/InitOnlySetter.cs
new file mode 100644
index 00000000..4ffc55c4
--- /dev/null
+++ b/mdoc/mdoc.Test/SampleClasses/InitOnlySetter.cs
@@ -0,0 +1,20 @@
+namespace mdoc.Test.SampleClasses
+{
+ public class InitOnlySetter
+ {
+ public int Property1 { get; set; }
+ public int Property2 { get; init; }
+ public int Property3 { get; protected init; }
+ public int this[int index]
+ {
+ get
+ {
+ throw null;
+ }
+ init
+ {
+ throw null;
+ }
+ }
+ }
+}
diff --git a/mdoc/mdoc.Test/SampleClasses/IsExternalInit.cs b/mdoc/mdoc.Test/SampleClasses/IsExternalInit.cs
new file mode 100644
index 00000000..48584312
--- /dev/null
+++ b/mdoc/mdoc.Test/SampleClasses/IsExternalInit.cs
@@ -0,0 +1,7 @@
+using System.ComponentModel;
+
+namespace System.Runtime.CompilerServices
+{
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal class IsExternalInit { }
+} \ No newline at end of file