/// <summary> /// Constructor for use by derived classes. /// </summary> /// <param name="type">Type described by this object.</param> /// <param name="elementType">Type of elements stored within the /// collection type described by this object.</param> protected CollectionArgumentTypeBase(Type type, Type elementType) : base(type) { if (!ArgumentType.TryGetType(elementType, out _elementArgumentType)) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Strings.ElementTypeNotSupported, type)); } }
/// <summary> /// Primary constructor. /// </summary> /// <param name="type">The flag-based enumeration type to describe. /// </param> public FlagsEnumArgumentType(Type type) : base(type) { if (type.GetTypeInfo().GetSingleAttribute <FlagsAttribute>() == null) { throw new ArgumentOutOfRangeException(nameof(type)); } _underlyingType = Enum.GetUnderlyingType(type); if (!ArgumentType.TryGetType(_underlyingType, out IArgumentType underlyingArgType)) { throw new NotSupportedException(nameof(type)); } _underlyingIntegerType = (IntegerArgumentType)underlyingArgType; }
/// <summary> /// Constructs an object to describe the provided KeyValuePair type. /// </summary> /// <param name="type">The KeyValuePair type to describe.</param> public KeyValuePairArgumentType(Type type) : base(type) { if (!type.GetTypeInfo().IsGenericType) { throw new ArgumentOutOfRangeException(nameof(type)); } if (!type.GetGenericTypeDefinition().IsEffectivelySameAs(typeof(KeyValuePair <,>))) { throw new ArgumentOutOfRangeException(nameof(type)); } var typeParams = type.GetTypeInfo().GetGenericArguments(); if (!ArgumentType.TryGetType(typeParams[0], out _keyType) || !ArgumentType.TryGetType(typeParams[1], out _valueType)) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Strings.ConstituentTypeNotSupported, type.Name)); } _constructor = type.GetTypeInfo().GetConstructor(typeParams); Debug.Assert(_constructor != null); }
/// <summary> /// Constructor. /// </summary> /// <param name="type">The primitive object type to find a corresponding /// IArgumentType implementation for (e.g. System.String).</param> /// <param name="parser">Optionally provides an override implementation /// of the base argument type's string parser implementation.</param> /// <param name="formatter">Optionally provides an override /// implementation of the base argument type's object formatter /// implementation.</param> /// <param name="completer">Optionally provides an override /// implementation of the base argument type's string completer /// implementation.</param> public ArgumentTypeExtension(Type type, IStringParser parser = null, IObjectFormatter formatter = null, IStringCompleter completer = null) : this(ArgumentType.GetType(type), parser, formatter, completer) { }