예제 #1
0
        public void Serialization1()
        {
            IMainObject                    mainObj       = MainObjectFactory.Singleton.GetNew();
            MainObjectRepoSerMgr           mainObjSerMgr = MainObjectRepoSerMgr.Singleton;
            RepositorySerializationContext serCtx        = new RepositorySerializationContext();
            RepositorySerializationContext serCtx2       = new RepositorySerializationContext();
            ISubObject subObject = null;

            if (typeof(IMainObject).GetTypeGuid().ToString() == "e94473ee-f53f-4b7b-95d6-36d78d327e86")
            {
                System.Diagnostics.Debug.WriteLine("Guid verificato");
            }

            mainObj.DateTimeField       = DateTime.Now;
            mainObj.Field3              = SubObjectFactory.Singleton.GetNew();
            mainObj.Field1              = "String Field \", \"aaa\" : \"bbb\", Insidioso";
            mainObj.Field2              = "Mario";
            mainObj.Field3.SubObjField1 = "Sub 1";
            mainObj.Field3.SubObjField2 = "Sub 2";
            mainObj.Field4              = true;
            mainObj.Field5              = new List <ISubObject> ();
            mainObj.Field6              = new List <Object> ();
            mainObj.Field6Bis           = (IList)mainObj.Field6;
            mainObj.Field7              = new Dictionary <String, ISubObject> ();
            mainObj.Field8              = -1234567.890;
            mainObj.BooleanArray        = new Boolean [] { true, false, true };
            mainObj.DateTimeArray       = new DateTime [] { DateTime.Now.AddDays(-1),
                                                            DateTime.Now,
                                                            DateTime.Now.AddDays(1) };
            mainObj.Int32Array     = new Int32 [] { 123, 456, 789 };
            mainObj.MixedArray     = new Object [] { 123, true, DateTime.Now };
            mainObj.SubObjectArray = new ISubObject [2];

            subObject = SubObjectFactory.Singleton.GetNew();
            subObject.SubObjField1 = "Collection Item 1 Field 1";
            subObject.SubObjField2 = "Collection Item 1 Field 2";
            mainObj.Field5.Add(subObject);
            mainObj.Field6.Add(subObject);
            mainObj.SubObjectArray [0] = subObject;

            subObject = SubObjectFactory.Singleton.GetNew();
            subObject.SubObjField1 = "Collection Item 2 Field 1";
            subObject.SubObjField2 = "Collection Item 2 Field 2";
            mainObj.Field5.Add(subObject);
            mainObj.SubObjectArray [1] = subObject;

            mainObj.Field6.Add("Ciccio Pasticcio");
            mainObj.Field6.Add(subObject);

            mainObj.Field7.Add("Dictionary Test", subObject);

            //dynamic test = MainObjectFactory.Singleton.ExportToJson ( mainObj );

            TextWriter tw = new StringWriter();

            serCtx.SerializeMetadata = true;
            mainObjSerMgr.Serialize(tw, mainObj, serCtx);

            tw.Flush();
            tw.Close();

            String serialization = tw.ToString();

            using (StringReader sr1 = new StringReader(serialization))
            {
                IMainObject deserResult = mainObjSerMgr.Deserialize(sr1, serCtx2);
            }
        } // End of Serialization1 ()
예제 #2
0
        /// <summary>
        /// 循环读取命令
        /// </summary>
        static void loop()
        {
            bool   flag = false;
            string com  = null;

            while (!flag)
            {
                Console.WriteLine(getString());
                com = Console.ReadLine();
                if (com.EndsWith("exit", StringComparison.OrdinalIgnoreCase))
                {
                    if (stack.Count == 1)
                    {
                        flag = true;
                        continue;
                    }
                    stack.Pop();
                }
                else
                {
                    object obj2;
                    if (com.EndsWith("sub", StringComparison.OrdinalIgnoreCase))
                    {
                        obj2 = stack.Peek();
                        if (obj2.GetType().GetInterface(typeof(ISubObject).Name) != null)
                        {
                            ISubObject obj3 = obj2 as ISubObject;
                            Console.Write("请输入要选取的对象名>");
                            object subObject = obj3.GetSubObject(Console.ReadLine());
                            if (subObject != null)
                            {
                                stack.Push(subObject);
                            }
                            else
                            {
                                Console.WriteLine("不存在此对象");
                            }
                        }
                        else
                        {
                            Console.WriteLine("当期对象不支持此命令");
                        }
                    }
                    else if (com.EndsWith("info", StringComparison.OrdinalIgnoreCase))
                    {
                        obj2 = stack.Peek();
                        if (obj2.GetType().GetInterface(typeof(IStatus).Name) != null)
                        {
                            Console.WriteLine((obj2 as IStatus).GetInfo());
                        }
                        else
                        {
                            Console.WriteLine("当期对象不支持此命令");
                        }
                    }
                    else
                    {
                        command(com);
                    }
                }
            }
            Console.WriteLine(com);
        }
예제 #3
0
 public ISubObject VerifyObject(ISubObject obj)
 {
     throw new NotImplementedException();
 }
예제 #4
0
 public ISubObject VerifyObject(ISubObject obj)
 {
     return(ReferenceEquals(_subObject, obj) ? obj : null);
 }
예제 #5
0
 public ISubObject ReflectObj(ISubObject s)
 {
     return(s);
 }
예제 #6
0
 public ISubObject SetNameFromSubObject(ISubObject obj)
 {
     return(new SubObject {
         Name = obj.Name
     });
 }
예제 #7
0
 public Payload(ISubObject property)
 {
     Property = property;
 }