You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How can I assign TypeConverter to Enum in Options? #944
Since CreateDirectory is quite long to type in command line, I want to allow cd as valid Operation.CreateDirectory
publicclassOperationConverter:EnumConverter{// ... candidates for other enum valuesprivatestaticreadonlyList<string>OperationCandidate=["createdirectory","cd"];// ...publicoverrideobjectConvertFrom(ITypeDescriptorContext?ctx,CultureInfo?ci,objectvalue){if(valueisstrings){stringl=s.Trim().ToLowerInvariant();// ...if(OperationCandidate.Contains(l))returnOperation.CreateDirectory;// ...}}}
But I can't assign this OperationConverter to Options.Operation. I don't see anything that might be related to this.
#83 says it is resolved, but at the bottom of that issue, someone said:
I dont think this works in the latest version. I tried annotating my option's property, but the converter is not invoked. Instead I had to register it using TypeDescriptor.AddAttributes().
But I don't see any methods named .AddAttributes() in TypeDescriptor. this has .AddAttributes(), but this doesn't seem to work.
privatestaticvoidMain(string[]args){// ...TypeDescriptor.AddAttributes(typeof(Operation),newTypeConverterAttribute(typeof(OperationConverter)));// other logic + command line parsing}
Now I'm completely lost. Wiki doesn't provide any useful information that I can easily access.
How can I assign TypeConverter to Enum in Options?
Activity