internal void SetPropertyValues(object o) { foreach (var argument in Arguments) { var property = argument.Source as PropertyInfo; if (property == null || argument.RevivedValue == null) continue; property.SetValue(o, argument.RevivedValue, null); } }
/// <summary> /// If properties on the given object contain default value attributes then this method will initalize those properties with /// the right defaults /// </summary> /// <param name="o">the object to initialize</param> public static void InitializeDefaults(object o) { if (o == null) { throw new ArgumentNullException("o cannot be null"); } var def = new CommandLineArgumentsDefinition(o.GetType()); var context = new ArgHook.HookContext(); context.Definition = def; context.Args = o; foreach (var arg in def.Arguments) { context.ArgumentValue = null; context.CurrentArgument = arg; context.RevivedProperty = null; if (arg.HasDefaultValue == false) { continue; } arg.Populate(context); } def.SetPropertyValues(o); }