Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var list = EnumHelper.GetList(typeof(Attrbute.enum1));

            list = EnumHelper.GetList(typeof(int));
            Console.WriteLine(EnumHelper.GetDescription(Attrbute.enum1.name2));
            Console.WriteLine(EnumHelper.GetDescription(Attrbute.enum2.name2));
            var aa = Attrbute.enum1.name2.GetType().GetFields();

            var ab = Attrbute.enum2.name1.GetType().GetFields();

            foreach (var name in Enum.GetNames(typeof(Attrbute.enum1)))
            {
                Console.WriteLine(name);
            }
            foreach (var value in Enum.GetValues(typeof(Attrbute.enum1)))
            {
                Console.WriteLine(string.Format("{0}={1}", value.ToString(), Convert.ToInt32(value)));
            }

            foreach (var value in Enum.GetValues(typeof(Attrbute.enum1)))
            {
                object[] objAttrs = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
                if (objAttrs != null &&
                    objAttrs.Length > 0)
                {
                    DescriptionAttribute descAttr = objAttrs[0] as DescriptionAttribute;
                    Console.WriteLine(string.Format("[{0}]", descAttr.Description));
                }
                Console.WriteLine(string.Format("{0}={1}", value.ToString(), Convert.ToInt32(value)));
            }

            //var t=typeof(Attrbute.enum1);
            //var CustomAttributes = t.CustomAttributes;
            //foreach (var item in CustomAttributes)
            //{
            //    var l = item.AttributeType.Name;
            //    Console.WriteLine(l);
            //}

            //Console.WriteLine(t.FullName);
            Console.Read();
        }
Пример #2
0
        static void Main(string[] args)
        {
            //dateTimeHelperTest();
            //Console.ReadLine();
            //return;



            Console.WriteLine("==================enum=================");
            var list = EnumHelper.GetList <OsType>();

            Console.WriteLine(JsonConvert.SerializeObject(list));

            var desc = OsType.HarmonyOS.GetDescription();

            Console.WriteLine(desc);

            var oss = OsType.Ios | OsType.HarmonyOS;

            Console.WriteLine(oss.ToString());


            var oss2  = (OsType)15;
            var oss2s = oss2.ToString();

            Console.WriteLine(oss2s);
            Console.WriteLine($"oss2包涵鸿蒙吗?{oss2.HasFlag(OsType.HarmonyOS)}。");
            var ostype = Enum.Parse(typeof(OsType), oss2s);

            Console.WriteLine($"ostype:{ostype} => {(int)ostype}");
            var ostype2 = Enum.Parse <OsType>(oss2s, ignoreCase: true);

            Console.WriteLine($"ostype2:{ostype2} => {(int)ostype2}");


            Console.WriteLine($"7&8:{Convert.ToString(7,2)}&{Convert.ToString(8, 2)} ==>{7 & (int)OsType.HarmonyOS}, { (7 & (int)OsType.HarmonyOS) == (int)OsType.HarmonyOS}");
            Console.WriteLine($"15&8:{Convert.ToString(15, 2)}&{Convert.ToString(8, 2)} ==>{15 & (int)OsType.HarmonyOS}, { (15 & (int)OsType.HarmonyOS) == (int)OsType.HarmonyOS}");

            Console.ReadLine();
            return;

            var a = Convert.ToString(100, 2);

            Console.WriteLine(a);
            return;

            var url  = $"https://dev.king.kingcome.net.cn/notify/reserve/PaidMoneyRefund";
            var data = new
            {
                orderId      = 5164,
                reason       = "xxxxx",
                employeeId   = 5541,
                employeeName = "PAUL"
            };
            var res = HttpHelpler.Post(url, JsonConvert.SerializeObject(data));

            Console.WriteLine(res);
            return;

            Console.WriteLine("Hello World!");

            var ts1 = 1400515200000L;
            var ts2 = 1604368569296L;
            var t   = ts2 - ts1;
            var b1  = Convert.ToString(ts1, 2);
            var b2  = Convert.ToString(ts2, 2);
            var b   = Convert.ToString(t, 2);

            Console.WriteLine($"{b1}");
            Console.WriteLine($"{b2}");
            Console.WriteLine($"{b}");

            var ts3 = 1400515200L;
            var ts4 = 1604368782L;
            var t2  = ts4 - ts3;
            var b3  = Convert.ToString(ts3, 2);
            var b4  = Convert.ToString(ts4, 2);
            var b_2 = Convert.ToString(t2, 2);

            Console.WriteLine($"{b3}");
            Console.WriteLine($"{b4}");
            Console.WriteLine($"{b_2}");

            var myarr = new string[] { "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" };
            //1. 获取数组 前3个元素
            var query1 = myarr[0..3];