Hello !
I would like to send class’s data to a PHP script using POST, I’m actually doing it by using the WWWForm class but the point is that I would like to avoid typing each single value I would like to send, this is what I’m doing right now:
SortedList<string, string> arguments = new SortedList<string, string>();
if (contactToMod.isAbove18)
arguments.Add(“is_above_18”, “1”);
else
arguments.Add(“is_above_18”, “0”);
if (contactToMod.isAccompagnated)
arguments.Add("is_accompagnated", "1");
else
arguments.Add("is_accompagnated", "0");
// There is a lot more lines, I've just cut it to don't make the post too long
arguments.Add("notes", contactToMod.Notes);
arguments.Add("children", contactToMod.Children);
arguments.Add("idContactsDb", contactToMod.idContactsDb);
arguments.Add("idToday", contactToMod.idToday);
dummy.StartCoroutine(DoResquest(arguments, URL, callbackSuccess, callbackError));
But I found an interesting code on internet involving System.Reflection, and on a previous Unity’s forum post, it seems to work well, but when I translated it in C# it didn’t found any class’s property (whenever my properties are all publics, but not statics) :
SortedList<string, string> argsPosted = new SortedList<string, string>();
Debug.Log ("contactToMod.Firstname = " + contactToMod.Firstname);
foreach (PropertyInfo prop in contactToMod.GetType().GetProperties())
{
argsPosted.Add(prop.Name, prop.GetValue(contactToMod, null).ToString());
Debug.Log("name = " + prop.Name + " and value = " + prop.GetValue(contactToMod, null).ToString());
}
Debug.Log ("Kappa");
But it only display:
contactToMod.Firstname = John Snow
--> Nothing <--
Kappa
And my previous code was working well so the object contains well defined values