Example #1
0
        private static void FilterAndOutput <T>(TableArguments args, List <T> queryResult) where T : IEOSTable
        {
            List <dynamic> filteredFieldObject = null;

            if (args.fieldList != null)
            {
                foreach (var field in args.fieldList)
                {
                    if (typeof(T).GetProperty(field) == null)
                    {
                        Console.WriteLine(string.Format("Table rows do not contain field \"{0}\"", field));
                        return;
                    }
                }

                filteredFieldObject = EOSUtility.FilterFields(args.fieldList, queryResult);
            }

            if (args.outputFormat == OutputFormats.json)
            {
                string json = string.Empty;
                if (filteredFieldObject == null)
                {
                    json = JsonConvert.SerializeObject(queryResult, Formatting.Indented);
                }
                else
                {
                    json = JsonConvert.SerializeObject(filteredFieldObject, Formatting.Indented);
                }

                Console.WriteLine(json);
            }
            else
            {
                if (filteredFieldObject == null)
                {
                    Console.Write(queryResult.ToCsv());
                }
                else
                {
                    Console.Write(filteredFieldObject.ToCsv());
                }
            }
        }
Example #2
0
        private static bool CheckProperties <T>(TableArguments args) where T : IEOSTable
        {
            bool error = false;

            if (args.fieldList != null)
            {
                foreach (var field in args.fieldList)
                {
                    if (typeof(T).GetProperty(field) == null)
                    {
                        Console.WriteLine(string.Format("Table rows do not contain field \"{0}\"", field));
                        Console.WriteLine("Valid fields include:");
                        PropertyInfo[] properties = typeof(T).GetProperties();
                        foreach (var property in properties)
                        {
                            Console.WriteLine(property.Name);
                        }
                        error = true;
                    }
                }
            }
            return(error);
        }