Esempio n. 1
0
        public ExpressionConverterValue GetValue(List <ExpressionConverterElement> macrosList, object value)
        {
            ExpressionConverterValue macrosValue = null;

            foreach (var macrosElement in macrosList)
            {
                macrosValue = GetValue(macrosElement, value, macrosValue);
            }
            return(macrosValue);
        }
Esempio n. 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);
 }