Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Expression <Func <object, object> > exp = x => ((MyClass)x).Value.Length;

            var m = new MyClass {
                Value = "ssdf",

                /*Nested = new MyClass {
                 *  Value = "asd"
                 * }*/
            };

            RUtils <MyClass> .TrySet(m, "Nested.Nested.Nested.Value", "fdg");

            RUtils <MyClass> .TryGet(m, "Nested.Nested.Nested.Value", out var value);


            RUtils <MyClass> .Set(obj, "Value", "asd");

            RUtils <MyClass> .Get(obj, "Value");

            var summary = BenchmarkRunner.Run <RUtils_Benchmarks>(new Config());

            Console.WriteLine();

            Console.WriteLine("\nString value set and then get");

            var runCount = summary.Reports.Length;// / 2;

            foreach (var report in summary.Reports.Take(runCount).OrderBy(x => x.ResultStatistics.Median))
            {
                var ns    = $"{report.ResultStatistics.Median:N1} ns";
                var spase = new string(' ', 10 - ns.Length);

                Console.WriteLine($"{ns}{spase}{Info(report)}");
            }

            /*
             * Console.WriteLine("\nString value set and then get");
             * foreach (var report in summary.Reports.Skip(runCount).Take(runCount).OrderBy(x => x.ResultStatistics.Median)) {
             *  var ns = $"{report.ResultStatistics.Median:N1} ns";
             *  var spase = new string(' ', 10 - ns.Length);
             *
             *  Console.WriteLine($"{ns}{spase}{Info(report)}");
             * }*/

            /*
             * Console.WriteLine("\nString value set and then get");
             * foreach (var report in summary.Reports.Skip(16).OrderBy(x => x.ResultStatistics.Median)) {
             *  var ns = $"{report.ResultStatistics.Median:N1} ns";
             *  var spase = new string(' ', 10 - ns.Length);
             *
             *  Console.WriteLine($"{ns}{spase}{Info(report)}");
             * }
             */

            Console.WriteLine();
            Console.ReadLine();
        }
Exemplo n.º 2
0
        public string REtilsTrySetValue()
        {
            RUtils <MyClass> .TrySet(obj, "Value", "asd");

            RUtils <MyClass> .TryGet(obj, "Value", out object value);

            return((string)value);
        }
Exemplo n.º 3
0
        public static T To <T>([NotNull] this DataRow row, [NotNull] T item) where T : class
        {
            foreach (DataColumn column in row.Table.Columns)
            {
                var value = row[column];
                if (value == DBNull.Value || value == null)
                {
                    continue;
                }

                if (!RUtils <T> .TrySet(item, column.ColumnName, value))
                {
                    Log.TraceEvent(TraceEventType.Warning, $"Can't set property {column.ColumnName} from '{typeof (T).FullName}' context.");
                }
            }

            return(item);
        }