33using  OpenQA . Selenium . DevToolsGenerator . ProtocolDefinition ; 
44using  System ; 
55using  System . Collections . Generic ; 
6+ using  System . Data ; 
67using  System . IO ; 
78using  System . Linq ; 
89
@@ -22,7 +23,7 @@ public override IDictionary<string, string> GenerateCode(ProtocolDefinition.Prot
2223        { 
2324            if  ( string . IsNullOrWhiteSpace ( Settings . TemplatesPath ) ) 
2425            { 
25-                 Settings . TemplatesPath  =  Path . GetDirectoryName ( Settings . TemplatesPath ) ; 
26+                 Settings . TemplatesPath  =  Path . GetDirectoryName ( Settings . TemplatesPath ) ! ; 
2627            } 
2728
2829            ICollection < DomainDefinition >  domains  =  protocolDefinition . Domains ; 
@@ -44,11 +45,11 @@ public override IDictionary<string, string> GenerateCode(ProtocolDefinition.Prot
4445                foreach  ( var  command  in  domain . Commands ) 
4546                { 
4647                    commands . Add ( new  CommandInfo 
47-                     { 
48-                         CommandName   =  $ "{ domain . Name } .{ command . Name } ", 
49-                         FullTypeName   =  $ "{ domain . Name . Dehumanize ( ) } .{ command . Name . Dehumanize ( ) } CommandSettings", 
50-                         FullResponseTypeName   =  $ "{ domain . Name . Dehumanize ( ) } .{ command . Name . Dehumanize ( ) } CommandResponse"
51-                     } ) ; 
48+                     ( 
49+                         commandName :  $ "{ domain . Name } .{ command . Name } ", 
50+                         fullTypeName :  $ "{ domain . Name . Dehumanize ( ) } .{ command . Name . Dehumanize ( ) } CommandSettings", 
51+                         fullResponseTypeName :  $ "{ domain . Name . Dehumanize ( ) } .{ command . Name . Dehumanize ( ) } CommandResponse"
52+                     ) ) ; 
5253                } 
5354            } 
5455
@@ -60,10 +61,10 @@ public override IDictionary<string, string> GenerateCode(ProtocolDefinition.Prot
6061                foreach  ( var  @event  in  domain . Events ) 
6162                { 
6263                    events . Add ( new  EventInfo 
63-                     { 
64-                         EventName   =  $ "{ domain . Name } .{ @event . Name } ", 
65-                         FullTypeName   =   $ "{ domain . Name . Dehumanize ( ) } .{ @event . Name . Dehumanize ( ) } EventArgs"
66-                     } ) ; 
64+                     ( 
65+                         eventName :  $ "{ domain . Name } .{ @event . Name } ", 
66+                         fullTypeName :   $ "{ domain . Name . Dehumanize ( ) } .{ @event . Name . Dehumanize ( ) } EventArgs") 
67+                     ) ; 
6768                } 
6869            } 
6970
@@ -102,7 +103,7 @@ public override IDictionary<string, string> GenerateCode(ProtocolDefinition.Prot
102103            return  result ; 
103104        } 
104105
105-         private  Dictionary < string ,  TypeInfo >  GetTypesInDomain ( ICollection < DomainDefinition >  domains ) 
106+         private  static   Dictionary < string ,  TypeInfo >  GetTypesInDomain ( ICollection < DomainDefinition >  domains ) 
106107        { 
107108            var  knownTypes  =  new  Dictionary < string ,  TypeInfo > ( StringComparer . OrdinalIgnoreCase ) ; 
108109
@@ -116,9 +117,9 @@ private Dictionary<string, TypeInfo> GetTypesInDomain(ICollection<DomainDefiniti
116117                    { 
117118                        if  ( propertyType . Type  ==  "string"  &&  type . Enum  !=  null  &&  propertyType . Enum . Count  >  0 ) 
118119                        { 
119-                             TypeDefinition  propertyTypeDefinition  =  new  TypeDefinition ( ) 
120+                             string  id  =  $ "{ type . Id . Dehumanize ( ) } { propertyType . Name . Dehumanize ( ) } Values"; 
121+                             TypeDefinition  propertyTypeDefinition  =  new  TypeDefinition ( id ) 
120122                            { 
121-                                 Id  =  type . Id . Dehumanize ( )  +  propertyType . Name . Dehumanize ( )  +  "Values" , 
122123                                Type  =  propertyType . Type , 
123124                                Description  =  $ "Enumerated values for { domain . Name } .{ type . Id } .{ propertyType . Name } "
124125                            } ; 
@@ -136,35 +137,33 @@ private Dictionary<string, TypeInfo> GetTypesInDomain(ICollection<DomainDefiniti
136137                    switch  ( type . Type ) 
137138                    { 
138139                        case  "object" : 
139-                             typeInfo  =  new  TypeInfo 
140-                             { 
141-                                 IsPrimitive  =  false , 
142-                                 TypeName  =  type . Id . Dehumanize ( ) , 
143-                             } ; 
140+                             typeInfo  =  new  TypeInfo ( typeName :  type . Id . Dehumanize ( ) ,  isPrimitive :  false ) ; 
144141                            break ; 
142+ 
145143                        case  "string" : 
146144                            if  ( type . Enum  !=  null  &&  type . Enum . Count  >  0 ) 
147145                            { 
148-                                 typeInfo  =  new  TypeInfo 
146+                                 typeInfo  =  new  TypeInfo ( typeName :   type . Id . Dehumanize ( ) ,   isPrimitive :   false ) 
149147                                { 
150148                                    ByRef  =  true , 
151-                                     IsPrimitive  =  false , 
152-                                     TypeName  =  type . Id . Dehumanize ( ) , 
153149                                } ; 
154150                            } 
155151                            else 
156152                            { 
157-                                 typeInfo  =  new  TypeInfo 
158-                                 { 
159-                                     IsPrimitive  =  true , 
160-                                     TypeName  =  "string" 
161-                                 } ; 
153+                                 typeInfo  =  new  TypeInfo ( "string" ,  isPrimitive :  true ) ; 
162154                            } 
163155
164156                            break ; 
157+ 
165158                        case  "array" : 
166-                             if  ( ( type . Items  ==  null  ||  string . IsNullOrWhiteSpace ( type . Items . Type ) )  && 
167-                                 type . Items . TypeReference  !=  "StringIndex"  &&  type . Items . TypeReference  !=  "FilterEntry" ) 
159+                             if  ( type . Items  is  null ) 
160+                             { 
161+                                 throw  new  InvalidOperationException ( "Type definition's Type was array but Items is missing" ) ; 
162+                             } 
163+ 
164+                             if  ( string . IsNullOrWhiteSpace ( type . Items . Type )  && 
165+                                 type . Items . TypeReference  !=  "StringIndex"  && 
166+                                 type . Items . TypeReference  !=  "FilterEntry" ) 
168167                            { 
169168                                throw  new  NotImplementedException ( "Did not expect a top-level domain array type to specify a TypeReference" ) ; 
170169                            } 
@@ -199,28 +198,23 @@ private Dictionary<string, TypeInfo> GetTypesInDomain(ICollection<DomainDefiniti
199198                                default : 
200199                                    throw  new  NotImplementedException ( $ "Did not expect a top-level domain array type to specify items of type { type . Items . Type } ") ; 
201200                            } 
202-                             typeInfo  =  new  TypeInfo 
203-                             { 
204-                                 IsPrimitive  =  true , 
205-                                 TypeName  =  $ "{ itemType } []"
206-                             } ; 
201+                             typeInfo  =  new  TypeInfo ( typeName :  $ "{ itemType } []",  isPrimitive :  true ) ; 
207202                            break ; 
203+ 
208204                        case  "number" : 
209-                             typeInfo  =  new  TypeInfo 
205+                             typeInfo  =  new  TypeInfo ( "double" ,   isPrimitive :   true ) 
210206                            { 
211207                                ByRef  =  true , 
212-                                 IsPrimitive  =  true , 
213-                                 TypeName  =  "double" 
214208                            } ; 
215209                            break ; 
210+ 
216211                        case  "integer" : 
217-                             typeInfo  =  new  TypeInfo 
212+                             typeInfo  =  new  TypeInfo ( "long" ,   isPrimitive :   true ) 
218213                            { 
219214                                ByRef  =  true , 
220-                                 IsPrimitive  =  true , 
221-                                 TypeName  =  "long" 
222215                            } ; 
223216                            break ; 
217+ 
224218                        default : 
225219                            throw  new  InvalidOperationException ( $ "Unknown Type Definition Type: { type . Id } ") ; 
226220                    } 
@@ -232,11 +226,9 @@ private Dictionary<string, TypeInfo> GetTypesInDomain(ICollection<DomainDefiniti
232226
233227                foreach  ( var  embeddedEnumType  in  embeddedTypes ) 
234228                { 
235-                     TypeInfo  propertyTypeInfo  =  new  TypeInfo 
229+                     TypeInfo  propertyTypeInfo  =  new  TypeInfo ( typeName :   embeddedEnumType . Id ,   isPrimitive :   false ) 
236230                    { 
237-                         TypeName  =  embeddedEnumType . Id , 
238231                        ByRef  =  true , 
239-                         IsPrimitive  =  false , 
240232                        Namespace  =  domain . Name . Dehumanize ( ) , 
241233                        SourcePath  =  $ "{ domain . Name } .{ embeddedEnumType . Id } "
242234                    } ; 
@@ -257,7 +249,7 @@ private Dictionary<string, string> GenerateCode(ICollection<DomainDefinition> do
257249            //Generate types/events/commands for all domains. 
258250            foreach  ( var  domain  in  domains ) 
259251            { 
260-                 var  context  =  new  CodeGeneratorContext   {   Domain   =   domain ,  KnownTypes   =   knownTypes   } ; 
252+                 var  context  =  new  CodeGeneratorContext ( domain ,  knownTypes ) ; 
261253                foreach  ( KeyValuePair < string ,  string >  x  in  domainGenerator . GenerateCode ( domain ,  context ) ) 
262254                { 
263255                    result . Add ( x . Key ,  x . Value ) ; 
0 commit comments