@@ -24,10 +24,17 @@ public static class GavinsAlgorithim
24
24
if ( property . IsPropertyValueConditionPassed ( ifCondition . IfConditionValue , ifCondition . IfConditionType ) )
25
25
{
26
26
//Condition Passed
27
- TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfConditionTemplate , options ) ;
27
+ TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfConditionTrueTemplate , options ) ;
28
28
string templatedIfContentMapped = GenerateFromTemplate ( record , templatedIfContent , parameterKeyValues , options ) ;
29
29
clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , templatedIfContentMapped ) ;
30
30
}
31
+ else if ( ! string . IsNullOrEmpty ( ifCondition . IfConditionFalseTemplate ) )
32
+ {
33
+ //If Else Condition Block
34
+ TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfConditionFalseTemplate , options ) ;
35
+ string templatedIfElseContentMapped = GenerateFromTemplate ( record , templatedIfContent , parameterKeyValues , options ) ;
36
+ clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , templatedIfElseContentMapped ) ;
37
+ }
31
38
else
32
39
clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , string . Empty ) ;
33
40
}
@@ -99,14 +106,17 @@ internal static TemplatedContent GenerateTemplateFromFileContents(string fileCon
99
106
string subBlock = templatedContent . Template . GetSubstringByIndexStartAndEnd ( regexIfConditionMatch . Index + regexIfConditionMatch . Length , regexIfConditionMatchEnd . Index - 1 ) ;
100
107
//#Replace Template Block with unique Code
101
108
templatedContent . Template = templatedContent . Template . ReplaceByIndexStartAndEnd ( regexIfConditionMatch . Index , ( regexIfConditionMatchEnd . Index - 1 ) + regexIfConditionMatchEnd . Length , _replaceCode ) ;
109
+ //Determine if subBlock has Else Condition
110
+ string [ ] elseIfSplits = Regex . Split ( subBlock , @"{{\s*else-if\s*}}" , RegexOptions . IgnoreCase ) ;
102
111
//#Append Condition Code
103
112
templatedContent . ReplaceIfConditionCodes . Add ( new ReplaceIfConditionCode
104
113
{
105
114
ReplaceRef = _replaceCode ,
106
- IfPropertyName = ( regexIfConditionMatch . Groups . Count >= 1 ) ? regexIfConditionMatch . Groups [ 1 ] . Value ? . Trim ( ) ? . ToString ( ) ? . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
107
- IfConditionType = ( regexIfConditionMatch . Groups . Count >= 2 ) ? regexIfConditionMatch . Groups [ 2 ] . Value ? . Trim ( ) ? . ToString ( ) ? . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
108
- IfConditionValue = ( regexIfConditionMatch . Groups . Count >= 3 ) ? regexIfConditionMatch . Groups [ 3 ] . Value ? . Trim ( ) ? . ToString ( ) ? . ToLower ( ) : "unspecified" ,
109
- IfConditionTemplate = subBlock
115
+ IfPropertyName = ( regexIfConditionMatch . Groups . Count >= 1 ) ? regexIfConditionMatch . Groups [ 1 ] . Value ? . ToString ( ) . Trim ( ) . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
116
+ IfConditionType = ( regexIfConditionMatch . Groups . Count >= 2 ) ? regexIfConditionMatch . Groups [ 2 ] . Value ? . ToString ( ) . Trim ( ) . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
117
+ IfConditionValue = ( regexIfConditionMatch . Groups . Count >= 3 ) ? regexIfConditionMatch . Groups [ 3 ] . Value ? . ToString ( ) ? . Trim ( ) . ToLower ( ) : "unspecified" ,
118
+ IfConditionTrueTemplate = ( elseIfSplits ? . Length >= 2 ) ? elseIfSplits [ 0 ] : subBlock ,
119
+ IfConditionFalseTemplate = ( elseIfSplits ? . Length >= 2 ) ? elseIfSplits [ 1 ] : string . Empty
110
120
} ) ;
111
121
//Move Next (Both)
112
122
regexIfConditionMatch = regexIfConditionMatch . NextMatch ( ) ;
0 commit comments