Inheritance: AttributeTransform
 protected static string SubstituteKownValue(string transformValue, Regex patternRegex, string patternPrefix, SetTokenizedAttributes.GetValueCallback getValueDelegate)
 {
     int num1 = 0;
     List<System.Text.RegularExpressions.Match> list = new List<System.Text.RegularExpressions.Match>();
     do
     {
         num1 = transformValue.IndexOf(patternPrefix, num1, StringComparison.OrdinalIgnoreCase);
         if (num1 > -1)
         {
             System.Text.RegularExpressions.Match match = patternRegex.Match(transformValue, num1);
             if (match.Success)
             {
                 list.Add(match);
                 num1 = match.Index + match.Length;
             }
             else
                 ++num1;
         }
     }
     while (num1 > -1);
     StringBuilder stringBuilder = new StringBuilder(transformValue.Length);
     if (list.Count > 0)
     {
         stringBuilder.Remove(0, stringBuilder.Length);
         int startIndex = 0;
         int num2 = 0;
         foreach (System.Text.RegularExpressions.Match match in list)
         {
             stringBuilder.Append(transformValue.Substring(startIndex, match.Index - startIndex));
             string key = match.Groups["tagname"].Value;
             string str = getValueDelegate(key);
             if (str != null)
                 stringBuilder.Append(str);
             else
                 stringBuilder.Append(match.Value);
             startIndex = match.Index + match.Length;
             ++num2;
         }
         stringBuilder.Append(transformValue.Substring(startIndex));
         transformValue = ((object)stringBuilder).ToString();
     }
     return transformValue;
 }
示例#2
0
        private string TokenizeValue(XmlAttribute targetAttribute, XmlAttribute transformAttribute, bool fTokenizeParameter, List <Dictionary <string, string> > parameters)
        {
            this.tokenizeValueCurrentXmlAttribute = transformAttribute;
            string transformValue    = transformAttribute.Value;
            string xpathToAttribute1 = this.GetXPathToAttribute(targetAttribute);
            string input             = SetTokenizedAttributes.SubstituteKownValue(transformValue, SetTokenizedAttributes.ParentAttributeRegex, "$(", (SetTokenizedAttributes.GetValueCallback)(key => this.EscapeDirRegexSpecialCharacter(this.GetAttributeValue(key), true)));

            if (fTokenizeParameter && parameters != null)
            {
                StringBuilder stringBuilder = new StringBuilder(input.Length);
                int           num1          = 0;
                List <System.Text.RegularExpressions.Match> list = new List <System.Text.RegularExpressions.Match>();
                do
                {
                    num1 = input.IndexOf("{%", num1, StringComparison.OrdinalIgnoreCase);
                    if (num1 > -1)
                    {
                        System.Text.RegularExpressions.Match match = SetTokenizedAttributes.DirRegex.Match(input, num1);
                        if (match.Success)
                        {
                            list.Add(match);
                            num1 = match.Index + match.Length;
                        }
                        else
                        {
                            ++num1;
                        }
                    }
                }while (num1 > -1);
                if (list.Count > 0)
                {
                    stringBuilder.Remove(0, stringBuilder.Length);
                    int startIndex = 0;
                    int num2       = 0;
                    foreach (System.Text.RegularExpressions.Match match in list)
                    {
                        stringBuilder.Append(input.Substring(startIndex, match.Index - startIndex));
                        CaptureCollection captures1 = match.Groups["attrname"].Captures;
                        if (captures1 != null && captures1.Count > 0)
                        {
                            CaptureCollection           captures2       = match.Groups["attrval"].Captures;
                            Dictionary <string, string> paramDictionary = new Dictionary <string, string>(4, (IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);
                            paramDictionary[SetTokenizedAttributes.XPathWithIndex] = xpathToAttribute1;
                            paramDictionary[SetTokenizedAttributes.TokenNumber]    = num2.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                            for (int index1 = 0; index1 < captures1.Count; ++index1)
                            {
                                string index2 = captures1[index1].Value;
                                string str    = (string)null;
                                if (captures2 != null && index1 < captures2.Count)
                                {
                                    str = this.EscapeDirRegexSpecialCharacter(captures2[index1].Value, false);
                                }
                                paramDictionary[index2] = str;
                            }
                            string str1 = (string)null;
                            if (!paramDictionary.TryGetValue(SetTokenizedAttributes.Token, out str1))
                            {
                                str1 = this.storageDictionary.TokenFormat;
                            }
                            if (!string.IsNullOrEmpty(str1))
                            {
                                paramDictionary[SetTokenizedAttributes.Token] = str1;
                            }
                            int      count = paramDictionary.Count;
                            string[] array = new string[count];
                            paramDictionary.Keys.CopyTo(array, 0);
                            for (int index1 = 0; index1 < count; ++index1)
                            {
                                string index2 = array[index1];
                                string str2   = SetTokenizedAttributes.SubstituteKownValue(paramDictionary[index2], SetTokenizedAttributes.TokenFormatRegex, "#(", (SetTokenizedAttributes.GetValueCallback)(key =>
                                {
                                    if (!paramDictionary.ContainsKey(key))
                                    {
                                        return((string)null);
                                    }
                                    else
                                    {
                                        return(paramDictionary[key]);
                                    }
                                }));
                                paramDictionary[index2] = str2;
                            }
                            if (paramDictionary.TryGetValue(SetTokenizedAttributes.Token, out str1))
                            {
                                stringBuilder.Append(str1);
                            }
                            string argumentString;
                            if (paramDictionary.TryGetValue(SetTokenizedAttributes.XpathLocator, out argumentString) && !string.IsNullOrEmpty(argumentString))
                            {
                                IList <string> locators          = XmlArgumentUtility.SplitArguments(argumentString);
                                string         xpathToAttribute2 = this.GetXPathToAttribute(targetAttribute, locators);
                                if (!string.IsNullOrEmpty(xpathToAttribute2))
                                {
                                    paramDictionary[SetTokenizedAttributes.XPathWithLocator] = xpathToAttribute2;
                                }
                            }
                            parameters.Add(paramDictionary);
                        }
                        startIndex = match.Index + match.Length;
                        ++num2;
                    }
                    stringBuilder.Append(input.Substring(startIndex));
                    input = ((object)stringBuilder).ToString();
                }
            }
            return(input);
        }