Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                var info  = MappingInfo.Create <Foo, Foo>();
                var info2 = MappingInfo.Create <MyClassB, MyClassB>();
                //var info2 = MappingInfo.Create<InnerFoo, InnerFooDest>();
                //info.BeforeMap = x => Console.WriteLine(x.MyProperty);
                //info.AfterMap = x => Console.WriteLine(x.MyProperty3);

                // info.AddMap(x => x.MyProperty, x => x.MyPropertyNano, x => x);
                //info.AddMap(x => x.MyProperty, x => x.MyProperty3, x => x);
                //info.AddUse(x => x.DT, _ => DateTime.Now);

                // info.WithConvertAction(x => x.MyProperty, x => x.MyProperty, x => new MyClassC());


                info.BuildMapper();
                info2.BuildMapper();
                // info2.BuildMapper();

                // DynamicObjectResolver.Default.GetMapper<MyClassA, MyClassB>();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
#if DEBUG
                var a = DynamicObjectTypeBuilder.Save();
                Verify(a);
#endif
            }
        }
            static FormatterCache()
            {
                var ti = typeof(T).GetTypeInfo();

                if (ti.IsNullable())
                {
                    ti = ti.GenericTypeArguments[0].GetTypeInfo();

                    var innerFormatter = DynamicObjectResolver.Instance.GetFormatterDynamic(ti.AsType());
                    if (innerFormatter == null)
                    {
                        return;
                    }
                    formatter = (IMessagePackFormatter <T>)Activator.CreateInstance(typeof(StaticNullableFormatter <>).MakeGenericType(ti.AsType()), new object[] { innerFormatter });
                    return;
                }

                var formatterTypeInfo = DynamicObjectTypeBuilder.BuildType(assembly, typeof(T), false);

                if (formatterTypeInfo == null)
                {
                    return;
                }

                formatter = (IMessagePackFormatter <T>)Activator.CreateInstance(formatterTypeInfo.AsType());
            }
 static FormatterCache()
 {
     mapper = (IObjectMapper <TFrom, TTo>)DynamicObjectTypeBuilder.BuildMapperFromType <TFrom, TTo>(nameMutator);
 }