Esempio n. 1
0
        /// <summary>
        /// Parses the specified field.
        /// </summary>
        /// <param name="field">The unicode string representing the native object to be parsed.</param>
        /// <param name="valueType">The managed type to be used.</param>
        /// <returns>A managed object that might safely be used by Gallio assertion failure engine.</returns>
        /// <exception cref="ModelException">Thrown if the parsing fails.</exception>
        public static object Parse(string field, NativeValueType valueType)
        {
            try
            {
                switch (valueType)
                {
                case NativeValueType.Raw:
                    return(new NativeRawObject(field));

                case NativeValueType.String:
                    return(field);

                case NativeValueType.Boolean:
                    return(Boolean.Parse(field));

                case NativeValueType.Char:
                    return(Char.Parse(field));

                case NativeValueType.Byte:
                    return(Byte.Parse(field));

                case NativeValueType.Int16:
                    return(Int16.Parse(field));

                case NativeValueType.UInt16:
                    return(UInt16.Parse(field));

                case NativeValueType.Int32:
                    return(Int32.Parse(field));

                case NativeValueType.UInt32:
                    return(UInt32.Parse(field));

                case NativeValueType.Int64:
                    return(Int64.Parse(field));

                case NativeValueType.UInt64:
                    return(UInt64.Parse(field));

                case NativeValueType.Single:
                    return(Single.Parse(field));

                case NativeValueType.Double:
                    return(Double.Parse(field));

                case NativeValueType.Address:
                    return(NativeIntPtr.Parse(field));

                default:
                    throw new ModelException(String.Format("Cannot parse the native unmanaged type value: unsupported type '{0}'.", valueType));
                }
            }
            catch (FormatException exception)
            {
                throw new ModelException(String.Format("Cannot parse the native unmanaged type value: invalid value '{0}' of type '{1}'.", field, valueType), exception);
            }
        }
Esempio n. 2
0
 public void Print()
 {
     var value = new NativeIntPtr(0x4589df);
     string text = value.ToString();
     Assert.AreEqual("0x004589df", text);
 }