From 80201c19ccc446aa10724d8ddfe5fab8ea4fc51a Mon Sep 17 00:00:00 2001 From: Alexander Gayko Date: Thu, 14 Aug 2025 12:32:21 +0200 Subject: [PATCH] added the RHOMICRO_EMIT_PUBLIC_COLLECTIONS compiler directive to allow the generator using those classes to be public --- .../Library/Models/ArrayTypeModel.cs | 7 ++++++- .../Library/Models/AttributeParameterTypeKind.cs | 14 ++++++++++++-- .../Library/Models/AttributeParameterTypeModel.cs | 7 ++++++- .../Collections/DictionaryEqualityComparer.cs | 7 ++++++- .../Collections/EnumerableEqualityComparer.cs | 14 ++++++++++++-- .../Models/Collections/EqualityComparerFactory.cs | 7 ++++++- .../Models/Collections/EquatableCollection.cs | 14 ++++++++++++-- .../Collections/EquatableCollectionFactory.cs | 7 ++++++- .../Models/Collections/EquatableDictionary.cs | 7 ++++++- .../Library/Models/Collections/EquatableList.cs | 7 ++++++- .../Library/Models/Collections/EquatableSet.cs | 7 ++++++- .../Collections/KeyValuePairEqualityComparer.cs | 7 ++++++- .../Models/Collections/LazyEquatableDictionary.cs | 15 +++++++++++++-- .../Models/Collections/LazyEquatableList.cs | 15 +++++++++++++-- .../Models/Collections/MutabilityContext.cs | 7 ++++++- .../Models/Collections/MutableCollection.cs | 14 ++++++++++++-- .../Models/Collections/SetEqualityComparer.cs | 7 ++++++- .../Models/ContainingTypeSignatureModel.cs | 7 ++++++- .../Library/Models/ModelCreationContext.cs | 7 ++++++- .../Library/Models/NamedTypeModel.cs | 7 ++++++- .../Library/Models/PartialTypeKindModel.cs | 7 ++++++- UtilityGenerators/Library/Models/TypeModel.cs | 7 ++++++- 22 files changed, 170 insertions(+), 28 deletions(-) diff --git a/UtilityGenerators/Library/Models/ArrayTypeModel.cs b/UtilityGenerators/Library/Models/ArrayTypeModel.cs index 0dbb6c8..8ac7031 100644 --- a/UtilityGenerators/Library/Models/ArrayTypeModel.cs +++ b/UtilityGenerators/Library/Models/ArrayTypeModel.cs @@ -9,7 +9,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal sealed record ArrayTypeModel( +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record ArrayTypeModel( TypeModel ElementType, EquatableList NamespaceParts, String Name) : TypeModel( diff --git a/UtilityGenerators/Library/Models/AttributeParameterTypeKind.cs b/UtilityGenerators/Library/Models/AttributeParameterTypeKind.cs index 26ba2f3..8ed7f7a 100644 --- a/UtilityGenerators/Library/Models/AttributeParameterTypeKind.cs +++ b/UtilityGenerators/Library/Models/AttributeParameterTypeKind.cs @@ -5,7 +5,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal enum AttributeParameterTypeKind +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +enum AttributeParameterTypeKind { ReferenceType = 1, Type = 2, @@ -36,7 +41,12 @@ internal enum AttributeParameterTypeKind NullableReferenceTypeNullableArray = Nullable | ReferenceType | NullableArray, } -internal static class AttributeArgumentTypeKindExtensions +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +static class AttributeArgumentTypeKindExtensions { public static Boolean HasAnyFlagFast(this AttributeParameterTypeKind value, params ReadOnlySpan flags) { diff --git a/UtilityGenerators/Library/Models/AttributeParameterTypeModel.cs b/UtilityGenerators/Library/Models/AttributeParameterTypeModel.cs index 173b01f..469dfc0 100644 --- a/UtilityGenerators/Library/Models/AttributeParameterTypeModel.cs +++ b/UtilityGenerators/Library/Models/AttributeParameterTypeModel.cs @@ -8,7 +8,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal sealed record AttributeParameterTypeModel( +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record AttributeParameterTypeModel( AttributeParameterTypeKind Kind, String KindString, String DisplayString, diff --git a/UtilityGenerators/Library/Models/Collections/DictionaryEqualityComparer.cs b/UtilityGenerators/Library/Models/Collections/DictionaryEqualityComparer.cs index 047edd2..201de1a 100644 --- a/UtilityGenerators/Library/Models/Collections/DictionaryEqualityComparer.cs +++ b/UtilityGenerators/Library/Models/Collections/DictionaryEqualityComparer.cs @@ -12,7 +12,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #if GENERATOR [NonEquatable] #endif -internal sealed partial class DictionaryEqualityComparer(IEqualityComparer keyComparer, IEqualityComparer valueComparer) : IEqualityComparer> +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed partial class DictionaryEqualityComparer(IEqualityComparer keyComparer, IEqualityComparer valueComparer) : IEqualityComparer> { public DictionaryEqualityComparer(IEqualityComparer valueComparer) : this(EqualityComparer.Default, valueComparer) { } public DictionaryEqualityComparer(IEqualityComparer keyComparer) : this(keyComparer, EqualityComparer.Default) { } diff --git a/UtilityGenerators/Library/Models/Collections/EnumerableEqualityComparer.cs b/UtilityGenerators/Library/Models/Collections/EnumerableEqualityComparer.cs index 340aff2..3b18fac 100644 --- a/UtilityGenerators/Library/Models/Collections/EnumerableEqualityComparer.cs +++ b/UtilityGenerators/Library/Models/Collections/EnumerableEqualityComparer.cs @@ -9,7 +9,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal static class EnumerableEqualityComparer +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +static class EnumerableEqualityComparer { public static Int32 GetHashCode(TEnumerable obj, IEqualityComparer elementComparer) where TEnumerable : IEnumerable @@ -26,7 +31,12 @@ public static Int32 GetHashCode(TEnumerable obj, IEqualityCompar #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [NonEquatable] #endif -internal sealed partial class EnumerableEqualityComparer(IEqualityComparer elementComparer) : IEqualityComparer> +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed partial class EnumerableEqualityComparer(IEqualityComparer elementComparer) : IEqualityComparer> { public static EnumerableEqualityComparer Default { get; } = new(EqualityComparer.Default); diff --git a/UtilityGenerators/Library/Models/Collections/EqualityComparerFactory.cs b/UtilityGenerators/Library/Models/Collections/EqualityComparerFactory.cs index 71d0e55..0fa6ce5 100644 --- a/UtilityGenerators/Library/Models/Collections/EqualityComparerFactory.cs +++ b/UtilityGenerators/Library/Models/Collections/EqualityComparerFactory.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #if GENERATOR [NonEquatable] #endif -internal partial class EqualityComparerFactory +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +partial class EqualityComparerFactory { public static EqualityComparerFactory Default { get; } = new(); diff --git a/UtilityGenerators/Library/Models/Collections/EquatableCollection.cs b/UtilityGenerators/Library/Models/Collections/EquatableCollection.cs index a51d9f3..5f8de2a 100644 --- a/UtilityGenerators/Library/Models/Collections/EquatableCollection.cs +++ b/UtilityGenerators/Library/Models/Collections/EquatableCollection.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; [IncludeFile] #endif [DebuggerDisplay("Count: {Count}")] -internal sealed record EquatableCollection : EquatableCollection> +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record EquatableCollection : EquatableCollection> { public EquatableCollection( ICollection collection, @@ -21,7 +26,12 @@ public EquatableCollection( { } } -internal abstract record EquatableCollection : MutableCollection, ICollection +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +abstract record EquatableCollection : MutableCollection, ICollection where TCollection : ICollection { public EquatableCollection( diff --git a/UtilityGenerators/Library/Models/Collections/EquatableCollectionFactory.cs b/UtilityGenerators/Library/Models/Collections/EquatableCollectionFactory.cs index 3e4ebcc..03e018e 100644 --- a/UtilityGenerators/Library/Models/Collections/EquatableCollectionFactory.cs +++ b/UtilityGenerators/Library/Models/Collections/EquatableCollectionFactory.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #if GENERATOR [NonEquatable] #endif -internal sealed partial class EquatableCollectionFactory(EqualityComparerFactory comparerFactory, MutabilityContext mutabilityContext) : IDisposable +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed partial class EquatableCollectionFactory(EqualityComparerFactory comparerFactory, MutabilityContext mutabilityContext) : IDisposable { public static EquatableCollectionFactory CreateDefault() => new(EqualityComparerFactory.Default, new()); diff --git a/UtilityGenerators/Library/Models/Collections/EquatableDictionary.cs b/UtilityGenerators/Library/Models/Collections/EquatableDictionary.cs index c6dccec..fa1df06 100644 --- a/UtilityGenerators/Library/Models/Collections/EquatableDictionary.cs +++ b/UtilityGenerators/Library/Models/Collections/EquatableDictionary.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; [IncludeFile] #endif [DebuggerDisplay("Count: {Count}")] -internal sealed record EquatableDictionary : EquatableCollection, IDictionary>, IDictionary, IReadOnlyDictionary +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record EquatableDictionary : EquatableCollection, IDictionary>, IDictionary, IReadOnlyDictionary { public EquatableDictionary( IDictionary collection, diff --git a/UtilityGenerators/Library/Models/Collections/EquatableList.cs b/UtilityGenerators/Library/Models/Collections/EquatableList.cs index 73c215e..7c5859d 100644 --- a/UtilityGenerators/Library/Models/Collections/EquatableList.cs +++ b/UtilityGenerators/Library/Models/Collections/EquatableList.cs @@ -11,7 +11,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #endif [CollectionBuilder(typeof(Builder), "Create")] [DebuggerDisplay("Count: {Count}")] -internal sealed record EquatableList : EquatableCollection>, IList, IReadOnlyList +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record EquatableList : EquatableCollection>, IList, IReadOnlyList { public EquatableList( IList collection, diff --git a/UtilityGenerators/Library/Models/Collections/EquatableSet.cs b/UtilityGenerators/Library/Models/Collections/EquatableSet.cs index 23a5a71..aee5689 100644 --- a/UtilityGenerators/Library/Models/Collections/EquatableSet.cs +++ b/UtilityGenerators/Library/Models/Collections/EquatableSet.cs @@ -12,7 +12,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #endif [CollectionBuilder(typeof(Builder), "Create")] [DebuggerDisplay("Count: {Count}")] -internal sealed record EquatableSet : EquatableCollection>, ISet +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record EquatableSet : EquatableCollection>, ISet { public EquatableSet( ISet collection, diff --git a/UtilityGenerators/Library/Models/Collections/KeyValuePairEqualityComparer.cs b/UtilityGenerators/Library/Models/Collections/KeyValuePairEqualityComparer.cs index 7d9d0c4..df81eae 100644 --- a/UtilityGenerators/Library/Models/Collections/KeyValuePairEqualityComparer.cs +++ b/UtilityGenerators/Library/Models/Collections/KeyValuePairEqualityComparer.cs @@ -11,7 +11,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #if GENERATOR [NonEquatable] #endif -internal sealed partial class KeyValuePairEqualityComparer(IEqualityComparer keyComparer, IEqualityComparer valueComparer) : IEqualityComparer> +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed partial class KeyValuePairEqualityComparer(IEqualityComparer keyComparer, IEqualityComparer valueComparer) : IEqualityComparer> { public KeyValuePairEqualityComparer(IEqualityComparer valueComparer) : this(EqualityComparer.Default, valueComparer) { } public static KeyValuePairEqualityComparer Default { get; } = new(EqualityComparer.Default, EqualityComparer.Default); diff --git a/UtilityGenerators/Library/Models/Collections/LazyEquatableDictionary.cs b/UtilityGenerators/Library/Models/Collections/LazyEquatableDictionary.cs index d254658..0d91020 100644 --- a/UtilityGenerators/Library/Models/Collections/LazyEquatableDictionary.cs +++ b/UtilityGenerators/Library/Models/Collections/LazyEquatableDictionary.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; [IncludeFile] #endif [DebuggerDisplay("Count: {Count}")] -internal sealed record LazyEquatableDictionary : LazyEquatableDictionary> +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record LazyEquatableDictionary : LazyEquatableDictionary> { public LazyEquatableDictionary( IDictionary collection, @@ -24,7 +29,13 @@ public LazyEquatableDictionary( public Boolean Equals(LazyEquatableDictionary other) => base.Equals(other); public override Int32 GetHashCode() => base.GetHashCode(); } -internal record LazyEquatableDictionary : EquatableCollection, IDictionary>, IDictionary + +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +record LazyEquatableDictionary : EquatableCollection, IDictionary>, IDictionary { public LazyEquatableDictionary( IDictionary collection, diff --git a/UtilityGenerators/Library/Models/Collections/LazyEquatableList.cs b/UtilityGenerators/Library/Models/Collections/LazyEquatableList.cs index 6dcb987..8373003 100644 --- a/UtilityGenerators/Library/Models/Collections/LazyEquatableList.cs +++ b/UtilityGenerators/Library/Models/Collections/LazyEquatableList.cs @@ -12,7 +12,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #endif [CollectionBuilder(typeof(Builder), "Create")] [DebuggerDisplay("Count: {Count}")] -internal sealed record LazyEquatableList : LazyEquatableList> +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record LazyEquatableList : LazyEquatableList> { public LazyEquatableList( IList collection, @@ -26,7 +31,13 @@ public LazyEquatableList( public Boolean Equals(LazyEquatableList other) => base.Equals(other); public override Int32 GetHashCode() => base.GetHashCode(); } -internal record LazyEquatableList : EquatableCollection>, IList, IReadOnlyList + +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +record LazyEquatableList : EquatableCollection>, IList, IReadOnlyList { public LazyEquatableList( IList collection, diff --git a/UtilityGenerators/Library/Models/Collections/MutabilityContext.cs b/UtilityGenerators/Library/Models/Collections/MutabilityContext.cs index 2de0ca5..0e34c59 100644 --- a/UtilityGenerators/Library/Models/Collections/MutabilityContext.cs +++ b/UtilityGenerators/Library/Models/Collections/MutabilityContext.cs @@ -11,7 +11,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #if GENERATOR [NonEquatable] #endif -internal sealed partial class MutabilityContext : IDisposable +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed partial class MutabilityContext : IDisposable { private Int32 _mutable; public Boolean IsImmutable => _mutable == 1; diff --git a/UtilityGenerators/Library/Models/Collections/MutableCollection.cs b/UtilityGenerators/Library/Models/Collections/MutableCollection.cs index 1356dfd..7f01201 100644 --- a/UtilityGenerators/Library/Models/Collections/MutableCollection.cs +++ b/UtilityGenerators/Library/Models/Collections/MutableCollection.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; [IncludeFile] #endif [DebuggerDisplay("Count: {Count}")] -internal abstract partial record MutableCollection(MutabilityContext MutabilityContext) +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +abstract partial record MutableCollection(MutabilityContext MutabilityContext) { public MutableCollection() : this(new MutabilityContext()) { } public Boolean IsReadOnly => MutabilityContext.IsImmutable; @@ -22,7 +27,12 @@ public MutableCollection() : this(new MutabilityContext()) { } #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [NonEquatable] #endif -internal partial class MutableCollection(ICollection wrapped, MutabilityContext mutabilityContext) : ICollection +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +partial class MutableCollection(ICollection wrapped, MutabilityContext mutabilityContext) : ICollection { public void Add(T item) { diff --git a/UtilityGenerators/Library/Models/Collections/SetEqualityComparer.cs b/UtilityGenerators/Library/Models/Collections/SetEqualityComparer.cs index b379471..99ad304 100644 --- a/UtilityGenerators/Library/Models/Collections/SetEqualityComparer.cs +++ b/UtilityGenerators/Library/Models/Collections/SetEqualityComparer.cs @@ -14,7 +14,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models.Collections; #if GENERATOR [NonEquatable] #endif -internal sealed partial class SetEqualityComparer(IEqualityComparer elementComparer) : IEqualityComparer> +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed partial class SetEqualityComparer(IEqualityComparer elementComparer) : IEqualityComparer> { public static SetEqualityComparer Default { get; } = new(EqualityComparer.Default); diff --git a/UtilityGenerators/Library/Models/ContainingTypeSignatureModel.cs b/UtilityGenerators/Library/Models/ContainingTypeSignatureModel.cs index a5364a8..0a44fbc 100644 --- a/UtilityGenerators/Library/Models/ContainingTypeSignatureModel.cs +++ b/UtilityGenerators/Library/Models/ContainingTypeSignatureModel.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal readonly record struct ContainingTypeSignatureModel( +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +readonly record struct ContainingTypeSignatureModel( PartialTypeKindModel Kind, String Name, EquatableList TypeArguments) diff --git a/UtilityGenerators/Library/Models/ModelCreationContext.cs b/UtilityGenerators/Library/Models/ModelCreationContext.cs index da3426b..3c3d821 100644 --- a/UtilityGenerators/Library/Models/ModelCreationContext.cs +++ b/UtilityGenerators/Library/Models/ModelCreationContext.cs @@ -10,7 +10,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if GENERATOR [NonEquatable] #endif -internal readonly partial struct ModelCreationContext(EquatableCollectionFactory collectionFactory, CancellationToken cancellationToken) : IDisposable +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +readonly partial struct ModelCreationContext(EquatableCollectionFactory collectionFactory, CancellationToken cancellationToken) : IDisposable { public EquatableCollectionFactory CollectionFactory { get; } = collectionFactory; public CancellationToken CancellationToken { get; } = cancellationToken; diff --git a/UtilityGenerators/Library/Models/NamedTypeModel.cs b/UtilityGenerators/Library/Models/NamedTypeModel.cs index cbf48c9..3568ad9 100644 --- a/UtilityGenerators/Library/Models/NamedTypeModel.cs +++ b/UtilityGenerators/Library/Models/NamedTypeModel.cs @@ -12,7 +12,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal sealed record NamedTypeModel( +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +sealed record NamedTypeModel( EquatableList ContainingTypes, Accessibility? Accessibility, PartialTypeKindModel Kind, diff --git a/UtilityGenerators/Library/Models/PartialTypeKindModel.cs b/UtilityGenerators/Library/Models/PartialTypeKindModel.cs index 8709905..069a785 100644 --- a/UtilityGenerators/Library/Models/PartialTypeKindModel.cs +++ b/UtilityGenerators/Library/Models/PartialTypeKindModel.cs @@ -8,7 +8,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal readonly record struct PartialTypeKindModel(String Value) +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +readonly record struct PartialTypeKindModel(String Value) { public static PartialTypeKindModel Class => new("class"); public static PartialTypeKindModel Record => new("record"); diff --git a/UtilityGenerators/Library/Models/TypeModel.cs b/UtilityGenerators/Library/Models/TypeModel.cs index 6acf52a..ffd4421 100644 --- a/UtilityGenerators/Library/Models/TypeModel.cs +++ b/UtilityGenerators/Library/Models/TypeModel.cs @@ -9,7 +9,12 @@ namespace RhoMicro.CodeAnalysis.Library.Models; #if RHOMICRO_CODEANALYSIS_UTILITYGENERATORS [IncludeFile] #endif -internal record TypeModel( +#if RHOMICRO_EMIT_PUBLIC_COLLECTIONS +public +#else +internal +#endif +record TypeModel( EquatableList NamespaceParts, String Name) {