Skip to content

Instantly share code, notes, and snippets.

@salami-art
Created July 10, 2015 08:33
Show Gist options
  • Save salami-art/6d0d3144cf0bfd578964 to your computer and use it in GitHub Desktop.
Save salami-art/6d0d3144cf0bfd578964 to your computer and use it in GitHub Desktop.
public static string Aggiorna(string classe, string parametri)
{
int id;
string aggiornato = "";
ClasseCollegataAUnRecordSuDB_Base classeCollegata = ritornaIstanza(classe);
JObject par = JObject.Parse(parametri);
var oggettoParametri = par.ToObject<Dictionary<string, dynamic>>();
var chiavi = oggettoParametri.Keys.ToArray();
if (!int.TryParse("0" + (string)oggettoParametri["Id"], out id))
id = 0;
if( id > 0)
classeCollegata.leggiDatiDaDB(id);
if (classeCollegata.haGliStessiParametri(chiavi));
{
Type type = classeCollegata.GetType();
// assegna le proprietà alla classe programmaticamente
foreach (KeyValuePair<string, dynamic> entry in oggettoParametri)
{
PropertyInfo prop = type.GetProperty(entry.Key);
Type propertyType = prop.PropertyType;
prop.SetValue(classeCollegata, Convert.ChangeType(entry.Value, propertyType));
}
}
//classeCollegata.SalvaSuDB();
return aggiornato;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment