Пример #1
0
        /// <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;
        }
Пример #2
0
        /// <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);
        }