Server.Commands.Add.ParseValue C# (CSharp) Méthode

ParseValue() public static méthode

public static ParseValue ( Type type, string value ) : object
type System.Type
value string
Résultat object
		public static object ParseValue( Type type, string value )
		{
			try
			{
				if ( IsEnum( type ) )
				{
					return Enum.Parse( type, value, true );
				}
				else if ( IsType( type ) )
				{
					return ScriptCompiler.FindTypeByName( value );
				}
				else if ( IsParsable( type ) )
				{
					return ParseParsable( type, value );
				}
				else
				{
					object obj = value;

					if ( value != null && value.StartsWith( "0x" ) )
					{
						if ( IsSignedNumeric( type ) )
							obj = Convert.ToInt64( value.Substring( 2 ), 16 );
						else if ( IsUnsignedNumeric( type ) )
							obj = Convert.ToUInt64( value.Substring( 2 ), 16 );

						obj = Convert.ToInt32( value.Substring( 2 ), 16 );
					}

					if ( obj == null && !type.IsValueType )
						return null;
					else
						return Convert.ChangeType( obj, type );
				}
			}
			catch
			{
				return null;
			}
		}