Example #1
0
        public ExpressionConverterValue GetValue(string macrosName, object value)
        {
            var macrosElement = new ExpressionConverterElement()
            {
                Name     = macrosName,
                Argument = string.Empty
            };

            return(GetValue(macrosElement, value));
        }
Example #2
0
 /// <summary>
 /// Converts string value with specified macros.
 /// </summary>
 /// <param name="macrosElement">Macros element.</param>
 /// <param name="value">Converting value.</param>
 /// <param name="macrosValue">Macros value.</param>
 /// <returns>Converted string value.</returns>
 public ExpressionConverterValue GetValue(ExpressionConverterElement macrosElement, object value, ExpressionConverterValue macrosValue = null)
 {
     if (macrosValue == null)
     {
         macrosValue = new ExpressionConverterValue();
     }
     else
     {
         value = macrosValue.Data;
     }
     if (ExpressionConverterCollection == null)
     {
         ExpressionConverterCollection = new Dictionary <string, string>();
         var assembly = Type.GetType("Terrasoft.Configuration.ExpressionConverterElement").Assembly;
         var types    =
             from type in assembly.GetTypes()
             let attributes = type.GetCustomAttributes(typeof(ExpressionConverterAttribute), true)
                              where attributes != null && attributes.Length > 0
                              select type;
         foreach (var type in types)
         {
             var attributes = type.GetCustomAttributes(typeof(ExpressionConverterAttribute), true);
             if (attributes.Count() > 0)
             {
                 if (!ExpressionConverterCollection.ContainsKey(
                         ((ExpressionConverterAttribute)attributes[0]).ExpressionName))
                 {
                     ExpressionConverterCollection.Add(((ExpressionConverterAttribute)attributes[0]).ExpressionName,
                                                       string.Format("Terrasoft.Configuration.{0}", type.Name));
                 }
             }
         }
     }
     if (ExpressionConverterCollection.ContainsKey(macrosElement.Name))
     {
         Type expressionConverterClass = Type.GetType(ExpressionConverterCollection[macrosElement.Name]);
         var  expressionConverter      = (IExpressionConverter)Activator.CreateInstance(expressionConverterClass);
         if (expressionConverter != null)
         {
             macrosValue.Data = expressionConverter.Evaluate(value, macrosElement.Argument);
         }
     }
     return(macrosValue);
 }
Example #3
0
        public List <ExpressionConverterElement> MacrosList(string source)
        {
            var response   = new List <ExpressionConverterElement>();
            var macrosList = Match(source);

            string[] argumentSeparator = new string[] { "|" };
            foreach (string macros in macrosList)
            {
                var      item        = new ExpressionConverterElement();
                string[] macrosSplit = macros.Split(argumentSeparator, StringSplitOptions.RemoveEmptyEntries);
                item.Name = macrosSplit[0];
                if (macrosSplit.Length > 1)
                {
                    item.Argument = macrosSplit[1];
                }
                response.Add(item);
            }
            return(response);
        }