I have a function that saves different variables, but the variables are not always the same type, they consist of ints, strings and a list. Is there was way I can pass a generic parameter to a method without defining its type?
I am trying to turn this code
public static void UpdateUser(User user) {
DatabaseReference databaseReference = FirebaseDatabase.DefaultInstance.RootReference;
databaseReference.Child("users").Child(AuthenitcationKey()).Child("userName").SetValueAsync(user.userName);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("hair").SetValueAsync(user.hair);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("face").SetValueAsync(user.face);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("kit").SetValueAsync(user.kit);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("body").SetValueAsync(user.body);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("offlineGamesPlayed").SetValueAsync(user.offlineGamesPlayed);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("onlineGamesPlayed").SetValueAsync(user.onlineGamesPlayed);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("offlineGamesWon").SetValueAsync(user.offlineGamesWon);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("onlineGamesWon").SetValueAsync(user.onlineGamesWon);
databaseReference.Child("users").Child(AuthenitcationKey()).Child("friends").SetValueAsync(user.friends);
}
into something more like this
public static Task<bool> UpdateUser(string saveName, Var varToSave) {
DatabaseReference databaseReference = FirebaseDatabase.DefaultInstance.RootReference;
return databaseReference.Child("users").Child(AuthenitcationKey()).Child(saveName).SetValueAsync(varToSave).ContinueWith((task) => {
return task.IsCompleted;
});
}