Esempio n. 1
0
        private string replacePatterns(string input, user user, order order = null)
        {
            string output = input;
            Regex  r      = new Regex(@"\[(.+?)\]", RegexOptions.IgnoreCase);
            Match  m      = r.Match(input);

            while (m.Success)
            {
                try
                {
                    string pat    = m.Groups[1].Value;
                    string newVal = $"[{pat}]";
                    var    arr    = pat.Split('.');
                    if (arr[0] == "user")
                    {
                        newVal = user.GetType().GetProperty(arr[1]).GetValue(user, null).ToString();
                    }
                    else if (arr[0] == "order")
                    {
                        newVal = order.GetType().GetProperty(arr[1]).GetValue(order, null).ToString();
                    }
                    output = output.Replace($"[{pat}]", newVal);
                }
                catch { }
                m = m.NextMatch();
            }
            return(output);
        }