Exemple #1
0
 public void GetMemberInfoTest()
 {   // 225 to 25 ms to5
     for (int i = 0; i < MaxTime; i++)
     {
         var mem = CTRCHelper.GetMemberInfos <MethodModel>().FirstOrDefault(c => c.Name == "Test1");
     }
 }
Exemple #2
0
        public void MyTestMethod()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var dict =
                CTRCHelper.GetMethodInfos <MethodModel>()
                .ToDictionary(c => c, t => new Dictionary <string, Func <int, int> >
            {
                { "a", (i) => i + 12 },
                { "b", (i) => i + 12 },
                { "c", (i) => i + 12 },
                { "d", (i) => i + 12 },
                { "e", (i) => i + 12 }
            });
            var key = CTRCHelper.GetMethodInfos <MethodModel>().LastOrDefault(c => c.Name == "Generic");

            Console.WriteLine(dict.Count);
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            var d = EqualityComparer <MethodInfo> .Default;

            for (int i = 0; i < MaxTime; i++)
            {
                //  var t= d.GetHashCode(key);

                //var t = key.Equals(dict.Keys.First());
                var t = dict[key]["a"];
            }
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }
Exemple #3
0
 public void GetMemberInfosTest()
 {   // 225 to 25 ms to5
     for (int i = 0; i < MaxTime; i++)
     {
         var mem = CTRCHelper.GetMemberInfos <MethodModel>();
     }
 }
Exemple #4
0
 public void GetMethodInfosTest()
 {
     //60ms 2 11ms
     for (int i = 0; i < MaxTime; i++)
     {
         var mem = CTRCHelper.GetMethodInfos <MethodModel>();
     }
 }
Exemple #5
0
        public void GetPropertyTest()
        {
            var props = CTRCHelper.GetPropertiesCache <PropertyTestModel>();

            foreach (var propertyInfo in props)
            {
                Console.WriteLine(propertyInfo.Name);
            }
            Assert.AreEqual(1, props.Length);
        }
Exemple #6
0
        public void GetDifferentMemberInfosTest()
        {
            var t = CTRCHelper.GetMemberInfos <MethodModel>();

            Console.WriteLine(t);

            var t1 = CTRCHelper.GetMemberInfos <FieldModel>();

            Console.WriteLine(t1);
        }
Exemple #7
0
        public void GetFieldInfosTest()
        {
            for (int i = 0; i < MaxTime; i++)
            {
                // var t= typeof(MyClass).GetFields();

                var t = CTRCHelper.GetFieldInfos <MethodModel>();
                //var t = string.Empty;
            }
        }
Exemple #8
0
        public void MethodCountTest()
        {
            var methods = CTRCHelper.GetMethodInfos <MethodTestModel>();

            foreach (var m in methods)
            {
                Console.WriteLine(m.Name);
            }
            Assert.AreEqual(3, methods.Length);
        }
Exemple #9
0
        public void GetExecutingAssemblyVersionTest()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            for (int i = 0; i < MaxTime; i++)
            {
                var b = CTRCHelper.GetExecutingAssemblyVersion();
            }
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }
Exemple #10
0
        public void TestMethod1()
        {
            var fields = CTRCHelper.GetFieldInfos <TestEnum>();

            //Console.WriteLine(fields.Length);

            foreach (var field in fields)
            {
                // if (field.Name == "value__") continue;
                // Console.WriteLine(Enum.Parse(typeof(TestEnum), field.Name));

                var t = CTRCHelper.GetCustomAttributes <DescriptionAttribute>(field);

                //Console.WriteLine(t?.Description??"none");
            }
        }
Exemple #11
0
        /// <summary>
        /// Get the ExcelTitleAttribute on proerties
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Dictionary <PropertyInfo, ExcelTitleAttribute> GetPropertiesAttributesDict <T>()
        {
            var dict         = new Dictionary <PropertyInfo, ExcelTitleAttribute>();
            int defaultOrder = 10000;

            foreach (var propertyInfo in CTRCHelper.GetPropertiesCache <T>())
            {
                var attrs = propertyInfo.GetCustomAttributes(true);
                var attr  = GetExcelTitleAttributeFromAttributes(attrs, defaultOrder++);

                if (attr == null)
                {
                    continue;
                }
                dict.Add(propertyInfo, attr);
            }

            return(dict);
        }