Exemple #1
0
        private static void Test2()
        {
#if NETCORE
            //ProtoBufTest.Test();
            {
                object exobj = null;
                try
                {
                    var b = 3;
                    b = 0;
                    var c = 2 / b;
                }
                catch (Exception exs)
                {
                    exobj = exs;
                }
                //var ex = new Exception("test ex");
                var ex = exobj;
                //var ex = new ServiceTest.Contract.Product
                //{
                //	Id = 223,
                //	Name = "abc book",
                //	Category = "Book",
                //	ListDate = DateTime.Now,
                //	Price = 34,
                //	Tags = new List<string>
                //	{
                //		"book",
                //		"tech",
                //		"new"
                //	}
                //};

                {
                    try
                    {
                        var setting = new JsonSerializerSettings
                        {
                            Formatting       = Formatting.Indented,
                            ContractResolver = new SerializeContractResolver()
                        };
                        var json = JsonConvert.SerializeObject(ex, setting);
                        Console.WriteLine(json);
                        var dex = JsonConvert.DeserializeObject(json, ex.GetType(), setting);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                var dcs = new DataContractSerializer(ex.GetType());
                var ms  = new MemoryStream();
                dcs.WriteObject(ms, ex);

                ms.Position = 0;
                var dex3 = dcs.ReadObject(ms);
                var xml  = Encoding.UTF8.GetString(ms.ToArray());

                var jss  = new System.Runtime.Serialization.Json.DataContractJsonSerializer(ex.GetType());
                var jsms = new MemoryStream();
                jss.WriteObject(jsms, ex);

                ms.Position = 0;
                var dexjs = dcs.ReadObject(ms);
                var jsss  = Encoding.UTF8.GetString(ms.ToArray());

                var product = new ServiceTest.Contract.Product
                {
                    Id       = 223,
                    Name     = "abc book",
                    Category = "Book",
                    ListDate = DateTime.Now,
                    Price    = 34,
                    Tags     = new List <string>
                    {
                        "book",
                        "tech",
                        "new"
                    }
                };
                var xmlSeriaizer = new System.Xml.Serialization.XmlSerializer(product.GetType());
                var stringWriter = new StringWriter();
                //var xmlWriter = new XmlWriter();
                xmlSeriaizer.Serialize(stringWriter, (object)product);
            }
#endif
        }
Exemple #2
0
        private static void Test2()
        {
            #if NETCORE

            //ProtoBufTest.Test();
            {
                object exobj = null;
                try
                {
                    var b = 3;
                    b = 0;
                    var c = 2 / b;
                }
                catch (Exception exs)
                {
                    exobj = exs;
                }
                //var ex = new Exception("test ex");
                var ex = exobj;
                //var ex = new ServiceTest.Contract.Product
                //{
                //	Id = 223,
                //	Name = "abc book",
                //	Category = "Book",
                //	ListDate = DateTime.Now,
                //	Price = 34,
                //	Tags = new List<string>
                //	{
                //		"book",
                //		"tech",
                //		"new"
                //	}
                //};

                {
                    try
                    {
                        var setting = new JsonSerializerSettings
                        {
                            Formatting = Formatting.Indented,
                            ContractResolver = new SerializeContractResolver()
                        };
                        var json = JsonConvert.SerializeObject(ex, setting);
                        Console.WriteLine(json);
                        var dex = JsonConvert.DeserializeObject(json, ex.GetType(), setting);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                var dcs = new DataContractSerializer(ex.GetType());
                var ms = new MemoryStream();
                dcs.WriteObject(ms, ex);

                ms.Position = 0;
                var dex3 = dcs.ReadObject(ms);
                var xml = Encoding.UTF8.GetString(ms.ToArray());

                var jss = new System.Runtime.Serialization.Json.DataContractJsonSerializer(ex.GetType());
                var jsms = new MemoryStream();
                jss.WriteObject(jsms, ex);

                ms.Position = 0;
                var dexjs = dcs.ReadObject(ms);
                var jsss = Encoding.UTF8.GetString(ms.ToArray());

                var product = new ServiceTest.Contract.Product
                {
                    Id = 223,
                    Name = "abc book",
                    Category = "Book",
                    ListDate = DateTime.Now,
                    Price = 34,
                    Tags = new List<string>
                    {
                        "book",
                        "tech",
                        "new"
                    }
                };
                var xmlSeriaizer = new System.Xml.Serialization.XmlSerializer(product.GetType());
                var stringWriter = new StringWriter();
                //var xmlWriter = new XmlWriter();
                xmlSeriaizer.Serialize(stringWriter, (object)product);
            }
            #endif
        }
Exemple #3
0
 public Task<Product> GetInputAsync(Product product)
 {
     return Task.FromResult(product);
 }
Exemple #4
0
 public Product GetInput(Product product)
 {
     return product;
 }
Exemple #5
0
 public Task<int> AddAsync(Product product)
 {
     Products.Add(product);
     return Task.FromResult(product?.Id ?? -1);
 }
Exemple #6
0
 public int Add(Product product)
 {
     return AddAsync(product).Result;
 }