Smdn.Reflection.ReverseGenerating version 1.1.2
·
375 commits
to main
since this release
Released package
Release notes
The full release notes are available at gist.
Change log
Change log in this release:
- 2022-07-19 update assembly version
- 2022-07-19 bump Smdn.Fundamental.Reflection up to 3.3.1
- 2022-07-19 add GeneratorOptions.MemberDeclaration.WithEnumTypeName and refer it instead of WithDeclaringTypeName if member's declaring type is enum
- 2022-07-19 add support for formatting ref properties
- 2022-07-19 add support for formatting parameter type of by-ref pointers
- 2022-07-17 make the workaround for nullability of by-ref types configurable with DefineConstants
- 2022-07-17 add workaround for by-ref parameter types
- 2022-07-16 refactor
- 2022-07-16 add support for formatting Nullable<GenericValueType<...>> with nullability annotations
- 2022-07-14 bump Smdn.MSBuild.DefineConstants.NETSdkApi up to 1.3.4
API changes
API changes in this release:
diff --git a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net45.apilist.cs b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net45.apilist.cs
index 071d776..7044626 100644
--- a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net45.apilist.cs
+++ b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net45.apilist.cs
@@ -1,122 +1,123 @@
-// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.1)
+// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.2)
// Name: Smdn.Reflection.ReverseGenerating
-// AssemblyVersion: 1.1.1.0
-// InformationalVersion: 1.1.1+9c1ed7379f1b7fe2562a51f0283b02332d84584f
+// AssemblyVersion: 1.1.2.0
+// InformationalVersion: 1.1.2+775287448dc58ab1c9fb7f0618d8c8bb6de9e775
// TargetFramework: .NETFramework,Version=v4.5
// Configuration: Release
#nullable enable annotations
using System;
using System.Collections.Generic;
using System.Reflection;
using Smdn.Reflection;
using Smdn.Reflection.ReverseGenerating;
namespace Smdn.Reflection.ReverseGenerating {
public delegate bool AttributeTypeFilter(Type type, ICustomAttributeProvider attributeProvider);
public enum AttributeSectionFormat : int {
Discrete = 1,
List = 0,
}
public enum MethodBodyOption : int {
EmptyImplementation = 1,
None = 0,
ThrowNotImplementedException = 2,
ThrowNull = 3,
}
public static class CSharpFormatter {
public static string EscapeString(string s, bool escapeSingleQuote = false, bool escapeDoubleQuote = false) {}
public static string FormatAccessibility(Accessibility accessibility) {}
public static string FormatParameter(ParameterInfo p, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(MethodBase m, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(ParameterInfo[] parameterList, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatSpecialNameMethod(MethodBase methodOrConstructor, out MethodSpecialName nameType) {}
public static string FormatTypeName(this EventInfo ev, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this FieldInfo f, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this ParameterInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this PropertyInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this Type t, ICustomAttributeProvider? attributeProvider = null, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatValueDeclaration(object? val, Type typeOfValue, bool typeWithNamespace = true, bool findConstantField = false, bool useDefaultLiteral = false) {}
public static bool IsLanguagePrimitiveType(Type t, out string primitiveTypeName) {}
public static IEnumerable<string> ToNamespaceList(Type t) {}
}
public static class Generator {
public static IEnumerable<string> GenerateAttributeList(ICustomAttributeProvider attributeProvider, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateGenericArgumentConstraintDeclaration(Type genericArgument, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string? GenerateMemberDeclaration(MemberInfo member, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateTypeDeclaration(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateTypeDeclarationWithExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
}
public class GeneratorOptions : ICloneable {
public class AttributeDeclarationOptions {
public AttributeDeclarationOptions() {}
public AttributeSectionFormat AccessorFormat { get; set; }
public AttributeSectionFormat AccessorParameterFormat { get; set; }
public AttributeSectionFormat BackingFieldFormat { get; set; }
public AttributeSectionFormat DelegateParameterFormat { get; set; }
public AttributeSectionFormat GenericParameterFormat { get; set; }
public AttributeSectionFormat MethodParameterFormat { get; set; }
public bool OmitAttributeSuffix { get; set; }
public AttributeTypeFilter? TypeFilter { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamedArguments { get; set; }
public bool WithNamespace { get; set; }
}
public class MemberDeclarationOptions {
public MemberDeclarationOptions() {}
public MethodBodyOption AccessorBody { get; set; }
public MethodBodyOption MethodBody { get; set; }
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
+ public bool WithEnumTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ParameterDeclarationOptions {
public ParameterDeclarationOptions() {}
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class TypeDeclarationOptions {
public TypeDeclarationOptions() {}
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ValueDeclarationOptions {
public ValueDeclarationOptions() {}
public bool UseDefaultLiteral { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public GeneratorOptions() {}
public GeneratorOptions.AttributeDeclarationOptions AttributeDeclaration { get; init; }
public bool IgnorePrivateOrAssembly { get; set; }
public string? Indent { get; set; }
public GeneratorOptions.MemberDeclarationOptions MemberDeclaration { get; init; }
public GeneratorOptions.ParameterDeclarationOptions ParameterDeclaration { get; init; }
public bool TranslateLanguagePrimitiveTypeDeclaration { get; set; }
public GeneratorOptions.TypeDeclarationOptions TypeDeclaration { get; init; }
public GeneratorOptions.ValueDeclarationOptions ValueDeclaration { get; init; }
public virtual GeneratorOptions Clone() {}
object ICloneable.Clone() {}
}
}
diff --git a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net47.apilist.cs b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net47.apilist.cs
index d725878..c5584e3 100644
--- a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net47.apilist.cs
+++ b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net47.apilist.cs
@@ -1,122 +1,123 @@
-// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.1)
+// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.2)
// Name: Smdn.Reflection.ReverseGenerating
-// AssemblyVersion: 1.1.1.0
-// InformationalVersion: 1.1.1+9c1ed7379f1b7fe2562a51f0283b02332d84584f
+// AssemblyVersion: 1.1.2.0
+// InformationalVersion: 1.1.2+775287448dc58ab1c9fb7f0618d8c8bb6de9e775
// TargetFramework: .NETFramework,Version=v4.7
// Configuration: Release
#nullable enable annotations
using System;
using System.Collections.Generic;
using System.Reflection;
using Smdn.Reflection;
using Smdn.Reflection.ReverseGenerating;
namespace Smdn.Reflection.ReverseGenerating {
public delegate bool AttributeTypeFilter(Type type, ICustomAttributeProvider attributeProvider);
public enum AttributeSectionFormat : int {
Discrete = 1,
List = 0,
}
public enum MethodBodyOption : int {
EmptyImplementation = 1,
None = 0,
ThrowNotImplementedException = 2,
ThrowNull = 3,
}
public static class CSharpFormatter {
public static string EscapeString(string s, bool escapeSingleQuote = false, bool escapeDoubleQuote = false) {}
public static string FormatAccessibility(Accessibility accessibility) {}
public static string FormatParameter(ParameterInfo p, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(MethodBase m, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(ParameterInfo[] parameterList, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatSpecialNameMethod(MethodBase methodOrConstructor, out MethodSpecialName nameType) {}
public static string FormatTypeName(this EventInfo ev, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this FieldInfo f, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this ParameterInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this PropertyInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this Type t, ICustomAttributeProvider? attributeProvider = null, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatValueDeclaration(object? val, Type typeOfValue, bool typeWithNamespace = true, bool findConstantField = false, bool useDefaultLiteral = false) {}
public static bool IsLanguagePrimitiveType(Type t, out string primitiveTypeName) {}
public static IEnumerable<string> ToNamespaceList(Type t) {}
}
public static class Generator {
public static IEnumerable<string> GenerateAttributeList(ICustomAttributeProvider attributeProvider, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateGenericArgumentConstraintDeclaration(Type genericArgument, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string? GenerateMemberDeclaration(MemberInfo member, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateTypeDeclaration(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateTypeDeclarationWithExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
}
public class GeneratorOptions : ICloneable {
public class AttributeDeclarationOptions {
public AttributeDeclarationOptions() {}
public AttributeSectionFormat AccessorFormat { get; set; }
public AttributeSectionFormat AccessorParameterFormat { get; set; }
public AttributeSectionFormat BackingFieldFormat { get; set; }
public AttributeSectionFormat DelegateParameterFormat { get; set; }
public AttributeSectionFormat GenericParameterFormat { get; set; }
public AttributeSectionFormat MethodParameterFormat { get; set; }
public bool OmitAttributeSuffix { get; set; }
public AttributeTypeFilter? TypeFilter { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamedArguments { get; set; }
public bool WithNamespace { get; set; }
}
public class MemberDeclarationOptions {
public MemberDeclarationOptions() {}
public MethodBodyOption AccessorBody { get; set; }
public MethodBodyOption MethodBody { get; set; }
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
+ public bool WithEnumTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ParameterDeclarationOptions {
public ParameterDeclarationOptions() {}
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class TypeDeclarationOptions {
public TypeDeclarationOptions() {}
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ValueDeclarationOptions {
public ValueDeclarationOptions() {}
public bool UseDefaultLiteral { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public GeneratorOptions() {}
public GeneratorOptions.AttributeDeclarationOptions AttributeDeclaration { get; init; }
public bool IgnorePrivateOrAssembly { get; set; }
public string? Indent { get; set; }
public GeneratorOptions.MemberDeclarationOptions MemberDeclaration { get; init; }
public GeneratorOptions.ParameterDeclarationOptions ParameterDeclaration { get; init; }
public bool TranslateLanguagePrimitiveTypeDeclaration { get; set; }
public GeneratorOptions.TypeDeclarationOptions TypeDeclaration { get; init; }
public GeneratorOptions.ValueDeclarationOptions ValueDeclaration { get; init; }
public virtual GeneratorOptions Clone() {}
object ICloneable.Clone() {}
}
}
diff --git a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net5.0.apilist.cs b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net5.0.apilist.cs
index ac492dd..ff6378a 100644
--- a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net5.0.apilist.cs
+++ b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net5.0.apilist.cs
@@ -1,123 +1,124 @@
-// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.1)
+// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.2)
// Name: Smdn.Reflection.ReverseGenerating
-// AssemblyVersion: 1.1.1.0
-// InformationalVersion: 1.1.1+9c1ed7379f1b7fe2562a51f0283b02332d84584f
+// AssemblyVersion: 1.1.2.0
+// InformationalVersion: 1.1.2+775287448dc58ab1c9fb7f0618d8c8bb6de9e775
// TargetFramework: .NETCoreApp,Version=v5.0
// Configuration: Release
#nullable enable annotations
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Smdn.Reflection;
using Smdn.Reflection.ReverseGenerating;
namespace Smdn.Reflection.ReverseGenerating {
public delegate bool AttributeTypeFilter(Type type, ICustomAttributeProvider attributeProvider);
public enum AttributeSectionFormat : int {
Discrete = 1,
List = 0,
}
public enum MethodBodyOption : int {
EmptyImplementation = 1,
None = 0,
ThrowNotImplementedException = 2,
ThrowNull = 3,
}
public static class CSharpFormatter {
public static string EscapeString(string s, bool escapeSingleQuote = false, bool escapeDoubleQuote = false) {}
public static string FormatAccessibility(Accessibility accessibility) {}
public static string FormatParameter(ParameterInfo p, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(MethodBase m, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(ParameterInfo[] parameterList, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatSpecialNameMethod(MethodBase methodOrConstructor, out MethodSpecialName nameType) {}
public static string FormatTypeName(this EventInfo ev, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this FieldInfo f, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this ParameterInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this PropertyInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this Type t, ICustomAttributeProvider? attributeProvider = null, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatValueDeclaration(object? val, Type typeOfValue, bool typeWithNamespace = true, bool findConstantField = false, bool useDefaultLiteral = false) {}
public static bool IsLanguagePrimitiveType(Type t, [MaybeNullWhen(false)] out string? primitiveTypeName) {}
public static IEnumerable<string> ToNamespaceList(Type t) {}
}
public static class Generator {
public static IEnumerable<string> GenerateAttributeList(ICustomAttributeProvider attributeProvider, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateGenericArgumentConstraintDeclaration(Type genericArgument, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string? GenerateMemberDeclaration(MemberInfo member, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateTypeDeclaration(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateTypeDeclarationWithExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
}
public class GeneratorOptions : ICloneable {
public class AttributeDeclarationOptions {
public AttributeDeclarationOptions() {}
public AttributeSectionFormat AccessorFormat { get; set; }
public AttributeSectionFormat AccessorParameterFormat { get; set; }
public AttributeSectionFormat BackingFieldFormat { get; set; }
public AttributeSectionFormat DelegateParameterFormat { get; set; }
public AttributeSectionFormat GenericParameterFormat { get; set; }
public AttributeSectionFormat MethodParameterFormat { get; set; }
public bool OmitAttributeSuffix { get; set; }
public AttributeTypeFilter? TypeFilter { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamedArguments { get; set; }
public bool WithNamespace { get; set; }
}
public class MemberDeclarationOptions {
public MemberDeclarationOptions() {}
public MethodBodyOption AccessorBody { get; set; }
public MethodBodyOption MethodBody { get; set; }
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
+ public bool WithEnumTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ParameterDeclarationOptions {
public ParameterDeclarationOptions() {}
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class TypeDeclarationOptions {
public TypeDeclarationOptions() {}
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ValueDeclarationOptions {
public ValueDeclarationOptions() {}
public bool UseDefaultLiteral { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public GeneratorOptions() {}
public GeneratorOptions.AttributeDeclarationOptions AttributeDeclaration { get; init; }
public bool IgnorePrivateOrAssembly { get; set; }
public string? Indent { get; set; }
public GeneratorOptions.MemberDeclarationOptions MemberDeclaration { get; init; }
public GeneratorOptions.ParameterDeclarationOptions ParameterDeclaration { get; init; }
public bool TranslateLanguagePrimitiveTypeDeclaration { get; set; }
public GeneratorOptions.TypeDeclarationOptions TypeDeclaration { get; init; }
public GeneratorOptions.ValueDeclarationOptions ValueDeclaration { get; init; }
public virtual GeneratorOptions Clone() {}
object ICloneable.Clone() {}
}
}
diff --git a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net6.0.apilist.cs b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net6.0.apilist.cs
index 170a63a..236901d 100644
--- a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net6.0.apilist.cs
+++ b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-net6.0.apilist.cs
@@ -1,132 +1,133 @@
-// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.1)
+// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.2)
// Name: Smdn.Reflection.ReverseGenerating
-// AssemblyVersion: 1.1.1.0
-// InformationalVersion: 1.1.1+9c1ed7379f1b7fe2562a51f0283b02332d84584f
+// AssemblyVersion: 1.1.2.0
+// InformationalVersion: 1.1.2+775287448dc58ab1c9fb7f0618d8c8bb6de9e775
// TargetFramework: .NETCoreApp,Version=v6.0
// Configuration: Release
#nullable enable annotations
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Smdn.Reflection;
using Smdn.Reflection.ReverseGenerating;
namespace Smdn.Reflection.ReverseGenerating {
public delegate bool AttributeTypeFilter(Type type, ICustomAttributeProvider attributeProvider);
public enum AttributeSectionFormat : int {
Discrete = 1,
List = 0,
}
public enum MethodBodyOption : int {
EmptyImplementation = 1,
None = 0,
ThrowNotImplementedException = 2,
ThrowNull = 3,
}
public static class CSharpFormatter {
public static string EscapeString(string s, bool escapeSingleQuote = false, bool escapeDoubleQuote = false) {}
public static string FormatAccessibility(Accessibility accessibility) {}
public static string FormatParameter(ParameterInfo p, NullabilityInfoContext? nullabilityInfoContext, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameter(ParameterInfo p, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(MethodBase m, NullabilityInfoContext? nullabilityInfoContext, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(MethodBase m, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(ParameterInfo[] parameterList, NullabilityInfoContext? nullabilityInfoContext, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(ParameterInfo[] parameterList, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatSpecialNameMethod(MethodBase methodOrConstructor, out MethodSpecialName nameType) {}
public static string FormatTypeName(this EventInfo ev, NullabilityInfoContext? nullabilityInfoContext, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this EventInfo ev, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this FieldInfo f, NullabilityInfoContext? nullabilityInfoContext, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this FieldInfo f, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this ParameterInfo p, NullabilityInfoContext? nullabilityInfoContext, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this ParameterInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this PropertyInfo p, NullabilityInfoContext? nullabilityInfoContext, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this PropertyInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this Type t, ICustomAttributeProvider? attributeProvider = null, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatValueDeclaration(object? val, Type typeOfValue, bool typeWithNamespace = true, bool findConstantField = false, bool useDefaultLiteral = false) {}
public static bool IsLanguagePrimitiveType(Type t, [MaybeNullWhen(false)] out string? primitiveTypeName) {}
public static IEnumerable<string> ToNamespaceList(Type t) {}
}
public static class Generator {
public static IEnumerable<string> GenerateAttributeList(ICustomAttributeProvider attributeProvider, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateGenericArgumentConstraintDeclaration(Type genericArgument, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string? GenerateMemberDeclaration(MemberInfo member, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateTypeDeclaration(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateTypeDeclarationWithExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
}
public class GeneratorOptions : ICloneable {
public class AttributeDeclarationOptions {
public AttributeDeclarationOptions() {}
public AttributeSectionFormat AccessorFormat { get; set; }
public AttributeSectionFormat AccessorParameterFormat { get; set; }
public AttributeSectionFormat BackingFieldFormat { get; set; }
public AttributeSectionFormat DelegateParameterFormat { get; set; }
public AttributeSectionFormat GenericParameterFormat { get; set; }
public AttributeSectionFormat MethodParameterFormat { get; set; }
public bool OmitAttributeSuffix { get; set; }
public AttributeTypeFilter? TypeFilter { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamedArguments { get; set; }
public bool WithNamespace { get; set; }
}
public class MemberDeclarationOptions {
public MemberDeclarationOptions() {}
public MethodBodyOption AccessorBody { get; set; }
public MethodBodyOption MethodBody { get; set; }
public NullabilityInfoContext? NullabilityInfoContext { get; set; }
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
+ public bool WithEnumTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ParameterDeclarationOptions {
public ParameterDeclarationOptions() {}
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class TypeDeclarationOptions {
public TypeDeclarationOptions() {}
public NullabilityInfoContext? NullabilityInfoContext { get; set; }
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ValueDeclarationOptions {
public ValueDeclarationOptions() {}
public bool UseDefaultLiteral { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public GeneratorOptions() {}
public GeneratorOptions.AttributeDeclarationOptions AttributeDeclaration { get; init; }
public bool IgnorePrivateOrAssembly { get; set; }
public string? Indent { get; set; }
public GeneratorOptions.MemberDeclarationOptions MemberDeclaration { get; init; }
public GeneratorOptions.ParameterDeclarationOptions ParameterDeclaration { get; init; }
public bool TranslateLanguagePrimitiveTypeDeclaration { get; set; }
public GeneratorOptions.TypeDeclarationOptions TypeDeclaration { get; init; }
public GeneratorOptions.ValueDeclarationOptions ValueDeclaration { get; init; }
public virtual GeneratorOptions Clone() {}
object ICloneable.Clone() {}
}
}
diff --git a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-netstandard2.0.apilist.cs b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-netstandard2.0.apilist.cs
index 0cb94fd..0dcbe84 100644
--- a/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-netstandard2.0.apilist.cs
+++ b/doc/api-list/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating-netstandard2.0.apilist.cs
@@ -1,122 +1,123 @@
-// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.1)
+// Smdn.Reflection.ReverseGenerating.dll (Smdn.Reflection.ReverseGenerating-1.1.2)
// Name: Smdn.Reflection.ReverseGenerating
-// AssemblyVersion: 1.1.1.0
-// InformationalVersion: 1.1.1+9c1ed7379f1b7fe2562a51f0283b02332d84584f
+// AssemblyVersion: 1.1.2.0
+// InformationalVersion: 1.1.2+775287448dc58ab1c9fb7f0618d8c8bb6de9e775
// TargetFramework: .NETStandard,Version=v2.0
// Configuration: Release
#nullable enable annotations
using System;
using System.Collections.Generic;
using System.Reflection;
using Smdn.Reflection;
using Smdn.Reflection.ReverseGenerating;
namespace Smdn.Reflection.ReverseGenerating {
public delegate bool AttributeTypeFilter(Type type, ICustomAttributeProvider attributeProvider);
public enum AttributeSectionFormat : int {
Discrete = 1,
List = 0,
}
public enum MethodBodyOption : int {
EmptyImplementation = 1,
None = 0,
ThrowNotImplementedException = 2,
ThrowNull = 3,
}
public static class CSharpFormatter {
public static string EscapeString(string s, bool escapeSingleQuote = false, bool escapeDoubleQuote = false) {}
public static string FormatAccessibility(Accessibility accessibility) {}
public static string FormatParameter(ParameterInfo p, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(MethodBase m, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatParameterList(ParameterInfo[] parameterList, bool typeWithNamespace = true, bool useDefaultLiteral = false) {}
public static string FormatSpecialNameMethod(MethodBase methodOrConstructor, out MethodSpecialName nameType) {}
public static string FormatTypeName(this EventInfo ev, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this FieldInfo f, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this ParameterInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this PropertyInfo p, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatTypeName(this Type t, ICustomAttributeProvider? attributeProvider = null, bool typeWithNamespace = true, bool withDeclaringTypeName = true, bool translateLanguagePrimitiveType = true) {}
public static string FormatValueDeclaration(object? val, Type typeOfValue, bool typeWithNamespace = true, bool findConstantField = false, bool useDefaultLiteral = false) {}
public static bool IsLanguagePrimitiveType(Type t, out string primitiveTypeName) {}
public static IEnumerable<string> ToNamespaceList(Type t) {}
}
public static class Generator {
public static IEnumerable<string> GenerateAttributeList(ICustomAttributeProvider attributeProvider, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateGenericArgumentConstraintDeclaration(Type genericArgument, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string? GenerateMemberDeclaration(MemberInfo member, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static string GenerateTypeDeclaration(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
public static IEnumerable<string> GenerateTypeDeclarationWithExplicitBaseTypeAndInterfaces(Type t, ISet<string>? referencingNamespaces, GeneratorOptions options) {}
}
public class GeneratorOptions : ICloneable {
public class AttributeDeclarationOptions {
public AttributeDeclarationOptions() {}
public AttributeSectionFormat AccessorFormat { get; set; }
public AttributeSectionFormat AccessorParameterFormat { get; set; }
public AttributeSectionFormat BackingFieldFormat { get; set; }
public AttributeSectionFormat DelegateParameterFormat { get; set; }
public AttributeSectionFormat GenericParameterFormat { get; set; }
public AttributeSectionFormat MethodParameterFormat { get; set; }
public bool OmitAttributeSuffix { get; set; }
public AttributeTypeFilter? TypeFilter { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamedArguments { get; set; }
public bool WithNamespace { get; set; }
}
public class MemberDeclarationOptions {
public MemberDeclarationOptions() {}
public MethodBodyOption AccessorBody { get; set; }
public MethodBodyOption MethodBody { get; set; }
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
+ public bool WithEnumTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ParameterDeclarationOptions {
public ParameterDeclarationOptions() {}
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class TypeDeclarationOptions {
public TypeDeclarationOptions() {}
public bool OmitEndOfStatement { get; set; }
public bool WithAccessibility { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public class ValueDeclarationOptions {
public ValueDeclarationOptions() {}
public bool UseDefaultLiteral { get; set; }
public bool WithDeclaringTypeName { get; set; }
public bool WithNamespace { get; set; }
}
public GeneratorOptions() {}
public GeneratorOptions.AttributeDeclarationOptions AttributeDeclaration { get; init; }
public bool IgnorePrivateOrAssembly { get; set; }
public string? Indent { get; set; }
public GeneratorOptions.MemberDeclarationOptions MemberDeclaration { get; init; }
public GeneratorOptions.ParameterDeclarationOptions ParameterDeclaration { get; init; }
public bool TranslateLanguagePrimitiveTypeDeclaration { get; set; }
public GeneratorOptions.TypeDeclarationOptions TypeDeclaration { get; init; }
public GeneratorOptions.ValueDeclarationOptions ValueDeclaration { get; init; }
public virtual GeneratorOptions Clone() {}
object ICloneable.Clone() {}
}
}Full changes
Full changes in this release:
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating.csproj b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating.csproj
index b144e12..4c7f3ca 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating.csproj
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating.csproj
@@ -6,7 +6,7 @@ SPDX-License-Identifier: MIT
<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;net47;net45;netstandard2.0</TargetFrameworks>
<RootNamespace>Smdn.Reflection.ReverseGenerating</RootNamespace>
- <VersionPrefix>1.1.1</VersionPrefix>
+ <VersionPrefix>1.1.2</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion>
<Nullable>enable</Nullable>
@@ -18,6 +18,9 @@ SPDX-License-Identifier: MIT
$(TargetFramework.StartsWith('netstandard2'))
)
">$(DefineConstants);CAN_OVERRIDE_CUSTOMATTRIBUTEDATA_ATTRIBUTETYPE</DefineConstants>
+ <DefineConstants Condition="
+ $(TargetFramework.StartsWith('net6.0'))
+ ">$(DefineConstants);WORKAROUND_NULLABILITYINFO_BYREFTYPE</DefineConstants>
</PropertyGroup>
<Import Project="..\Sdk.net7.0-preview.props" />
@@ -37,6 +40,6 @@ SPDX-License-Identifier: MIT
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" Condition="$(TargetFramework.StartsWith('net45')) or $(TargetFramework.StartsWith('net46')) or $(TargetFramework.StartsWith('netstandard1'))" />
- <PackageReference Include="Smdn.Fundamental.Reflection" Version="[3.3.0,4.0.0)" />
+ <PackageReference Include="Smdn.Fundamental.Reflection" Version="[3.3.1,4.0.0)" />
</ItemGroup>
</Project>
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeName.cs b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeName.cs
index ee39cdf..cc00e0f 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeName.cs
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeName.cs
@@ -14,6 +14,9 @@ static partial class CSharpFormatter {
bool TypeWithNamespace,
bool WithDeclaringTypeName,
bool TranslateLanguagePrimitiveType,
+#if SYSTEM_REFLECTION_NULLABILITYINFOCONTEXT && WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ NullabilityInfoContext? NullabilityInfoContext = null,
+#endif
Func<Type, string, string>? GenericParameterNameModifier = null,
bool OmitAttributeSuffix = false
#pragma warning restore SA1313
@@ -58,6 +61,9 @@ static partial class CSharpFormatter {
AttributeProvider: f,
TypeWithNamespace: typeWithNamespace,
WithDeclaringTypeName: withDeclaringTypeName,
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ NullabilityInfoContext: nullabilityInfoContext,
+#endif
TranslateLanguagePrimitiveType: translateLanguagePrimitiveType
)
).ToString();
@@ -101,6 +107,9 @@ static partial class CSharpFormatter {
AttributeProvider: p,
TypeWithNamespace: typeWithNamespace,
WithDeclaringTypeName: withDeclaringTypeName,
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ NullabilityInfoContext: nullabilityInfoContext,
+#endif
TranslateLanguagePrimitiveType: translateLanguagePrimitiveType
)
).ToString();
@@ -144,6 +153,9 @@ static partial class CSharpFormatter {
AttributeProvider: p,
TypeWithNamespace: typeWithNamespace,
WithDeclaringTypeName: withDeclaringTypeName,
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ NullabilityInfoContext: nullabilityInfoContext,
+#endif
TranslateLanguagePrimitiveType: translateLanguagePrimitiveType
)
).ToString();
@@ -187,6 +199,9 @@ static partial class CSharpFormatter {
AttributeProvider: ev,
TypeWithNamespace: typeWithNamespace,
WithDeclaringTypeName: withDeclaringTypeName,
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ NullabilityInfoContext: nullabilityInfoContext,
+#endif
TranslateLanguagePrimitiveType: translateLanguagePrimitiveType
)
).ToString();
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameCore.cs b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameCore.cs
index ab4e0c6..0bacdd2 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameCore.cs
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameCore.cs
@@ -42,17 +42,21 @@ static partial class CSharpFormatter {
if (t.IsByRef) {
var typeName = FormatCore(t.GetElementTypeOrThrow(), showVariance: false, options);
- if (options.AttributeProvider is ParameterInfo p) {
- // if (p.IsRetval)
+ switch (options.AttributeProvider) {
+ case ParameterInfo para:
+ // if (para.IsRetval)
// return "ref " + typeName;
- if (p.IsIn)
+ if (para.IsIn)
return "in " + typeName;
- else if (p.IsOut)
+ else if (para.IsOut)
return "out " + typeName;
else
return "ref " + typeName;
- }
- else {
+
+ case PropertyInfo p:
+ return "ref " + typeName;
+
+ default:
return typeName + "&";
}
}
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameWithNullabilityAnnotation.cs b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameWithNullabilityAnnotation.cs
index cba8871..06366d8 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameWithNullabilityAnnotation.cs
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/CSharpTypeFormatter.FormatTypeNameWithNullabilityAnnotation.cs
@@ -3,6 +3,9 @@
#if SYSTEM_REFLECTION_NULLABILITYINFO
using System;
using System.Collections.Generic;
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+using System.Globalization;
+#endif
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -15,12 +18,53 @@ namespace Smdn.Reflection.ReverseGenerating;
#pragma warning disable IDE0040
static partial class CSharpFormatter {
#pragma warning restore IDE0040
- private static readonly string NullableAnnotationSyntaxString = "?";
- private static string GetNullabilityAnnotation(NullabilityInfo target)
- => target.ReadState == NullabilityState.Nullable || target.WriteState == NullabilityState.Nullable
- ? NullableAnnotationSyntaxString
- : string.Empty;
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ // Workaround: The pseudo ParameterInfo type which unwraps 'ByRef' type to its element type
+ // See https://github.com/dotnet/runtime/issues/72320
+ private sealed class ByRefElementTypeParameterInfo : ParameterInfo {
+ public ParameterInfo BaseParameter { get; }
+
+ public ByRefElementTypeParameterInfo(ParameterInfo baseParam)
+ {
+ BaseParameter = baseParam;
+ }
+
+ public override MemberInfo Member => BaseParameter.Member;
+ public override Type ParameterType => BaseParameter.ParameterType.GetElementType()!;
+ public override IList<CustomAttributeData> GetCustomAttributesData()
+ => BaseParameter.GetCustomAttributesData();
+ }
+
+ private sealed class ByRefElementTypePropertyInfo : PropertyInfo {
+ public PropertyInfo BaseProperty { get; }
+
+ public ByRefElementTypePropertyInfo(PropertyInfo baseProperty)
+ {
+ BaseProperty = baseProperty;
+ }
+
+ public override string Name => BaseProperty.Name;
+ public override PropertyAttributes Attributes => BaseProperty.Attributes;
+ public override bool CanRead => BaseProperty.CanRead;
+ public override bool CanWrite => BaseProperty.CanWrite;
+ public override Type PropertyType => BaseProperty.PropertyType.GetElementType()!;
+ public override Type? DeclaringType => BaseProperty.DeclaringType;
+ public override Type? ReflectedType => BaseProperty.ReflectedType;
+ public override IList<CustomAttributeData> GetCustomAttributesData() => BaseProperty.GetCustomAttributesData();
+ public override object[] GetCustomAttributes(bool inherit) => BaseProperty.GetCustomAttributes(inherit);
+ public override object[] GetCustomAttributes(Type attributeType, bool inherit) => BaseProperty.GetCustomAttributes(attributeType, inherit);
+ public override bool IsDefined(Type attributeType, bool inherit) => BaseProperty.IsDefined(attributeType, inherit);
+ public override MethodInfo[] GetAccessors(bool nonPublic) => BaseProperty.GetAccessors(nonPublic);
+ public override MethodInfo? GetGetMethod(bool nonPublic) => BaseProperty.GetGetMethod(nonPublic);
+ public override MethodInfo? GetSetMethod(bool nonPublic) => BaseProperty.GetSetMethod(nonPublic);
+ public override ParameterInfo[] GetIndexParameters() => BaseProperty.GetIndexParameters();
+ public override object? GetValue(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture)
+ => BaseProperty.GetValue(obj, invokeAttr, binder, index, culture);
+ public override void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture)
+ => BaseProperty.SetValue(obj, value, invokeAttr, binder, index, culture);
+ }
+#endif
private static StringBuilder FormatTypeNameWithNullabilityAnnotation(
NullabilityInfo target,
@@ -28,80 +72,125 @@ static partial class CSharpFormatter {
FormatTypeNameOptions options
)
{
- Type? byRefParameterType = null;
+ const string NullableAnnotationSyntaxString = "?";
+
+ static string GetNullabilityAnnotation(NullabilityInfo target)
+ => target.ReadState == NullabilityState.Nullable || target.WriteState == NullabilityState.Nullable
+ ? NullableAnnotationSyntaxString
+ : string.Empty;
- if (target.Type.IsByRef && options.AttributeProvider is ParameterInfo p) {
+ if (target.Type.IsByRef) {
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ var elementTypeNullabilityInfo = target.ElementType;
+#endif
+
+ switch (options.AttributeProvider) {
+ case ParameterInfo para:
// retval/parameter modifiers
- if (p.IsIn)
+ if (para.IsIn)
builder.Append("in ");
- else if (p.IsOut)
+ else if (para.IsOut)
builder.Append("out ");
- else /*if (p.IsRetval)*/
+ else /*if (para.IsRetval)*/
+ builder.Append("ref ");
+
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ // [.net6.0] Currently, NullabilityInfo.ElementType is always null if the type is ByRef.
+ // Uses the workaround implementation instead in that case.
+ // See https://github.com/dotnet/runtime/issues/72320
+ if (options.NullabilityInfoContext is not null && target.ElementType is null && para.ParameterType.HasElementType)
+ elementTypeNullabilityInfo = options.NullabilityInfoContext.Create(new ByRefElementTypeParameterInfo(para));
+#endif
+ break;
+
+ case PropertyInfo p:
builder.Append("ref ");
- byRefParameterType = target.Type.GetElementTypeOrThrow();
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ if (options.NullabilityInfoContext is not null && target.ElementType is null && p.PropertyType.HasElementType)
+ elementTypeNullabilityInfo = options.NullabilityInfoContext.Create(new ByRefElementTypePropertyInfo(p));
+#endif
+ break;
+ }
+
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
+ if (elementTypeNullabilityInfo is not null) {
+ return FormatTypeNameWithNullabilityAnnotation(
+ elementTypeNullabilityInfo,
+ builder,
+ options
+ );
+ }
+#else
+ return FormatTypeNameWithNullabilityAnnotation(
+ target.ElementType!,
+ builder,
+ options
+ );
+#endif
}
- if (target.ElementType is not null) {
+ if (target.Type.IsArray) {
// arrays
- return FormatTypeNameWithNullabilityAnnotation(target.ElementType, builder, options)
+ return FormatTypeNameWithNullabilityAnnotation(target.ElementType!, builder, options)
.Append('[')
.Append(',', target.Type.GetArrayRank() - 1)
.Append(']')
.Append(GetNullabilityAnnotation(target));
}
- if (target.Type.IsPointer || (target.Type.IsByRef && options.AttributeProvider is not ParameterInfo))
+ if (target.Type.IsPointer || target.Type.IsByRef)
+ // pointer types or ByRef types (exclude ParameterInfo and PropertyInfo)
return builder.Append(FormatTypeNameCore(target.Type, options));
- var targetType = byRefParameterType ?? target.Type;
-
- if (IsValueTupleType(targetType)) {
- if (byRefParameterType is not null)
- // TODO: cannot get NullabilityInfo of generic type arguments from by-ref parameter type
- return builder.Append(FormatTypeNameCore(targetType, options));
-
+ if (IsValueTupleType(target.Type)) {
// special case for value tuples (ValueTuple<>)
- return FormatValueTuple(target, builder, options);
+ return FormatValueTupleType(target, builder, options)
+ .Append(GetNullabilityAnnotation(target));
}
+ var targetType = target.Type;
var isGenericTypeClosedOrDefinition =
targetType.IsGenericTypeDefinition ||
targetType.IsConstructedGenericType ||
(targetType.IsGenericType && targetType.ContainsGenericParameters);
- string? nullabilityAnnotationForByRefParameter = null;
if (Nullable.GetUnderlyingType(targetType) is Type nullableUnderlyingType) {
- if (byRefParameterType is not null)
- // note: if the by-ref parameter is Nullable<>, NullabilityState will not be Nullable
- nullabilityAnnotationForByRefParameter = NullableAnnotationSyntaxString;
-
// nullable value types (Nullable<>)
- if (IsValueTupleType(nullableUnderlyingType))
+ if (IsValueTupleType(nullableUnderlyingType)) {
// special case for nullable value tuples (Nullable<ValueTuple<>>)
- return FormatValueTuple(target, builder, options).Append(nullabilityAnnotationForByRefParameter);
- else if (isGenericTypeClosedOrDefinition)
+ return FormatValueTupleType(target, builder, options)
+ .Append(GetNullabilityAnnotation(target));
+ }
+ else if (nullableUnderlyingType.IsGenericType) {
// case for nullable generic value types (Nullable<GenericValueType<>>)
- // TODO: cannot get NullabilityInfo of generic type argument from Nullable<GenericValueType<>> (ex: KeyValuePair<int?, string?>?)
- return builder.Append(FormatTypeNameCore(targetType, options));
+ return FormatNullableGenericValueType(target, builder, options)
+ .Append(GetNullabilityAnnotation(target));
+ }
targetType = nullableUnderlyingType;
}
else if (isGenericTypeClosedOrDefinition) {
// other generic types
- if (targetType == byRefParameterType)
+ if (targetType.IsByRef) {
+#if WORKAROUND_NULLABILITYINFO_BYREFTYPE
// TODO: cannot get NullabilityInfo of generic type arguments from by-ref parameter type
return builder.Append(FormatTypeNameCore(targetType, options));
- else
- return FormatGenericTypeClosedOrDefinition(target, builder, options);
+#else
+ return FormatTypeNameWithNullabilityAnnotation(target.ElementType!, builder, options);
+#endif
+ }
+ else {
+ return FormatClosedGenericTypeOrGenericTypeDefinition(target, builder, options)
+ .Append(GetNullabilityAnnotation(target));
+ }
}
if (options.TranslateLanguagePrimitiveType && IsLanguagePrimitiveType(targetType, out var n)) {
// language primitive types
return builder
.Append(n)
- .Append(GetNullabilityAnnotation(target))
- .Append(nullabilityAnnotationForByRefParameter);
+ .Append(GetNullabilityAnnotation(target));
}
if (targetType.IsGenericParameter && targetType.HasGenericParameterNoConstraints())
@@ -117,11 +206,10 @@ static partial class CSharpFormatter {
return builder
.Append(GetTypeName(targetType, options))
- .Append(GetNullabilityAnnotation(target))
- .Append(nullabilityAnnotationForByRefParameter);
+ .Append(GetNullabilityAnnotation(target));
}
- private static StringBuilder FormatGenericTypeClosedOrDefinition(
+ private static StringBuilder FormatClosedGenericTypeOrGenericTypeDefinition(
NullabilityInfo target,
StringBuilder builder,
FormatTypeNameOptions options
@@ -164,10 +252,10 @@ static partial class CSharpFormatter {
builder.Append('>');
}
- return builder.Append(GetNullabilityAnnotation(target));
+ return builder;
}
- private static StringBuilder FormatValueTuple(
+ private static StringBuilder FormatValueTupleType(
NullabilityInfo target,
StringBuilder builder,
FormatTypeNameOptions options
@@ -200,7 +288,35 @@ static partial class CSharpFormatter {
builder.Append(' ').Append(tupleItemNames[i].Value);
}
- return builder.Append(')').Append(GetNullabilityAnnotation(target));
+ return builder.Append(')');
+ }
+
+ private static StringBuilder FormatNullableGenericValueType(
+ NullabilityInfo target,
+ StringBuilder builder,
+ FormatTypeNameOptions options
+ )
+ {
+ if (options.TypeWithNamespace && !target.Type.IsNested)
+ builder.Append(target.Type.Namespace).Append('.');
+
+ builder
+ .Append(
+ GetTypeName(
+ target.Type.GenericTypeArguments[0], // the type of GenericValueType of Nullable<GenericValueType<>>
+ options
+ )
+ )
+ .Append('<');
+
+ for (var i = 0; i < target.GenericTypeArguments.Length; i++) {
+ if (0 < i)
+ builder.Append(", ");
+
+ FormatTypeNameWithNullabilityAnnotation(target.GenericTypeArguments[i], builder, options);
+ }
+
+ return builder.Append('>');
}
}
#endif // SYSTEM_REFLECTION_NULLABILITYINFO
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.Attributes.cs b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.Attributes.cs
index a70fe2e..869e8d3 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.Attributes.cs
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.Attributes.cs
@@ -1,9 +1,5 @@
// SPDX-FileCopyrightText: 2020 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
-#if NET7_0_OR_GREATER
-#define SYSTEM_DIAGNOSTICS_UNREACHABLEEXCEPTION
-#endif
-
using System;
using System.Collections.Generic;
#if SYSTEM_DIAGNOSTICS_UNREACHABLEEXCEPTION
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.cs b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.cs
index 20c1f44..083d45c 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.cs
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/Generator.cs
@@ -1,9 +1,5 @@
// SPDX-FileCopyrightText: 2020 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
-#if NETCOREAPP3_0_OR_GREATER || NET5_0_OR_GREATER
-#define SYSTEM_STRING_CONCAT_READONLYSPAN_OF_CHAR
-#endif
-
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -1076,7 +1072,12 @@ public static partial class Generator {
GeneratorOptions options
)
{
- if (options.MemberDeclaration.WithDeclaringTypeName) {
+ var withDeclaringTypeName = options.MemberDeclaration.WithDeclaringTypeName;
+
+ if (member is FieldInfo field && field.GetDeclaringTypeOrThrow().IsEnum)
+ withDeclaringTypeName = options.MemberDeclaration.WithEnumTypeName;
+
+ if (withDeclaringTypeName) {
return member.GetDeclaringTypeOrThrow().FormatTypeName(
typeWithNamespace: options.MemberDeclaration.WithNamespace,
translateLanguagePrimitiveType: options.TranslateLanguagePrimitiveTypeDeclaration
@@ -1178,10 +1179,20 @@ public static partial class Generator {
if (isAsyncStateMachine)
sb.Append("async ");
- if (method is not null && method.GetParameters().Any(static p => p.ParameterType.IsPointer))
+ if (method is not null && method.GetParameters().Any(IsParameterUnsafe))
sb.Append("unsafe ");
}
+ static bool IsParameterUnsafe(ParameterInfo p)
+ {
+ if (p.ParameterType.IsPointer)
+ return true;
+ if (p.ParameterType.IsByRef && p.ParameterType.HasElementType && p.ParameterType.GetElementType()!.IsPointer)
+ return true;
+
+ return false;
+ }
+
if (member.IsHidingInheritedMember(nonPublic: true))
sb.Append("new ");
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/GeneratorOptions.cs b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/GeneratorOptions.cs
index 2188f27..ebb10f1 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/GeneratorOptions.cs
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection.ReverseGenerating/GeneratorOptions.cs
@@ -47,6 +47,7 @@ public class GeneratorOptions : ICloneable {
public class MemberDeclarationOptions {
public bool WithNamespace { get; set; } = false;
public bool WithDeclaringTypeName { get; set; } = false;
+ public bool WithEnumTypeName { get; set; } = false;
public bool WithAccessibility { get; set; } = true;
public bool OmitEndOfStatement { get; set; } = false;
public MethodBodyOption MethodBody { get; set; } = MethodBodyOption.EmptyImplementation;
diff --git a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection/TypeGenericParameterExtensions.cs b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection/TypeGenericParameterExtensions.cs
index 9a0e57f..705dc86 100644
--- a/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection/TypeGenericParameterExtensions.cs
+++ b/src/Smdn.Reflection.ReverseGenerating/Smdn.Reflection/TypeGenericParameterExtensions.cs
@@ -1,9 +1,5 @@
// SPDX-FileCopyrightText: 2022 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
-#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER || NET5_0_OR_GREATER
-#define SYSTEM_TYPE_ISGENERICMETHODPARAMETER
-#endif
-
using System;
#if NULL_STATE_STATIC_ANALYSIS_ATTRIBUTES
using System.Diagnostics.CodeAnalysis;Full Changelog: releases/Smdn.Reflection.ReverseGenerating.ListApi-1.1.0...releases/Smdn.Reflection.ReverseGenerating-1.1.2