コード例 #1
0
        internal void UpdateObjectFromPayLoad(PayLoad PL, Attribute attr)
        {
            List <PropertyInfo> list = GetProperties(attr);

            //TODO: unpack the Payload and update the obj
            foreach (PropertyInfo PI in list)
            {
                object v = PI.GetValue(mObj);

                if (PI.PropertyType.IsEnum)
                {
                    string s = PL.GetValueEnum();
                    object o = Enum.Parse(PI.PropertyType, s);
                    PI.SetValue(mObj, o);
                }
                else if (v is IObservableList)
                {
                    List <PayLoad> lst = PL.GetListPayLoad();
                    foreach (PayLoad PL1 in lst)
                    {
                        ObjectReflectionHelper ORH1 = new ObjectReflectionHelper();
                        ORH1.CreateObjectFromPayLoad(PL1, attr);
                        ((IObservableList)v).Add(ORH1.obj);
                    }
                }
                else if (PI.PropertyType.Name == "String")
                {
                    string s = PL.GetValueString();
                    PI.SetValue(mObj, s);
                }
                else
                {
                    throw new Exception("Unknown type to handle - " + PI.PropertyType);
                }
            }
        }