{"action":"closed","issue":{"url":"https://api.github.com/repos/adamabdelhamed/PowerArgs/issues/137","repository_url":"https://api.github.com/repos/adamabdelhamed/PowerArgs","labels_url":"https://api.github.com/repos/adamabdelhamed/PowerArgs/issues/137/labels{/name}","comments_url":"https://api.github.com/repos/adamabdelhamed/PowerArgs/issues/137/comments","events_url":"https://api.github.com/repos/adamabdelhamed/PowerArgs/issues/137/events","html_url":"https://github.com/adamabdelhamed/PowerArgs/issues/137","id":372330765,"node_id":"MDU6SXNzdWUzNzIzMzA3NjU=","number":137,"title":"Allow complex default values","user":{"login":"floatas","id":7883111,"node_id":"MDQ6VXNlcjc4ODMxMTE=","avatar_url":"https://avatars2.githubusercontent.com/u/7883111?v=4","gravatar_id":"","url":"https://api.github.com/users/floatas","html_url":"https://github.com/floatas","followers_url":"https://api.github.com/users/floatas/followers","following_url":"https://api.github.com/users/floatas/following{/other_user}","gists_url":"https://api.github.com/users/floatas/gists{/gist_id}","starred_url":"https://api.github.com/users/floatas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floatas/subscriptions","organizations_url":"https://api.github.com/users/floatas/orgs","repos_url":"https://api.github.com/users/floatas/repos","events_url":"https://api.github.com/users/floatas/events{/privacy}","received_events_url":"https://api.github.com/users/floatas/received_events","type":"User","site_admin":false},"labels":[{"id":156902754,"node_id":"MDU6TGFiZWwxNTY5MDI3NTQ=","url":"https://api.github.com/repos/adamabdelhamed/PowerArgs/labels/ANSWERED!","name":"ANSWERED!","color":"009800","default":false},{"id":2538429,"node_id":"MDU6TGFiZWwyNTM4NDI5","url":"https://api.github.com/repos/adamabdelhamed/PowerArgs/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-21T16:13:42Z","updated_at":"2018-12-19T17:15:21Z","closed_at":"2018-12-19T17:15:20Z","author_association":"CONTRIBUTOR","body":"Hi, I'm just starting to use this library and wanted to discuss one issue before making any real changes and pull requests. I wanted to set temp directory path as default value. I come up with solution, but it's not prettiest solution and can be improved by making few small changes to PowerArgs. \r\nMaybe there is different way to achieve same result ?\r\n\r\nComplex default value now:\r\n```\r\n    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter)]\r\n    public class TempDirPathAsDefaultValue : DefaultValueAttribute\r\n    {\r\n        static string TempDir = \"\";\r\n        static TempDirPathAsDefaultValue()\r\n        {\r\n            TempDir = System.IO.Path.GetTempPath();\r\n        }\r\n\r\n        public TempDirPathAsDefaultValue() : base(TempDir)\r\n        {\r\n        }\r\n    }\r\n```\r\n\r\n\r\n\r\nTwo small changes are required (see comments in code):\r\n```\r\n    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter)]\r\n    public class DefaultValueAttribute : ArgHook, ICommandLineArgumentMetadata\r\n    {\r\n        public object Value { get; protected set; }//<- Protected setter\r\n\r\n\r\n        public DefaultValueAttribute(object value)\r\n        {\r\n            Value = value;\r\n        }\r\n\r\n        protected DefaultValueAttribute()//<- protected constructor\r\n        {\r\n        }\r\n\r\n        public override void BeforePopulateProperty(HookContext Context)\r\n        {\r\n            if (Context.ArgumentValue == null) Context.ArgumentValue = Value.ToString();\r\n        }\r\n    }\r\n```\r\n\r\nComplex default value after changes:\r\n```\r\n    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter)]\r\n    public class TempDirPathAsDefaultValue : DefaultValueAttribute\r\n    {\r\n        public TempDirPathAsDefaultValue() : base()\r\n        {\r\n            Value = System.IO.Path.GetTempPath();\r\n        }\r\n    }\r\n```\r\n\r\nLet me know what you think, I can make pull request for this + tests if needed."}}
{"actor":{"display_login":"adamabdelhamed"}}