internal static void SetProperty(this IObjectSummary obj, string name, object value) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } var prop = obj.GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance); if (prop != null && prop.CanWrite) { if (value is SwitchParameter sp) { value = sp.IsPresent; } prop.SetValue(obj, value, null); } else { throw new ArgumentException("No writeable property found."); } }
internal static T GetProperty <T>(this IObjectSummary obj, string name) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } var prop = obj.GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance); if (prop != null && prop.CanRead) { return((T)prop.GetValue(obj)); } else { throw new ArgumentException("No property found."); } }