private void BindFields(WizardFragment wizardFragment, Bundle args) { var fields = wizardFragment.GetType().GetFields(); //Scan the step for fields annotated with WizardState and bind value if found in step's arguments foreach (var field in fields) { if (field.CustomAttributes == null || !field.CustomAttributes.Any(a => a.AttributeType == typeof(WizardStateAttribute))) { continue; } try { if (field.GetType() == typeof(DateTime)) { field.SetValue(wizardFragment, new DateTime(args.GetLong(field.Name))); } else { //var value = args.Get(field.Name); //This wont work when passed to field.SetValue var value = args.GetValue(field.Name, field.FieldType); //Workaround field.SetValue(wizardFragment, value); } } catch (FieldAccessException f) { throw new ArgumentException(string.Format("Unable to access the field: {0}. Only public fields are supported", field.Name), f); } } }
private void BindFields(WizardFragment wizardFragment, Bundle args) { var fields = wizardFragment.GetType().GetFields(); //Scan the step for fields annotated with WizardState and bind value if found in step's arguments foreach (var field in fields) { if (field.CustomAttributes == null || !field.CustomAttributes.Any(a => a.AttributeType == typeof(WizardStateAttribute))) continue; try { if (field.GetType() == typeof(DateTime)) { field.SetValue(wizardFragment, new DateTime(args.GetLong(field.Name))); } else { //var value = args.Get(field.Name); //This wont work when passed to field.SetValue var value = args.GetValue(field.Name, field.FieldType); //Workaround field.SetValue(wizardFragment, value); } } catch (FieldAccessException f) { throw new ArgumentException(string.Format("Unable to access the field: {0}. Only public fields are supported", field.Name), f); } } }