示例#1
0
 private IEnumerable <AspectModel> ParseYAMLEntries(List <string> entries)
 {
     foreach (string entry in entries)
     {
         if (!string.IsNullOrEmpty(entry.Trim()))
         {
             AspectModel currentAspect    = new AspectModel();
             string      aspect           = entry.Trim();
             var         aspectProperties = ParseYAMLPairs(aspect);
             foreach (var aspectProperty in aspectProperties)
             {
                 PropertyInfo property = currentAspect.GetType().GetProperty(aspectProperty.Key);
                 if (property.PropertyType == typeof(string))
                 {
                     property.SetValue(currentAspect, aspectProperty.Value);
                 }
                 else if (property.PropertyType == typeof(DateTime))
                 {
                     property.SetValue(currentAspect, DateTime.Parse(aspectProperty.Value, null, DateTimeStyles.AllowWhiteSpaces));
                 }
                 else if (property.PropertyType == typeof(StringType))
                 {
                     property.SetValue(currentAspect, (StringType)Enum.Parse(typeof(StringType), aspectProperty.Value));
                 }
                 else
                 {
                     dynamic convertedValue = DynamicConvert(aspectProperty.Value, property.PropertyType);
                     property.SetValue(currentAspect, convertedValue);
                 }
             }
             yield return(currentAspect);
         }
     }
 }
示例#2
0
 private IEnumerable <AspectModel> ParseCSVEntries(List <string> entries)
 {
     foreach (string entry in entries)
     {
         List <string> values        = entry.Split(';').ToList();
         AspectModel   currentAspect = new AspectModel();
         currentAspect.PropertyName = values[0];
         currentAspect.ClassName    = values[1];
         if (!string.IsNullOrEmpty(values[2]))
         {
             currentAspect.Required = Convert.ToBoolean(values[2]);
         }
         if (!string.IsNullOrEmpty(values[3]))
         {
             currentAspect.Minimum = Convert.ToInt32(values[3]);
         }
         if (!string.IsNullOrEmpty(values[4]))
         {
             currentAspect.Maximum = Convert.ToInt32(values[4]);
         }
         if (!string.IsNullOrEmpty(values[5]))
         {
             currentAspect.MinimumLength = Convert.ToInt32(values[5]);
         }
         if (!string.IsNullOrEmpty(values[6]))
         {
             currentAspect.MaximumLength = Convert.ToInt32(values[6]);
         }
         if (!string.IsNullOrEmpty(values[7]))
         {
             currentAspect.EarliestDateTime = DateTime.Parse(values[7], null, DateTimeStyles.AllowWhiteSpaces);
         }
         if (!string.IsNullOrEmpty(values[8]))
         {
             currentAspect.LatestDateTime = DateTime.Parse(values[8], null, DateTimeStyles.AllowWhiteSpaces);
         }
         if (!string.IsNullOrEmpty(values[9]))
         {
             currentAspect.StringType = (StringType)Enum.Parse(typeof(StringType), values[9]);
         }
         string maxLengthText = values[10];
         if (maxLengthText.IndexOf('\r') != -1)
         {
             maxLengthText = values[10].Substring(0, values[10].IndexOf('\r'));
         }
         if (!string.IsNullOrEmpty(maxLengthText))
         {
             currentAspect.RegexPattern = maxLengthText;
         }
         yield return(currentAspect);
     }
 }