Exemple #1
0
 public string Format(PositionalComponent component, ComponentDescription description, PropertyValue value)
 {
     foreach (ComponentPropertyFormat formatRule in FormatRules)
     {
         if (formatRule.Conditions.IsMet(component, description))
         {
             return(formatRule.Format(component, description));
         }
     }
     return(value.ToString());
 }
        public string Format(Component component, ComponentDescription description)
        {
            Regex  variable  = new Regex("\\$[a-zA-z]+ ");
            string plainVars = variable.Replace(Value, new MatchEvaluator(delegate(Match match)
            {
                string propertyName = match.Value.Replace("$", "").Trim();
                var property        = description.GetProperty(component, propertyName);
                return(property.ToString());
            }));

            variable = new Regex("\\$[a-zA-Z]+[\\(\\)a-z_0-9]+ ");
            string formattedVars = variable.Replace(plainVars, new MatchEvaluator(delegate(Match match)
            {
                Regex propertyNameRegex = new Regex("\\$[a-zA-z]+");
                string propertyName     = propertyNameRegex.Match(match.Value).Value.Replace("$", "").Trim();
                var property            = description.GetProperty(component, propertyName);
                return(ApplySpecialFormatting(property, match.Value.Replace(propertyNameRegex.Match(match.Value).Value, "").Trim()));
            }));

            Regex regex = new Regex(@"\\[uU]([0-9A-F]{4})");

            return(regex.Replace(formattedVars, match => ((char)Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString()));
        }