11using System ;
22using System . Collections . Generic ;
33using System . Data ;
4- using System . Text ;
54using System . Xml ;
65using SmartSql . AutoConverter ;
76using SmartSql . Cache ;
8- using SmartSql . Cache . Default ;
97using SmartSql . Configuration ;
108using SmartSql . Configuration . Tags ;
119using SmartSql . DataSource ;
1210using SmartSql . Exceptions ;
13- using SmartSql . Reflection ;
14- using SmartSql . Reflection . TypeConstants ;
1511
1612namespace SmartSql . ConfigBuilder
1713{
@@ -110,48 +106,48 @@ private void BuildCache(XmlElement cacheNode)
110106 switch ( childNode . Name )
111107 {
112108 case "Property" :
113- {
114- childNode . Attributes . TryGetValueAsString ( "Name" , out var name , SmartSqlConfig . Properties ) ;
115- childNode . Attributes . TryGetValueAsString ( "Value" , out var propVal , SmartSqlConfig . Properties ) ;
116- cache . Parameters . Add ( name , propVal ) ;
117- break ;
118- }
109+ {
110+ childNode . Attributes . TryGetValueAsString ( "Name" , out var name , SmartSqlConfig . Properties ) ;
111+ childNode . Attributes . TryGetValueAsString ( "Value" , out var propVal , SmartSqlConfig . Properties ) ;
112+ cache . Parameters . Add ( name , propVal ) ;
113+ break ;
114+ }
119115
120116 case "FlushInterval" :
121- {
122- childNode . Attributes . TryGetValueAsInt32 ( "Hours" , out var hours , SmartSqlConfig . Properties ) ;
123- childNode . Attributes . TryGetValueAsInt32 ( "Minutes" , out var minutes , SmartSqlConfig . Properties ) ;
124- childNode . Attributes . TryGetValueAsInt32 ( "Seconds" , out var seconds , SmartSqlConfig . Properties ) ;
125- cache . FlushInterval = new FlushInterval
126117 {
127- Hours = hours ,
128- Minutes = minutes ,
129- Seconds = seconds
130- } ;
118+ childNode . Attributes . TryGetValueAsInt32 ( "Hours" , out var hours , SmartSqlConfig . Properties ) ;
119+ childNode . Attributes . TryGetValueAsInt32 ( "Minutes" , out var minutes , SmartSqlConfig . Properties ) ;
120+ childNode . Attributes . TryGetValueAsInt32 ( "Seconds" , out var seconds , SmartSqlConfig . Properties ) ;
121+ cache . FlushInterval = new FlushInterval
122+ {
123+ Hours = hours ,
124+ Minutes = minutes ,
125+ Seconds = seconds
126+ } ;
131127
132- cache . Parameters . Add ( "FlushInterval" , cache . FlushInterval ) ;
133- break ;
134- }
128+ cache . Parameters . Add ( "FlushInterval" , cache . FlushInterval ) ;
129+ break ;
130+ }
135131
136132 case "FlushOnExecute" :
137- {
138- childNode . Attributes . TryGetValueAsString ( "Statement" , out var statementId ,
139- SmartSqlConfig . Properties ) ;
140- if ( ! String . IsNullOrEmpty ( statementId ) )
141133 {
142- if ( statementId . IndexOf ( '.' ) < 0 )
134+ childNode . Attributes . TryGetValueAsString ( "Statement" , out var statementId ,
135+ SmartSqlConfig . Properties ) ;
136+ if ( ! String . IsNullOrEmpty ( statementId ) )
143137 {
144- statementId = $ "{ SqlMap . Scope } .{ statementId } ";
138+ if ( statementId . IndexOf ( '.' ) < 0 )
139+ {
140+ statementId = $ "{ SqlMap . Scope } .{ statementId } ";
141+ }
142+
143+ cache . FlushOnExecutes . Add ( new FlushOnExecute
144+ {
145+ Statement = statementId
146+ } ) ;
145147 }
146148
147- cache . FlushOnExecutes . Add ( new FlushOnExecute
148- {
149- Statement = statementId
150- } ) ;
149+ break ;
151150 }
152-
153- break ;
154- }
155151 }
156152 }
157153
@@ -206,6 +202,16 @@ private void BuildParameters(XmlElement xmlNode, ParameterMap parameterMap)
206202 {
207203 Property = property
208204 } ;
205+
206+ if ( parameterNode . Attributes . TryGetValueAsString ( "DbType" , out var dbTypeStr ,
207+ SmartSqlConfig . Properties ) )
208+ {
209+ if ( Enum . TryParse ( dbTypeStr , true , out DbType dbType ) )
210+ {
211+ parameter . DbType = dbType ;
212+ }
213+ }
214+
209215 if ( parameterNode . Attributes . TryGetValueAsString ( "TypeHandler" , out var handlerName ,
210216 SmartSqlConfig . Properties ) )
211217 {
@@ -263,7 +269,7 @@ private void BuildResultCtor(XmlElement xmlNode, ResultMap resultMap)
263269 argNode . Attributes . TryGetValueAsString ( nameof ( Arg . Column ) , out var column , SmartSqlConfig . Properties ) ;
264270 argNode . Attributes . TryGetValueAsString ( nameof ( Arg . CSharpType ) , out var argTypeStr ,
265271 SmartSqlConfig . Properties ) ;
266- var arg = new Arg { Column = column , CSharpType = ArgTypeConvert ( argTypeStr ) } ;
272+ var arg = new Arg { Column = column , CSharpType = ArgTypeConvert ( argTypeStr ) } ;
267273 ctorMap . Args . Add ( arg ) ;
268274 }
269275
@@ -275,89 +281,89 @@ private static Type ArgTypeConvert(string typeStr)
275281 switch ( typeStr )
276282 {
277283 case "Boolean" :
278- {
279- return typeof ( Boolean ) ;
280- }
284+ {
285+ return typeof ( Boolean ) ;
286+ }
281287
282288 case "Char" :
283- {
284- return typeof ( Char ) ;
285- }
289+ {
290+ return typeof ( Char ) ;
291+ }
286292
287293 case "SByte" :
288- {
289- return typeof ( SByte ) ;
290- }
294+ {
295+ return typeof ( SByte ) ;
296+ }
291297
292298 case "Byte" :
293- {
294- return typeof ( Byte ) ;
295- }
299+ {
300+ return typeof ( Byte ) ;
301+ }
296302
297303 case "Int16" :
298- {
299- return typeof ( Int16 ) ;
300- }
304+ {
305+ return typeof ( Int16 ) ;
306+ }
301307
302308 case "UInt16" :
303- {
304- return typeof ( UInt16 ) ;
305- }
309+ {
310+ return typeof ( UInt16 ) ;
311+ }
306312
307313 case "Int32" :
308- {
309- return typeof ( Int32 ) ;
310- }
314+ {
315+ return typeof ( Int32 ) ;
316+ }
311317
312318 case "UInt32" :
313- {
314- return typeof ( UInt32 ) ;
315- }
319+ {
320+ return typeof ( UInt32 ) ;
321+ }
316322
317323 case "Int64" :
318- {
319- return typeof ( Int64 ) ;
320- }
324+ {
325+ return typeof ( Int64 ) ;
326+ }
321327
322328 case "UInt64" :
323- {
324- return typeof ( UInt64 ) ;
325- }
329+ {
330+ return typeof ( UInt64 ) ;
331+ }
326332
327333 case "Single" :
328- {
329- return typeof ( Single ) ;
330- }
334+ {
335+ return typeof ( Single ) ;
336+ }
331337
332338 case "Double" :
333- {
334- return typeof ( Double ) ;
335- }
339+ {
340+ return typeof ( Double ) ;
341+ }
336342
337343 case "Decimal" :
338- {
339- return typeof ( Decimal ) ;
340- }
344+ {
345+ return typeof ( Decimal ) ;
346+ }
341347
342348 case "DateTime" :
343- {
344- return typeof ( DateTime ) ;
345- }
349+ {
350+ return typeof ( DateTime ) ;
351+ }
346352
347353 case "String" :
348- {
349- return typeof ( String ) ;
350- }
354+ {
355+ return typeof ( String ) ;
356+ }
351357
352358 case "Guid" :
353- {
354- return typeof ( Guid ) ;
355- }
359+ {
360+ return typeof ( Guid ) ;
361+ }
356362
357363 default :
358- {
359- return Type . GetType ( typeStr , true ) ;
360- }
364+ {
365+ return Type . GetType ( typeStr , true ) ;
366+ }
361367 }
362368 }
363369
@@ -610,21 +616,21 @@ private ITag LoadTag(XmlNode xmlNode, Statement statement)
610616 switch ( xmlNode . Name )
611617 {
612618 case "#comment" :
613- {
614- return null ;
615- }
619+ {
620+ return null ;
621+ }
616622
617623 case "#text" :
618624 case "#cdata-section" :
619- {
620- return SmartSqlConfig . TagBuilderFactory . Get ( xmlNode . Name ) . Build ( xmlNode , statement ) ;
621- }
625+ {
626+ return SmartSqlConfig . TagBuilderFactory . Get ( xmlNode . Name ) . Build ( xmlNode , statement ) ;
627+ }
622628
623629 default :
624- {
625- tag = SmartSqlConfig . TagBuilderFactory . Get ( xmlNode . Name ) . Build ( xmlNode , statement ) ;
626- break ;
627- }
630+ {
631+ tag = SmartSqlConfig . TagBuilderFactory . Get ( xmlNode . Name ) . Build ( xmlNode , statement ) ;
632+ break ;
633+ }
628634 }
629635
630636 #endregion
0 commit comments