Exemplo n.º 1
0
        public static string Serialize(ControlEventInfo e)
        {
            StringBuilder sb = new StringBuilder(string.Empty);

            PropertyInfo[] piarray = null;
            PropertyInfo   pi      = null;
            object         value   = null;

            piarray = e.GetType().GetProperties();
            for (int i = 0; i < piarray.Length; i++)
            {
                pi    = piarray[i];
                value = pi.GetValue(e, null);
                if (value != null)
                {
                    if (value.ToString().Length > 0)
                    {
                        sb.Append(pi.Name + "=" + value.ToString());
                        if (i < piarray.Length - 1)
                        {
                            sb.Append("|");
                        }
                    }
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        public static ControlEventInfo Deserialize(string xml)
        {
            ControlEventInfo instance = new ControlEventInfo();
            PropertyInfo     pi       = null;

            string[] members = null;
            string[] array   = xml.Split(new string[] { "|" }, StringSplitOptions.None);
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].Length > 0)
                {
                    members = array[i].Split(new string[] { "=" }, StringSplitOptions.None);
                    if (members.Length > 0)
                    {
                        pi = instance.GetType().GetProperty(members[0]);
                        if (pi != null)
                        {
                            pi.SetValue(instance, (members.Length > 1 ? members[1] : string.Empty), null);
                        }
                    }
                }
            }
            return(instance);
        }