Commits

Anonymous committed c9894b6

implemented "throwNoException" argument

Comments (0)

Files changed (1)

TemplateStrings/TemplateString.cs

                                                    }
 												   
 												   //maybe rewrite to get rid of links to templateValue so that only depend on regex
+												   try
+												   {
 
-                                                   if (match.Groups["escapedstart"].Success)
-                                                   {
-                                                       if (string.IsNullOrEmpty(templateValue.EndDelimiterEscape) ||
-                                                           match.Groups["escapedend"].Success)
-                                                           return templateValue.StartDelimiter + match.Groups["named"] +
-                                                                  templateValue.EndDelimiter;
-                                                       else if (match.Groups["end"].Success)
-                                                           return templateValue.StartDelimiter +
-                                                                  GetValueFromDictionary(mapping,
-                                                                                         match.Groups["named"].Value);
-                                                   }
+													   if (match.Groups["escapedstart"].Success)
+													   {
+														   if (string.IsNullOrEmpty(templateValue.EndDelimiterEscape) ||
+															   match.Groups["escapedend"].Success)
+															   return templateValue.StartDelimiter + match.Groups["named"] +
+																	  templateValue.EndDelimiter;
+														   else if (match.Groups["end"].Success)
+															   return templateValue.StartDelimiter +
+																	  GetValueFromDictionary(mapping,
+																							 match.Groups["named"].Value);
+													   }
 
-                                                   if (match.Groups["escapedend"].Success)
-                                                   {
-                                                       if (string.IsNullOrEmpty(templateValue.StartDelimiterEscape) ||
-                                                           match.Groups["escapedstart"].Success)
-                                                           return templateValue.StartDelimiter + match.Groups["named"] +
-                                                                  templateValue.EndDelimiter;
-                                                       else if (match.Groups["start"].Success)
-                                                           return GetValueFromDictionary(mapping,
-                                                                                         match.Groups["named"].Value) +
-                                                                  templateValue.EndDelimiter;
-                                                   }
+													   if (match.Groups["escapedend"].Success)
+													   {
+														   if (string.IsNullOrEmpty(templateValue.StartDelimiterEscape) ||
+															   match.Groups["escapedstart"].Success)
+															   return templateValue.StartDelimiter + match.Groups["named"] +
+																	  templateValue.EndDelimiter;
+														   else if (match.Groups["start"].Success)
+															   return GetValueFromDictionary(mapping,
+																							 match.Groups["named"].Value) +
+																	  templateValue.EndDelimiter;
+													   }
 
-                                                   if (match.Groups["start"].Success)
-                                                   {
-                                                       if (string.IsNullOrEmpty(templateValue.EndDelimiter) ||
-                                                           match.Groups["end"].Success)
-                                                           return GetValueFromDictionary(mapping,
-                                                                                         match.Groups["named"].Value);
-                                                       else if (match.Groups["escapedend"].Success)
-                                                           return
-                                                               GetValueFromDictionary(mapping,
-                                                                                      match.Groups["named"].Value) +
-                                                               templateValue.EndDelimiter;
-                                                   }
+													   if (match.Groups["start"].Success)
+													   {
+														   if (string.IsNullOrEmpty(templateValue.EndDelimiter) ||
+															   match.Groups["end"].Success)
+															   return GetValueFromDictionary(mapping,
+																							 match.Groups["named"].Value);
+														   else if (match.Groups["escapedend"].Success)
+															   return
+																   GetValueFromDictionary(mapping,
+																						  match.Groups["named"].Value) +
+																   templateValue.EndDelimiter;
+													   }
 
-                                                   if (match.Groups["end"].Success)
-                                                   {
-                                                       if (string.IsNullOrEmpty(templateValue.StartDelimiter) ||
-                                                           match.Groups["start"].Success)
-                                                           return GetValueFromDictionary(mapping,
-                                                                                         match.Groups["named"].Value);
-                                                       else if (match.Groups["escapedstart"].Success)
-                                                           return templateValue.StartDelimiter +
-                                                                  GetValueFromDictionary(mapping,
-                                                                                         match.Groups["named"].Value);
-                                                   }
+													   if (match.Groups["end"].Success)
+													   {
+														   if (string.IsNullOrEmpty(templateValue.StartDelimiter) ||
+															   match.Groups["start"].Success)
+															   return GetValueFromDictionary(mapping,
+																							 match.Groups["named"].Value);
+														   else if (match.Groups["escapedstart"].Success)
+															   return templateValue.StartDelimiter +
+																	  GetValueFromDictionary(mapping,
+																							 match.Groups["named"].Value);
+													   }
+													   
+												}
+												catch(KeyNotFoundException)
+												{
+													if(throwNoException)
+														return match.Value;
+												
+													throw;
+												}
 
                                                    //what if value not in dictionary but escaped startdelimiter