1010
1111namespace schema . util . types ;
1212
13- public enum SchemaTypeKind {
14- BOOL ,
15- INTEGER ,
16- FLOAT ,
17- CHAR ,
18- STRING ,
19- ENUM ,
20- CONTAINER ,
21- GENERIC ,
22- SEQUENCE ,
23- }
24-
25- public interface ITypeInfo ;
26-
27- public interface IPrimitiveTypeInfo : ITypeInfo ;
28-
29- public interface IBoolTypeInfo : IPrimitiveTypeInfo ;
30-
31- public interface INumberTypeInfo : IPrimitiveTypeInfo ;
32-
33- public interface IIntegerTypeInfo : INumberTypeInfo ;
34-
35- public interface IEnumTypeInfo : IPrimitiveTypeInfo ;
36-
37- public interface ICharTypeInfo : IPrimitiveTypeInfo ;
38-
39- public interface IStringTypeInfo : ITypeInfo ;
40-
41- public interface IContainerTypeInfo : ITypeInfo ;
42-
43- public interface IGenericTypeInfo : ITypeInfo ;
44-
45- public interface ISequenceTypeInfo : ITypeInfo ;
46-
4713public class TypeInfoParser {
4814 public enum ParseStatus {
4915 SUCCESS ,
5016 NOT_A_FIELD_OR_PROPERTY_OR_METHOD ,
5117 NOT_IMPLEMENTED ,
5218 }
5319
54- public IEnumerable < ( ParseStatus , ISymbol , ITypeSymbol , ITypeInfo ? ) >
55- ParseMembers (
56- INamedTypeSymbol containerSymbol ) {
20+ public IEnumerable < ( ParseStatus , ISymbol ) > ParseMembers (
21+ INamedTypeSymbol containerSymbol ) {
5722 foreach ( var memberSymbol in containerSymbol . GetInstanceMembers ( ) ) {
5823 // Tries to parse the type to get info about it
59- var parseStatus = this . ParseMember (
60- memberSymbol ,
61- out var memberTypeSymbol ,
62- out var memberTypeInfo ) ;
63- yield return ( parseStatus , memberSymbol , memberTypeSymbol ,
64- memberTypeInfo ) ;
24+ var parseStatus = this . ParseMember ( memberSymbol ) ;
25+ yield return ( parseStatus , memberSymbol ) ;
6526 }
6627 }
6728
68- public ParseStatus ParseMember ( ISymbol memberSymbol ,
69- out ITypeSymbol ? memberTypeSymbol ,
70- out ITypeInfo ? memberTypeInfo ) {
71- memberTypeSymbol = null ;
72- memberTypeInfo = null ;
73-
29+ public ParseStatus ParseMember ( ISymbol memberSymbol ) {
7430 if ( memberSymbol is IMethodSymbol ) {
7531 return ParseStatus . SUCCESS ;
7632 }
7733
7834 if ( ! GetTypeOfMember_ (
7935 memberSymbol ,
80- out memberTypeSymbol ,
36+ out var memberTypeSymbol ,
8137 out var isReadonly ) ) {
8238 return ParseStatus . NOT_A_FIELD_OR_PROPERTY_OR_METHOD ;
8339 }
@@ -88,22 +44,15 @@ public ParseStatus ParseMember(ISymbol memberSymbol,
8844 return ParseStatus . NOT_A_FIELD_OR_PROPERTY_OR_METHOD ;
8945 }
9046
91- return this . ParseTypeSymbol (
92- memberTypeSymbol ,
93- isReadonly ,
94- out memberTypeInfo ) ;
47+ return this . ParseTypeSymbol ( memberTypeSymbol , isReadonly ) ;
9548 }
9649
97- public ParseStatus ParseTypeSymbol (
98- ITypeSymbol typeSymbol ,
99- bool isReadonly ,
100- out ITypeInfo typeInfo ) {
50+ public ParseStatus ParseTypeSymbol ( ITypeSymbol typeSymbol , bool isReadonly ) {
10151 this . ParseNullable_ ( ref typeSymbol ) ;
10252
10353 if ( typeSymbol . IsPrimitive ( out var primitiveType ) ) {
10454 switch ( primitiveType ) {
10555 case SchemaPrimitiveType . BOOLEAN : {
106- typeInfo = new BoolTypeInfo ( ) ;
10756 return ParseStatus . SUCCESS ;
10857 }
10958 case SchemaPrimitiveType . BYTE :
@@ -114,7 +63,6 @@ public ParseStatus ParseTypeSymbol(
11463 case SchemaPrimitiveType . UINT32 :
11564 case SchemaPrimitiveType . INT64 :
11665 case SchemaPrimitiveType . UINT64 : {
117- typeInfo = new IntegerTypeInfo ( ) ;
11866 return ParseStatus . SUCCESS ;
11967 }
12068 case SchemaPrimitiveType . SN8 :
@@ -123,67 +71,47 @@ public ParseStatus ParseTypeSymbol(
12371 case SchemaPrimitiveType . UN16 :
12472 case SchemaPrimitiveType . SINGLE :
12573 case SchemaPrimitiveType . DOUBLE : {
126- typeInfo = new FloatTypeInfo ( ) ;
12774 return ParseStatus . SUCCESS ;
12875 }
12976 case SchemaPrimitiveType . CHAR : {
130- typeInfo = new CharTypeInfo ( ) ;
13177 return ParseStatus . SUCCESS ;
13278 }
13379 case SchemaPrimitiveType . ENUM : {
134- typeInfo = new EnumTypeInfo ( ) ;
13580 return ParseStatus . SUCCESS ;
13681 }
13782 default : throw new ArgumentOutOfRangeException ( ) ;
13883 }
13984 }
14085
14186 if ( typeSymbol . IsString ( ) ) {
142- typeInfo = new StringTypeInfo ( ) ;
14387 return ParseStatus . SUCCESS ;
14488 }
14589
14690 if ( typeSymbol . IsSequence ( out var elementTypeV2 , out var sequenceType ) ) {
14791 var elementParseStatus = this . ParseTypeSymbol (
14892 elementTypeV2 ,
149- sequenceType . IsReadOnly ( ) ,
150- out _ ) ;
93+ sequenceType . IsReadOnly ( ) ) ;
15194 if ( elementParseStatus != ParseStatus . SUCCESS ) {
152- typeInfo = default ;
15395 return elementParseStatus ;
15496 }
15597
156- typeInfo = new SequenceTypeInfo ( ) ;
15798 return ParseStatus . SUCCESS ;
15899 }
159100
160101 if ( typeSymbol . IsClass ( ) ||
161102 typeSymbol . IsInterface ( ) ||
162103 typeSymbol . IsStruct ( ) ||
163104 typeSymbol is IErrorTypeSymbol ) {
164- typeInfo = new ContainerTypeInfo ( ) ;
165105 return ParseStatus . SUCCESS ;
166106 }
167107
168108 if ( typeSymbol . IsGenericTypeParameter ( out _ ) ) {
169- typeInfo = new GenericTypeInfo ( ) ;
170109 return ParseStatus . SUCCESS ;
171110 }
172111
173- typeInfo = default ;
174112 return ParseStatus . NOT_IMPLEMENTED ;
175113 }
176114
177- public ITypeInfo AssertParseType ( ITypeSymbol typeSymbol ) {
178- var parseStatus
179- = this . ParseTypeSymbol ( typeSymbol , true , out var typeInfo ) ;
180- if ( parseStatus != ParseStatus . SUCCESS ) {
181- throw new NotImplementedException ( ) ;
182- }
183-
184- return typeInfo ;
185- }
186-
187115 private bool GetTypeOfMember_ (
188116 ISymbol memberSymbol ,
189117 out ITypeSymbol memberTypeSymbol ,
@@ -215,14 +143,4 @@ private void ParseNullable_(ref ITypeSymbol typeSymbol) {
215143 Asserts . True ( typeSymbol . IsGeneric ( out _ , out var genericArguments ) ) ;
216144 typeSymbol = genericArguments . ToArray ( ) [ 0 ] ;
217145 }
218-
219- private record BoolTypeInfo : IBoolTypeInfo ;
220- private class FloatTypeInfo : INumberTypeInfo ;
221- private record IntegerTypeInfo : IIntegerTypeInfo ;
222- private record CharTypeInfo : ICharTypeInfo ;
223- private record StringTypeInfo : IStringTypeInfo ;
224- private class EnumTypeInfo : IEnumTypeInfo ;
225- private class ContainerTypeInfo : IContainerTypeInfo ;
226- private class GenericTypeInfo : IGenericTypeInfo ;
227- private class SequenceTypeInfo : ISequenceTypeInfo ;
228146}
0 commit comments