I am currently trying to convert a Xamarin.iOS app library to a PCL. I have this code that will not compile:
private void SetPrivateField<T>(object item, string fieldName, object value) {
typeof(T).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic)
.SetValue(item, value);
}
As you can see I am trying to set a private field for a type. Is there another way?
EDIT This compiles. Will it do the same thing?
private void SetPrivateField<T>(object item, string fieldName, object value) {
typeof(T).GetRuntimeField(fieldName).SetValue(item,value);
}