コード例 #1
0
        /// <summary>
        /// Creates a <see cref="NPCChatConditionalParameter"/> for the given <paramref name="valueType"/> that contains
        /// the given <paramref name="value"/>.
        /// </summary>
        /// <param name="valueType">Type <see cref="NPCChatConditionalParameterType"/> that describes the value type to use
        /// for the <see cref="NPCChatConditionalParameter"/>.</param>
        /// <param name="value">The value for the <see cref="NPCChatConditionalParameter"/>. Must be a valid type for the
        /// given <paramref name="valueType"/>.</param>
        /// <returns>A <see cref="NPCChatConditionalParameter"/> created using the given <paramref name="valueType"/>
        /// and <paramref name="value"/>.</returns>
        /// <exception cref="ArgumentException">The <paramref name="valueType"/> did not match the expected type
        /// of the <paramref name="value"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The <paramref name="valueType"/> is not a defined value of the
        /// <see cref="NPCChatConditionalParameterType"/> enum.</exception>
        public static NPCChatConditionalParameter CreateParameter(NPCChatConditionalParameterType valueType, object value)
        {
            switch (valueType)
            {
            case NPCChatConditionalParameterType.String:
                if (value.GetType() != typeof(string))
                {
                    throw GetInvalidTypeForValueException(valueType, value);
                }
                return(CreateParameterAsString((string)value));

            case NPCChatConditionalParameterType.Float:
                if (value.GetType() != typeof(float))
                {
                    throw GetInvalidTypeForValueException(valueType, value);
                }
                return(CreateParameterAsFloat((float)value));

            case NPCChatConditionalParameterType.Integer:
                if (value.GetType() != typeof(int))
                {
                    throw GetInvalidTypeForValueException(valueType, value);
                }
                return(CreateParameterAsInteger((int)value));

            default:
                throw new ArgumentOutOfRangeException("valueType", "Invalid NPCChatConditionalParameterType.");
            }
        }
コード例 #2
0
        static ArgumentException GetInvalidTypeForValueException(NPCChatConditionalParameterType valueType, object value)
        {
            const string errmsg =
                "The given value [{0}] is of Type `{1}`, which is not a" +
                " valid type for NPCChatConditionalParameterType `{2}`.";
            const string paramName = "value";

            return(new ArgumentException(string.Format(errmsg, value, value.GetType(), valueType), paramName));
        }
コード例 #3
0
        /// <summary>
        /// Creates a <see cref="NPCChatConditionalParameter"/> for the given <see cref="NPCChatConditionalParameterType"/>.
        /// </summary>
        /// <param name="valueType">The <see cref="NPCChatConditionalParameterType"/> to create the parameter for.</param>
        /// <returns>A <see cref="NPCChatConditionalParameter"/> for the given <see cref="NPCChatConditionalParameterType"/>.</returns>
        /// <exception cref="ArgumentOutOfRangeException">The <paramref name="valueType"/> is not
        /// a defined value of the <see cref="NPCChatConditionalParameterType"/> enum.</exception>
        public static NPCChatConditionalParameter CreateParameter(NPCChatConditionalParameterType valueType)
        {
            switch (valueType)
            {
            case NPCChatConditionalParameterType.Float:
                return(CreateParameterAsFloat(default(float)));

            case NPCChatConditionalParameterType.Integer:
                return(CreateParameterAsInteger(default(int)));

            case NPCChatConditionalParameterType.String:
                return(CreateParameterAsString(default(string)));

            default:
                throw new ArgumentOutOfRangeException("valueType", "Invalid NPCChatConditionalParameterType.");
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a <see cref="NPCChatConditionalParameter"/> for the given <paramref name="valueType"/> that contains
        /// the given <paramref name="value"/>.
        /// </summary>
        /// <param name="valueType">Type <see cref="NPCChatConditionalParameterType"/> that describes the value type to use
        /// for the <see cref="NPCChatConditionalParameter"/>.</param>
        /// <param name="value">The value for the <see cref="NPCChatConditionalParameter"/>. Must be a valid type for the
        /// given <paramref name="valueType"/>.</param>
        /// <returns>A <see cref="NPCChatConditionalParameter"/> created using the given <paramref name="valueType"/>
        /// and <paramref name="value"/>.</returns>
        /// <exception cref="ArgumentException">The <paramref name="valueType"/> did not match the expected type
        /// of the <paramref name="value"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The <paramref name="valueType"/> is not a defined value of the
        /// <see cref="NPCChatConditionalParameterType"/> enum.</exception>
        public static NPCChatConditionalParameter CreateParameter(NPCChatConditionalParameterType valueType, object value)
        {
            switch (valueType)
            {
                case NPCChatConditionalParameterType.String:
                    if (value.GetType() != typeof(string))
                        throw GetInvalidTypeForValueException(valueType, value);
                    return CreateParameterAsString((string)value);

                case NPCChatConditionalParameterType.Float:
                    if (value.GetType() != typeof(float))
                        throw GetInvalidTypeForValueException(valueType, value);
                    return CreateParameterAsFloat((float)value);

                case NPCChatConditionalParameterType.Integer:
                    if (value.GetType() != typeof(int))
                        throw GetInvalidTypeForValueException(valueType, value);
                    return CreateParameterAsInteger((int)value);

                default:
                    throw new ArgumentOutOfRangeException("valueType", "Invalid NPCChatConditionalParameterType.");
            }
        }
コード例 #5
0
        static ArgumentException GetInvalidTypeForValueException(NPCChatConditionalParameterType valueType, object value)
        {
            const string errmsg =
                "The given value [{0}] is of Type `{1}`, which is not a" +
                " valid type for NPCChatConditionalParameterType `{2}`.";
            const string paramName = "value";

            return new ArgumentException(string.Format(errmsg, value, value.GetType(), valueType), paramName);
        }
コード例 #6
0
        /// <summary>
        /// Creates a <see cref="NPCChatConditionalParameter"/> for the given <see cref="NPCChatConditionalParameterType"/>.
        /// </summary>
        /// <param name="valueType">The <see cref="NPCChatConditionalParameterType"/> to create the parameter for.</param>
        /// <returns>A <see cref="NPCChatConditionalParameter"/> for the given <see cref="NPCChatConditionalParameterType"/>.</returns>
        /// <exception cref="ArgumentOutOfRangeException">The <paramref name="valueType"/> is not
        /// a defined value of the <see cref="NPCChatConditionalParameterType"/> enum.</exception>
        public static NPCChatConditionalParameter CreateParameter(NPCChatConditionalParameterType valueType)
        {
            switch (valueType)
            {
                case NPCChatConditionalParameterType.Float:
                    return CreateParameterAsFloat(default(float));

                case NPCChatConditionalParameterType.Integer:
                    return CreateParameterAsInteger(default(int));

                case NPCChatConditionalParameterType.String:
                    return CreateParameterAsString(default(string));

                default:
                    throw new ArgumentOutOfRangeException("valueType", "Invalid NPCChatConditionalParameterType.");
            }
        }