Ejemplo n.º 1
0
        private static IDictionary ToDictionary(object obj)
        {
            HybridDictionary results = new HybridDictionary();

            foreach (PropertyInfo prop in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                object[] attributes = prop.GetCustomAttributes(typeof(XmlRpcStructMemberAttribute), false);
                if (attributes.Length > 0)
                {
                    XmlRpcStructMemberAttribute attr = (XmlRpcStructMemberAttribute)attributes[0];
                    string name = attr.Name;
                    object val  = prop.GetValue(obj, null);
                    if (val != null)
                    {
                        results[name] = ToXmlRpc(val);
                    }
                }
            }
            return(results);
        }
Ejemplo n.º 2
0
        private static object FromStruct(IDictionary val, Type type)
        {
            object result = Activator.CreateInstance(type);

            foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                object[] attributes = prop.GetCustomAttributes(typeof(XmlRpcStructMemberAttribute), false);
                if (attributes.Length > 0)
                {
                    XmlRpcStructMemberAttribute attr = (XmlRpcStructMemberAttribute)attributes[0];
                    string name      = attr.Name;
                    object propValue = val[name];
                    if (propValue != null)
                    {
                        Type propType = prop.PropertyType;
                        prop.SetValue(result, FromXmlRpc(propValue, propType), null);
                    }
                }
            }
            return(result);
        }