/// <summary> /// Resolves a parameter value based on the provided object. /// </summary> /// <param name="descriptor">Parameter descriptor.</param> /// <param name="value">Value to resolve the parameter value from.</param> /// <returns>The parameter value.</returns> public virtual object ResolveParameter(ParameterDescriptor descriptor, IParameterValue value) { if (value.GetType() == descriptor.Type) { return value; } return value.ConvertTo(descriptor.Type); }
private static bool GetParameterString(CommandEventArgs args, string paramName, bool throwException, bool allowNull, out string value) { value = null; IParameterValue parameterValue = GetParameterValue(args, paramName, throwException); if (parameterValue == null) { return(false); } IStringParameterValue param = parameterValue as IStringParameterValue; if (param == null) { if (throwException) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CommandParameterIncorrectType, args.Command.Name, paramName, parameterValue.GetType().FullName, typeof(IStringParameterValue).FullName)); } return(false); } value = param.Value; if (string.IsNullOrEmpty(value) && !allowNull) { if (throwException) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CommandParameterValueIsEmpty, args.Command.Name, paramName)); } } return(true); }
public void SerializeParameterValue(ISerializer s, ref IParameterValue value) { var genericType = value.GetType().GetGenericArguments()[0]; if (value is IParameterValue <bool> ) { var typedValueParameter = value as IParameterValue <bool>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <bool[]> ) { var typedValueParameter = value as IParameterValue <bool[]>; typedValueParameter.Value.Serialize(s); } if (value is IParameterValue <byte> ) { var typedValueParameter = value as IParameterValue <byte>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <byte[]> ) { var typedValueParameter = value as IParameterValue <byte[]>; typedValueParameter.Value.Serialize(s); } if (value is IParameterValue <Single> ) { var typedValueParameter = value as IParameterValue <Single>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Single[]> ) { var typedValueParameter = value as IParameterValue <Single[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Double> ) { var typedValueParameter = value as IParameterValue <Double>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Double[]> ) { var typedValueParameter = value as IParameterValue <Double[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Int16> ) { var typedValueParameter = value as IParameterValue <Int16>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Int16[]> ) { var typedValueParameter = value as IParameterValue <Int16>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Int32> ) { var typedValueParameter = value as IParameterValue <Int32>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Int32[]> ) { var typedValueParameter = value as IParameterValue <Int32>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <UInt16> ) { var typedValueParameter = value as IParameterValue <UInt16>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <UInt16[]> ) { var typedValueParameter = value as IParameterValue <UInt16>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <UInt32> ) { var typedValueParameter = value as IParameterValue <UInt32>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <UInt32[]> ) { var typedValueParameter = value as IParameterValue <UInt32>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Float2> ) { var typedValueParameter = value as IParameterValue <Float2>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Float2[]> ) { var typedValueParameter = value as IParameterValue <Float2[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Float3> ) { var typedValueParameter = value as IParameterValue <Float3>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Float3[]> ) { var typedValueParameter = value as IParameterValue <Float3[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Float4> ) { var typedValueParameter = value as IParameterValue <Float4>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Float4[]> ) { var typedValueParameter = value as IParameterValue <Float4[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Vector2> ) { var typedValueParameter = value as IParameterValue <Vector2>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Vector2[]> ) { var typedValueParameter = value as IParameterValue <Vector2[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Vector3> ) { var typedValueParameter = value as IParameterValue <Vector3>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Vector3[]> ) { var typedValueParameter = value as IParameterValue <Vector3[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Vector4> ) { var typedValueParameter = value as IParameterValue <Vector4>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Vector4[]> ) { var typedValueParameter = value as IParameterValue <Vector4[]>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Matrix4> ) { var typedValueParameter = value as IParameterValue <Matrix4>; typedValueParameter.Value.Serialize(s); } else if (value is IParameterValue <Matrix4[]> ) { var typedValueParameter = value as IParameterValue <Matrix4[]>; typedValueParameter.Value.Serialize(s); } else { throw new System.Exception("Unhandled IParameterType<ValueType> value type"); } }