Example #1
0
        static async void GetWeather(string area)
        {
            var data = await WeatherApi.GetTodayRestAsync(area);

            if (!data.State)
            {
                Console.WriteLine(data.Msg);
                return;
            }
            var properties = data.Data.GetType().GetProperties();
            var sb         = new StringBuilder();

            foreach (var item in properties)
            {
                var attr = item.GetCustomAttributes(typeof(DisplayAttribute), true).FirstOrDefault();
                if (attr != null)
                {
                    var nameText = ((DisplayAttribute)attr).Name;
                    sb.AppendLine(string.Format("{0} = {1}", nameText, item.GetValue(data.Data, null)));
                }
            }
            Console.WriteLine("{0} 天气情况如下:", area);
            Console.WriteLine(sb.ToString());
            Console.WriteLine("请输要查询的地区(帮助请输 -h):");
        }