Ejemplo n.º 1
0
        public static string GetDescription(this FileLine fileLine, string format)
        {
            var words       = GetWords(format);
            var @properties = fileLine.GetType().GetProperties();

            foreach (var word in words)
            {
                var value    = "";
                var property = @properties.FirstOrDefault(i => i.Name.EndsWith(word));

                if (property != null)
                {
                    var descriptionAttribute = property
                                               .GetCustomAttributes(typeof(DescriptionAttribute), false)
                                               .FirstOrDefault() as DescriptionAttribute;

                    if (descriptionAttribute != null)
                    {
                        value = descriptionAttribute.Description;
                    }

                    format = format.Replace(String.Concat("{", $"{ word }", "}"), value.ToString());
                    format = format.Replace(word, value.ToString());
                }
            }

            return(format);
        }
Ejemplo n.º 2
0
        public static string ToString(this FileLine fileLine, string format)
        {
            var words       = GetWords(format);
            var @properties = fileLine.GetType().GetProperties();

            foreach (var word in words)
            {
                var property = @properties.FirstOrDefault(i => i.Name.EndsWith(word));
                if (property != null)
                {
                    var value = property.GetValue(fileLine).ToString();

                    if (property.PropertyType.IsEnum)
                    {
                        value = ((int)Enum.Parse(property.PropertyType, value)).ToString();
                    }

                    format = format.Replace(String.Concat("{", $"{ word }", "}"), value.ToString());
                    format = format.Replace(word, value.ToString());
                }
            }

            return(format);
        }