DeveloperConsole.ParseStringToObject C# (CSharp) Method

ParseStringToObject() private method

private ParseStringToObject ( Type objectType, string argument, object &returnObject ) : bool
objectType Type
argument string
returnObject object
return bool
	bool ParseStringToObject(Type objectType, string argument, ref object returnObject)
	{
		bool paramSuccess = false;
		
		if (objectType == typeof(int))
		{
			int intResult = 0;
			paramSuccess = int.TryParse(argument, out intResult);
			if (paramSuccess)
			{
				returnObject = intResult;
				return true;
			}
			return false;
		}
		else if (objectType == typeof(float))
		{
			float floatResult = 0;
			paramSuccess = float.TryParse(argument, out floatResult);
			if (paramSuccess)
			{
				returnObject = floatResult;
				return true;
			}
			return false;
		}
		else if (objectType == typeof(double))
		{
			double doubleResult = 0;
			paramSuccess = double.TryParse(argument, out doubleResult);
			if (paramSuccess)
			{
				returnObject = doubleResult;
				return true;
			}
			return false;
		}
		else if (objectType == typeof(bool))
		{
			if (argument.ToUpper() == "FALSE")
			{
				returnObject = false;
				return true;
			}
			else if (argument.ToUpper() == "TRUE")
			{
				returnObject = true;
				return true;
			}
			else
			{
				int intResult = 0;
				paramSuccess = int.TryParse(argument, out intResult);
				if (paramSuccess)
				{
					returnObject = (intResult == 0) ? false : true;
					return true;
				}
				return false;
			}
		}
		else if (objectType == typeof(string))
		{
			returnObject = argument;
			return true;
		}
		else if (objectType == typeof(Vector2))
		{
			string[] splitArg = argument.Split(',');
			if (splitArg.Length == 2)
			{
				float xResult = 0f;
				bool xSuccess = false;
				xSuccess = float.TryParse(splitArg[0], out xResult);
				
				float yResult = 0f;
				bool ySuccess = false;
				ySuccess = float.TryParse(splitArg[2], out yResult);
				
				if (xSuccess && ySuccess)
				{
					returnObject = new Vector2(xResult, yResult);
					return true;
				}
				else
				{
					return false;
				}
			}
		}
		else if (objectType == typeof(Vector3))
		{
			string[] splitArg = argument.Split(',');
			if (splitArg.Length == 3)
			{
				float xResult = 0f;
				bool xSuccess = false;
				xSuccess = float.TryParse(splitArg[0], out xResult);
				
				float yResult = 0f;
				bool ySuccess = false;
				ySuccess = float.TryParse(splitArg[1], out yResult);
				
				float zResult = 0f;
				bool zSuccess = false;
				zSuccess = float.TryParse(splitArg[2], out zResult);
				
				if (xSuccess && ySuccess && zSuccess)
				{
					returnObject = new Vector3(xResult, yResult, zResult);
					return true;
				}
				else
				{
					return false;
				}
			}
		}
		else if (objectType == typeof(Quaternion))
		{
			string[] splitArg = argument.Split(',');
			if (splitArg.Length == 4)
			{
				float xResult = 0f;
				bool xSuccess = false;
				xSuccess = float.TryParse(splitArg[0], out xResult);
				
				float yResult = 0f;
				bool ySuccess = false;
				ySuccess = float.TryParse(splitArg[1], out yResult);
				
				float zResult = 0f;
				bool zSuccess = false;
				zSuccess = float.TryParse(splitArg[2], out zResult);
				
				float wResult = 0f;
				bool wSuccess = false;
				wSuccess = float.TryParse(splitArg[3], out wResult);
				
				if (xSuccess && ySuccess && zSuccess && wSuccess)
				{
					returnObject = new Quaternion(xResult, yResult, zResult, wResult);
					return true;
				}
				else
				{
					return false;
				}
			}
		}
		else if (objectType == typeof(Rect))
		{
			string[] splitArg = argument.Split(',');
			if (splitArg.Length == 4)
			{
				float xResult = 0f;
				bool xSuccess = false;
				xSuccess = float.TryParse(splitArg[0], out xResult);
				
				float yResult = 0f;
				bool ySuccess = false;
				ySuccess = float.TryParse(splitArg[1], out yResult);
				
				float wResult = 0f;
				bool wSuccess = false;
				wSuccess = float.TryParse(splitArg[2], out wResult);
				
				float hResult = 0f;
				bool hSuccess = false;
				hSuccess = float.TryParse(splitArg[3], out hResult);
				
				if (xSuccess && ySuccess && wSuccess && hSuccess)
				{
					returnObject = new Rect(xResult, yResult, wResult, hResult);
					return true;
				}
				else
				{
					return false;
				}
			}
		}
		else if (objectType == typeof(Color))
		{
			string[] splitArg = argument.Split(',');
			if (splitArg.Length == 4)
			{
				float xResult = 0f;
				bool xSuccess = false;
				xSuccess = float.TryParse(splitArg[0], out xResult);
				
				float yResult = 0f;
				bool ySuccess = false;
				ySuccess = float.TryParse(splitArg[1], out yResult);
				
				float zResult = 0f;
				bool zSuccess = false;
				zSuccess = float.TryParse(splitArg[2], out zResult);
				
				float wResult = 0f;
				bool wSuccess = false;
				wSuccess = float.TryParse(splitArg[2], out wResult);
				
				if (xSuccess && ySuccess && zSuccess && wSuccess)
				{
					returnObject = new Color(xResult, yResult, zResult, wResult);
					return true;
				}
				else
				{
					return false;
				}
			}
		}
		
		return false;
	}