Example #1
0
 public override void Visit(Command command)
 {
     PropertyInfo[] properties = command.GetType().GetProperties();
     foreach (PropertyInfo property in properties)
     {
         GinResultAttribute attr = (GinResultAttribute)property.GetCustomAttributes(typeof(GinResultAttribute), true).FirstOrDefault();
         if (attr != null)
         {
             if (attr.Result != null)
             {
                 string name = (string)property.GetValue(command, null);
                 if (!String.IsNullOrEmpty(name))
                 {
                     _list.Add(new ResultInfo()
                     {
                         Type        = attr.Result,
                         Name        = name,
                         Description = attr.Description
                     });
                 }
             }
             else if (_findRecursive && attr.Kind == CommandResultKind.Dynamic)
             {
                 string name = (string)property.GetValue(command, null);
                 if (name == null)
                 {
                     continue;
                 }
                 ResultInfo find = _firstRunResults.FirstOrDefault(r => ExecutionContext.GetPercentedKey(r.Name) == name);
                 if (find == null)
                 {
                     continue;
                 }
                 List <ParsedResult> members = CMParseResult.GetObjectValueMembers(find.Type, null, name);
                 foreach (var member in members)
                 {
                     if (!String.IsNullOrEmpty(member.Name))
                     {
                         _list.Add(new ResultInfo()
                         {
                             Type        = member.Type,
                             Name        = member.Name,
                             Description = member.Description
                         });
                     }
                 }
             }
         }
     }
 }
Example #2
0
        public static List <ParsedResult> GetObjectValueMembers(Type type, object objectValue, string objectName)
        {
            List <ParsedResult> result = new List <ParsedResult>();

            foreach (FieldInfo field in type.GetFields())
            {
                if (field.IsStatic)
                {
                    continue;
                }
                object fieldValue = objectValue != null?field.GetValue(objectValue) : null;

                string             cleanedArgumentName = CleanPercents(objectName);
                string             newArgumentName     = cleanedArgumentName + "." + field.Name;
                GinResultAttribute attr = field.GetCustomAttributes(false).OfType <GinResultAttribute>().FirstOrDefault();
                result.Add(new ParsedResult
                {
                    Name        = newArgumentName,
                    Value       = fieldValue,
                    Type        = attr != null ? attr.Result : null,
                    Description = attr != null ? attr.Description : null
                });
            }

            foreach (PropertyInfo prop in type.GetProperties())
            {
                object propValue = objectValue != null?prop.GetValue(objectValue, null) : null;

                string             cleanedArgumentName = CleanPercents(objectName);
                string             newArgumentName     = cleanedArgumentName + "." + prop.Name;
                GinResultAttribute attr = prop.GetCustomAttributes(false).OfType <GinResultAttribute>().FirstOrDefault();
                result.Add(new ParsedResult
                {
                    Name        = newArgumentName,
                    Value       = propValue,
                    Type        = attr != null ? attr.Result : null,
                    Description = attr != null ? attr.Description : null
                });
            }

            return(result);
        }
Example #3
0
 private void CheckResultNamePresent(Command command)
 {
     PropertyInfo[] properties = command.GetType().GetProperties();
     foreach (PropertyInfo property in properties)
     {
         GinResultAttribute attr = (GinResultAttribute)property.GetCustomAttributes(typeof(GinResultAttribute), true).FirstOrDefault();
         if (attr != null)
         {
             string name = (string)property.GetValue(command, null);
             if (String.IsNullOrEmpty(name))
             {
                 _errors.Add(new PackageErrorInfo
                 {
                     Body        = _body,
                     Command     = command,
                     Description = "У команды " + command + "(" + command.Description + ") отсутствует параметр 'Имя результата'"
                 });
             }
         }
     }
 }