/// <summary> /// Convenience method, primarily useful to allow for inference of the /// first argument to the constructor. /// </summary> /// <typeparam name="T">Type to describe.</typeparam> /// <param name="parseHandler">Delegate used to parse strings with the /// given type.</param> /// <param name="isSigned">True if this type is signed; false if it's /// unsigned.</param> /// <param name="displayName">Optionally provides a custom display /// name for the type, or null to use the default.</param> /// <returns>The constructed object.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="parseHandler"/> /// is null.</exception> public static IntegerArgumentType Create <T>(IntegerArgumentTypeParseHandler <T> parseHandler, bool isSigned, string displayName = null) { if (parseHandler == null) { throw new ArgumentNullException(nameof(parseHandler)); } return(new IntegerArgumentType(typeof(T), (s, styles) => parseHandler(s, styles), isSigned, displayName)); }
/// <summary> /// Constructs a new object to describe the provided integer type. /// </summary> /// <param name="type">Type to describe.</param> /// <param name="parseHandler">Delegate used to parse strings with the /// given type.</param> /// <param name="isSigned">True if this type is signed; false if it's /// unsigned.</param> public IntegerArgumentType(Type type, IntegerArgumentTypeParseHandler <object> parseHandler, bool isSigned) : base(type) { if (!type.GetTypeInfo().IsPrimitive) { throw new ArgumentOutOfRangeException(nameof(type)); } _parseHandler = parseHandler; IsSigned = isSigned; }
public static IntegerArgumentType Create <T>(IntegerArgumentTypeParseHandler <T> parseHandler, bool isSigned) { Debug.Assert(parseHandler != null); return(new IntegerArgumentType(typeof(T), (s, styles) => parseHandler(s, styles), isSigned)); }