@@ -69,29 +69,20 @@ private static void WriteGenericColor((string, bool, bool, bool, bool) details)
6969 private static void WriteCustomColor ( IndentedTextWriter writer , string name , Type type , bool hasRed , bool hasGreen , bool hasBlue , bool hasAlpha , bool fullyUtilized )
7070 {
7171 string typeName = CSharpPrimitives . Dictionary [ type ] . LangName ;
72- writer . WriteLine ( "//This code is source generated. Do not edit manually." ) ;
73- writer . WriteLine ( ) ;
74- writer . WriteLine ( $ "using { AttributeNamespace } ;") ;
72+ writer . WriteGeneratedCodeWarning ( ) ;
7573 writer . WriteLine ( ) ;
76- writer . WriteLine ( $ "namespace { OutputNamespace } ") ;
77- using ( new CurlyBrackets ( writer ) )
74+ using ( new Namespace ( writer , OutputNamespace ) )
7875 {
79- WriteRgbaAttribute ( writer , hasRed , hasGreen , hasBlue , hasAlpha , fullyUtilized ) ;
8076 writer . WriteLine ( $ "public partial struct { name } : IColor<{ typeName } >") ;
8177 using ( new CurlyBrackets ( writer ) )
8278 {
83- WriteHasChannelStaticProperties ( writer , hasRed , hasGreen , hasBlue , hasAlpha , typeName ) ;
79+ WriteColorBaseStaticProperties ( writer , hasRed , hasGreen , hasBlue , hasAlpha , fullyUtilized , typeName ) ;
8480 writer . WriteLineNoTabs ( ) ;
8581 WriteToString ( writer , hasRed , hasGreen , hasBlue , hasAlpha ) ;
8682 }
8783 }
8884 }
8985
90- private static void WriteRgbaAttribute ( IndentedTextWriter writer , bool hasRed , bool hasGreen , bool hasBlue , bool hasAlpha , bool fullyUtilized )
91- {
92- writer . WriteLine ( $ "[RgbaAttribute(RedChannel = { hasRed . ToLowerString ( ) } , GreenChannel = { hasGreen . ToLowerString ( ) } , BlueChannel = { hasBlue . ToLowerString ( ) } , AlphaChannel = { hasAlpha . ToLowerString ( ) } , FullyUtilizedChannels = { fullyUtilized . ToLowerString ( ) } )]") ;
93- }
94-
9586 private static void WriteToString ( IndentedTextWriter writer , bool hasRed , bool hasGreen , bool hasBlue , bool hasAlpha )
9687 {
9788 writer . WriteLine ( "public override string ToString()" ) ;
@@ -136,12 +127,14 @@ private static void WriteToString(IndentedTextWriter writer, bool hasRed, bool h
136127 }
137128 }
138129
139- private static void WriteHasChannelStaticProperties ( IndentedTextWriter writer , bool hasRed , bool hasGreen , bool hasBlue , bool hasAlpha , string typeName )
130+ private static void WriteColorBaseStaticProperties ( IndentedTextWriter writer , bool hasRed , bool hasGreen , bool hasBlue , bool hasAlpha , bool fullyUtilized , string typeName )
140131 {
141- writer . WriteLine ( $ "static bool IColor<{ typeName } >.HasRedChannel => { hasRed . ToLowerString ( ) } ;") ;
142- writer . WriteLine ( $ "static bool IColor<{ typeName } >.HasGreenChannel => { hasGreen . ToLowerString ( ) } ;") ;
143- writer . WriteLine ( $ "static bool IColor<{ typeName } >.HasBlueChannel => { hasBlue . ToLowerString ( ) } ;") ;
144- writer . WriteLine ( $ "static bool IColor<{ typeName } >.HasAlphaChannel => { hasAlpha . ToLowerString ( ) } ;") ;
132+ writer . WriteLine ( $ "static bool IColorBase.HasRedChannel => { hasRed . ToLowerString ( ) } ;") ;
133+ writer . WriteLine ( $ "static bool IColorBase.HasGreenChannel => { hasGreen . ToLowerString ( ) } ;") ;
134+ writer . WriteLine ( $ "static bool IColorBase.HasBlueChannel => { hasBlue . ToLowerString ( ) } ;") ;
135+ writer . WriteLine ( $ "static bool IColorBase.HasAlphaChannel => { hasAlpha . ToLowerString ( ) } ;") ;
136+ writer . WriteLine ( $ "static bool IColorBase.ChannelsAreFullyUtilized => { fullyUtilized . ToLowerString ( ) } ;") ;
137+ writer . WriteLine ( $ "static Type IColorBase.ChannelType => typeof({ typeName } );") ;
145138 }
146139
147140 private static void WriteGenericColor ( IndentedTextWriter writer , string name , bool hasRed , bool hasGreen , bool hasBlue , bool hasAlpha )
@@ -153,13 +146,9 @@ private static void WriteGenericColor(IndentedTextWriter writer, string name, bo
153146 writer . WriteGeneratedCodeWarning ( ) ;
154147 writer . WriteLineNoTabs ( ) ;
155148
156- writer . WriteLine ( $ "using { AttributeNamespace } ;") ;
157- writer . WriteLineNoTabs ( ) ;
158-
159149 writer . WriteFileScopedNamespace ( OutputNamespace ) ;
160150 writer . WriteLineNoTabs ( ) ;
161151
162- WriteRgbaAttribute ( writer , hasRed , hasGreen , hasBlue , hasAlpha , true ) ;
163152 string constraints = hasRed && hasGreen && hasBlue && hasAlpha
164153 ? "unmanaged"
165154 : "unmanaged, INumberBase<T>, IMinMaxValue<T>" ;
@@ -179,7 +168,7 @@ private static void WriteGenericColor(IndentedTextWriter writer, string name, bo
179168 writer . WriteLineNoTabs ( ) ;
180169 WriteSetChannels ( writer , typeName , hasRed , hasGreen , hasBlue , hasAlpha ) ;
181170 writer . WriteLineNoTabs ( ) ;
182- WriteHasChannelStaticProperties ( writer , hasRed , hasGreen , hasBlue , hasAlpha , typeName ) ;
171+ WriteColorBaseStaticProperties ( writer , hasRed , hasGreen , hasBlue , hasAlpha , true , typeName ) ;
183172 writer . WriteLineNoTabs ( ) ;
184173 WriteToString ( writer , hasRed , hasGreen , hasBlue , hasAlpha ) ;
185174 }
0 commit comments