Comments (5)
[ValueArgument(typeof(int))] - I am surprised that this does not crash.
property.SetValue(null) where property is of type int.... weird
But this
[ValueArgument(typeof(int?), "MaxRequestLogCount", Optional = true, DefaultValue = null)]
public int? MaxRequestLogCount { get; set; }
seem to work fine for me. And isn't DefaultValue=null redundant?
from commandlineparser.
Maybe it's just Net Core 2.0 related???
See https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.StandAlone.NETCoreApp
And the command is:
dotnet run -f netcoreapp2.0 --MaxRequestLogCount 100
The error is like:
Type System.Nullable`1[System.Int32] of argument 100 is not a built-in type.Set ConvertValueHandler to a conversion routine for this type or define static method Parse(string stringValue, Cu
ltureInfo cultureInfo) that can Parse your type from string.
Usage:
--Port[optional]... Port to listen on.
--Urls[optional]... URL(s) to listen on.
--AllowPartialMapping[optional]... Allow Partial Mapping (default set to false).
--StartAdminInterface[optional]... Start the AdminInterface (default set to true).
--ReadStaticMappings[optional]... Read StaticMappings from ./__admin/mappings (default set to true).
--ProxyURL[optional]... The ProxyURL to use.
--SaveProxyMapping[optional]... Save the proxied request and response mapping files in ./__admin/mappings. (default set to true).
--X509Certificate2ThumbprintOrSubjectName[optional]... The X509Certificate2 Thumbprint or SubjectName to use.
--AdminUsername[optional]... The username needed for __admin access.
--AdminPassword[optional]... The password needed for __admin access.
--RequestLogExpirationDuration[optional]... The RequestLog expiration in hours (optional).
--MaxRequestLogCount[optional]... The MaxRequestLog count (optional).
Unhandled Exception: CommandLineParser.Exceptions.InvalidConversionException: Type System.Nullable`1[System.Int32] of argument 100 is not a built-in type.Set ConvertValueHandler to a convers
ion routine for this type or define static method Parse(string stringValue, CultureInfo cultureInfo) that can Parse your type from string.
at CommandLineParser.Arguments.ValueArgument`1.DefaultConvert(String stringValue)
at CommandLineParser.Arguments.ValueArgument`1.Convert(String stringValue)
at CommandLineParser.Arguments.ValueArgument`1.Parse(IList`1 args, Int32& i)
at CommandLineParser.CommandLineParser.ParseCommandLine(String[] args)
at WireMock.Net.StandAlone.StandAloneApp.Start(String[] args) in C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net.StandAlone\StandAloneApp.cs:line 146
at WireMock.Net.StandAlone.NETCoreApp.Program.Main(String[] args) in C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\examples\WireMock.Net.StandAlone.NETCoreApp\Program.cs:line 14
from commandlineparser.
from commandlineparser.
I doubt if this is Net Core 2.0 related, actually I think that this code (
) cannot work if it's a Nullable type.I think you need this code:
if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
valueType = Nullable.GetUnderlyingType(valueType);
}
MethodInfo mi = valueType.GetMethod("Parse", new [] { typeof(string), typeof(CultureInfo)});
if (mi != null)
{
if (mi.IsStatic && mi.ReturnType == valueType)
{
return stringValue != null ? (TValue)mi.Invoke(null, new object[] { stringValue, _cultureInfo }) : null;
}
}
See my example at:
https://github.com/WireMock-Net/WireMock.Net-docker/blob/master/CommandLineParserTest/Program.cs#L16-L19
Also verify for null:
https://github.com/WireMock-Net/WireMock.Net-docker/blob/master/CommandLineParserTest/Program.cs#L46
from commandlineparser.
Should I make a PR + unit-tests for this issue?
from commandlineparser.
Related Issues (20)
- EnumeratedValueArgument w/ Enum HOT 2
- Error in the wiki - "Show Usage" section HOT 1
- Question on field and row terminators HOT 5
- Support for Folder Argument HOT 1
- getopt_long syntax HOT 1
- CheckMandatoryArguments not being evaluated HOT 1
- Message typo HOT 1
- Setup Code Shown On Documentation Page Missing Needed Parentheses HOT 1
- v3.0.20 binary is not signed HOT 10
- Parse failure error should say which argument is failing
- Default values are being ignored - regression HOT 2
- DefaultValue & Description for EnumeratedValueArgument?
- How to redirect log to Serilog
- Typo in EArgumentGroupCondition enum HOT 1
- Multiple groups of arguments
- RegexValueArgumentAttribute(char shortName, string longName, string pattern) constructor declaration error HOT 5
- Adding alternative methods for PrintUsage(…), PrintValueInfo etc for using in Non-Console application.
- Make it so that only one of the group of parameters can be specified
- Wrong display for ArgumentRequiresOtherArgumentsCertification
- Is this NuGet package being maintained?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commandlineparser.