Beispiel #1
0
        public static Panel PanelFromPanelInfo(DPanelInfo ifo)
        {
            string type = ifo.GetString("___type");

            if (type == null)
            {
                return(null);
            }
            string ParentIndex = ifo.GetString("___parent");
            Panel  p           = Derma.New(type);

            FieldInfo[]    fields     = GetSaveableFields(p);
            PropertyInfo[] properties = GetSaveableProperties(p);
            foreach (FieldInfo FInfo in fields)
            {
                Type   CastType  = FInfo.FieldType;
                object SavedProp = ifo.GetObject(FInfo.Name, CastType);
                if (SavedProp == null)
                {
                    continue;
                }
                FInfo.SetValue(p, SavedProp);
            }
            foreach (PropertyInfo FInfo in properties)
            {
                Type   CastType  = FInfo.PropertyType;
                object SavedProp = ifo.GetObject(FInfo.Name, CastType);
                if (SavedProp == null)
                {
                    continue;
                }
                FInfo.SetValue(p, SavedProp, null);
            }
            if (ParentIndex != null)
            {
                p.parentIdentifier = ParentIndex;
            }
            return(p);
        }
Beispiel #2
0
 /// <summary>
 /// Insert DPanelInfo into the DPacker object.
 /// </summary>
 /// <param name="ifo"></param>
 /// <returns>Index of added panel</returns>
 public int InsertPanelInfo(DPanelInfo ifo)
 {
     PanelData.Add(ifo);
     return(PanelData.Count() - 1);
 }
Beispiel #3
0
        /// <summary>
        /// Convert a Panel to a DPanelInfo
        /// </summary>
        /// <typeparam name="T">Derives from Panel</typeparam>
        /// <param name="Input">Any object deriving from Panel</param>
        /// <returns></returns>
        public static DPanelInfo PanelToInfo <T>(T Input) where T : Panel        // Must be a Panel
        {
            Type InputType = Input.GetType();

            FieldInfo[]    fields     = GetSaveableFields(Input);
            PropertyInfo[] properties = GetSaveableProperties(Input);
            DPanelInfo     ifo        = new DPanelInfo();

            foreach (FieldInfo FInfo in fields)
            {
                object val = FInfo.GetValue(Input);
                Type   t   = val.GetType();
                string key = FInfo.Name;
                // If I need to add more, tell me @Gbps
                if (t == typeof(string))
                {
                    ifo.Insert(key, Encoding.UTF8.GetBytes((string)val));
                }
                else if (t == typeof(int))
                {
                    ifo.Insert(key, BitConverter.GetBytes((int)val));
                }
                else if (t == typeof(bool))
                {
                    ifo.Insert(key, BitConverter.GetBytes((bool)val));
                }
                else if (t == typeof(char))
                {
                    ifo.Insert(key, BitConverter.GetBytes((char)val));
                }
                else if (t == typeof(float))
                {
                    ifo.Insert(key, BitConverter.GetBytes((float)val));
                }
                else if (t == typeof(double))
                {
                    ifo.Insert(key, BitConverter.GetBytes((double)val));
                }
                else if (t == typeof(List <string>))
                {
                    ifo.Insert(key, SerializeStringList((List <string>)val));
                }
            }
            foreach (PropertyInfo FInfo in properties)
            {
                object val = FInfo.GetValue(Input, null);
                Type   t   = val.GetType();
                string key = FInfo.Name;
                // If I need to add more, tell me @Gbps
                if (t == typeof(string))
                {
                    ifo.Insert(key, Encoding.UTF8.GetBytes((string)val));
                }
                else if (t == typeof(int))
                {
                    ifo.Insert(key, BitConverter.GetBytes((int)val));
                }
                else if (t == typeof(bool))
                {
                    ifo.Insert(key, BitConverter.GetBytes((bool)val));
                }
                else if (t == typeof(char))
                {
                    ifo.Insert(key, BitConverter.GetBytes((char)val));
                }
                else if (t == typeof(float))
                {
                    ifo.Insert(key, BitConverter.GetBytes((float)val));
                }
                else if (t == typeof(double))
                {
                    ifo.Insert(key, BitConverter.GetBytes((double)val));
                }
                else if (t == typeof(List <string>))
                {
                    ifo.Insert(key, SerializeStringList((List <string>)val));
                }
            }
            if (Input.hasParent && Input.parent)
            {
                ifo.Insert("___parent", Encoding.UTF8.GetBytes(Input.parent.varname));
            }
            ifo.Insert("___type", Encoding.UTF8.GetBytes(Input.GetType().Name));
            return(ifo);
        }