@@ -26,20 +26,20 @@ public static class GavinsAlgorithim
2626 //Condition Passed
2727 TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfOperationTrueTemplate , options ) ;
2828 string templatedIfContentMapped = GenerateFromTemplate ( record , templatedIfContent , parameterKeyValues , options ) ;
29- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , templatedIfContentMapped ) ;
29+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( ifCondition . ReplaceRef , templatedIfContentMapped ) ;
3030 }
3131 else if ( ! string . IsNullOrEmpty ( ifCondition . IfOperationFalseTemplate ) )
3232 {
3333 //If Else Condition Block
3434 TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfOperationFalseTemplate , options ) ;
3535 string templatedIfElseContentMapped = GenerateFromTemplate ( record , templatedIfContent , parameterKeyValues , options ) ;
36- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , templatedIfElseContentMapped ) ;
36+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( ifCondition . ReplaceRef , templatedIfElseContentMapped ) ;
3737 }
3838 else
39- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , string . Empty ) ;
39+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( ifCondition . ReplaceRef , string . Empty ) ;
4040 }
4141 else
42- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , $ "[IF-CONDITION EXCEPTION]: unrecognized property: [{ ifCondition . IfPropertyName } ]") ;
42+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( ifCondition . ReplaceRef , $ "[IF-CONDITION EXCEPTION]: unrecognized property: [{ ifCondition . IfPropertyName } ]") ;
4343 }
4444 #endregion
4545
@@ -63,20 +63,19 @@ public static class GavinsAlgorithim
6363 {
6464 ExtractedObjProperty objProperty = rowRecordValues . FirstOrDefault ( x => x . Name . ToUpper ( ) . Equals ( objLoopCode . TargetPropertyName . ToUpper ( ) ) ) ;
6565 if ( objProperty != null )
66- activeRow = ReplaceFirstOccurrence ( activeRow , objLoopCode . ReplaceRef , GetValueFromPropertyFormatted ( objProperty , objLoopCode . FormattingCommand ) ) ;
66+ activeRow = activeRow . ReplaceFirstOccurrence ( objLoopCode . ReplaceRef , objProperty . GetValueFromPropertyFormatted ( objLoopCode . FormattingCommand ) ) ;
6767 else
68- activeRow = ReplaceFirstOccurrence ( activeRow , objLoopCode . ReplaceRef , objLoopCode . ReplaceCommand ) ;
68+ activeRow = activeRow . ReplaceFirstOccurrence ( objLoopCode . ReplaceRef , objLoopCode . ReplaceCommand ) ;
6969 }
7070 //Append Record row
7171 rowContentTemplater . Append ( activeRow ) ;
7272 }
73-
7473 objLoop . ObjLoopTemplate = rowContentTemplater . ToString ( ) . RemoveLastInstanceOfString ( '\r ' , '\n ' ) ; //Assign Auto Generated
7574 //Replace the main Loop area
76- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , objLoop . ReplaceRef , objLoop . ObjLoopTemplate ) ;
75+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( objLoop . ReplaceRef , objLoop . ObjLoopTemplate ) ;
7776 }
7877 else
79- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , objLoop . ReplaceRef , string . Empty ) ;
78+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( objLoop . ReplaceRef , string . Empty ) ;
8079
8180 }
8281 #endregion
@@ -86,9 +85,9 @@ public static class GavinsAlgorithim
8685 {
8786 ExtractedObjProperty property = objProperties . FirstOrDefault ( x => x . Name . ToUpper ( ) . Equals ( replaceCode . TargetPropertyName . ToUpper ( ) ) ) ;
8887 if ( property != null )
89- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , replaceCode . ReplaceRef , GetValueFromPropertyFormatted ( property , replaceCode . FormattingCommand ) ) ;
88+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( replaceCode . ReplaceRef , property . GetValueFromPropertyFormatted ( replaceCode . FormattingCommand ) ) ;
9089 else
91- clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , replaceCode . ReplaceRef , @"{{ ##command## }}" . Replace ( "##command##" , replaceCode . ReplaceCommand ) ) ;
90+ clonedTemplate . Template = clonedTemplate . Template . ReplaceFirstOccurrence ( replaceCode . ReplaceRef , @"{{ ##command## }}" . Replace ( "##command##" , replaceCode . ReplaceCommand ) ) ;
9291 }
9392 #endregion
9493 return clonedTemplate . Template ;
@@ -184,13 +183,7 @@ internal static TemplatedContent GenerateTemplateFromFileContents(string fileCon
184183 return templatedContent ;
185184 }
186185
187- private static string ReplaceFirstOccurrence ( this string text , string search , string replace )
188- {
189- int pos = text . IndexOf ( search ) ;
190- if ( pos < 0 )
191- return text ;
192- return string . Format ( "{0}{1}{2}" , text . Substring ( 0 , pos ) , replace , text . Substring ( pos + search . Length ) ) ;
193- }
186+
194187 private static List < ExtractedObjProperty > GetObjectProperties < T > ( T value , List < ObjectSemanticsKeyValue > parameters = null ) where T : new ( )
195188 {
196189 List < ExtractedObjProperty > extractedObjProperties = new List < ExtractedObjProperty > ( ) ;
@@ -236,28 +229,5 @@ private static List<ExtractedObjProperty> GetObjPropertiesFromUnknown(object val
236229 return list ;
237230 }
238231
239- private static string GetValueFromPropertyFormatted ( ExtractedObjProperty p , string customFormattingValue )
240- {
241- if ( string . IsNullOrWhiteSpace ( customFormattingValue ) )
242- return p . StringFormatted ;
243- if ( p . Type . Equals ( typeof ( int ) ) )
244- return int . Parse ( p . StringFormatted ) . ToString ( customFormattingValue ) ;
245- else if ( p . Type . Equals ( typeof ( double ) ) )
246- return double . Parse ( p . StringFormatted ) . ToString ( customFormattingValue ) ;
247- else if ( p . Type . Equals ( typeof ( long ) ) )
248- return long . Parse ( p . StringFormatted ) . ToString ( customFormattingValue ) ;
249- else if ( p . Type . Equals ( typeof ( float ) ) )
250- return float . Parse ( p . StringFormatted ) . ToString ( customFormattingValue ) ;
251- else if ( p . Type . Equals ( typeof ( decimal ) ) )
252- return decimal . Parse ( p . StringFormatted ) . ToString ( customFormattingValue ) ;
253- else if ( p . Type . Equals ( typeof ( DateTime ) ) )
254- return DateTime . Parse ( p . StringFormatted ) . ToString ( customFormattingValue ) ;
255- //Custom Formats
256- else if ( customFormattingValue . ToLower ( ) . Equals ( "uppercase" ) )
257- return p . StringFormatted ? . ToUpper ( ) ;
258- else if ( customFormattingValue . ToLower ( ) . Equals ( "lowercase" ) )
259- return p . StringFormatted ? . ToLower ( ) ;
260- else
261- return p . StringFormatted ? . ToUpper ( ) ;
262- }
232+
263233}
0 commit comments