private static object ConvertValue()

in src/main/csharp/Util/IntrospectionSupport.cs [288:350]


		private static object ConvertValue(string inputString, Type targetType)
		{
			// If the target member is an enumeration, get the enumeration
			// value or combined (or-ed) values
			object value;
			if(targetType.IsEnum)
			{
				if(inputString.Contains("+"))
				{
					string[] inputValues = inputString.Split('+');

					FieldInfo fieldInfo = targetType.GetField(inputValues[0],
						BindingFlags.Public
						| BindingFlags.Static
						| BindingFlags.IgnoreCase);
					if(fieldInfo == null)
					{
						throw new NMSException(string.Format(
							"Invalid {0} value \"{1}\"", targetType.Name,
							inputValues[0]));
					}
					dynamic val = fieldInfo.GetValue(null);

					for(int v = 1; v < inputValues.Length; v++)
					{
						fieldInfo = targetType.GetField(inputValues[v],
							BindingFlags.Public
							| BindingFlags.Static
							| BindingFlags.IgnoreCase);
						if(fieldInfo == null)
						{
							throw new NMSException(string.Format(
								"Invalid {0} value \"{1}\"", targetType.Name,
								inputValues[v]));
						}
						val = (dynamic)val | (dynamic)fieldInfo.GetValue(null);
					}

					value = Convert.ChangeType(val, targetType);
				}
				else
				{
					FieldInfo fieldInfo = targetType.GetField(inputString,
                                 BindingFlags.Public
                               | BindingFlags.Static
                               | BindingFlags.IgnoreCase);
					if(fieldInfo == null)
					{
						throw new NMSException(string.Format(
							"Invalid {0} value \"{1}\"", targetType.Name,
							inputString));
					}
					value = fieldInfo.GetValue(null);
				}
			}
			else
			{
				// Not an enumeration
				value = Convert.ChangeType(inputString,
					targetType, CultureInfo.InvariantCulture);
			}
			return value;
		}