Example #1
0
        public static T ParseString <T>(string s)
        {
            ArgAssert.NotNull(s, "s");

            var converter = TypeDescriptor.GetConverter(typeof(T));

            return((T)(converter.ConvertFromInvariantString(s)));
        }
        /// <summary>
        /// Deserializes an object from a YAML string. For more details see the YamlDotNet lib.
        /// </summary>
        /// <typeparam name="Type">The type of the serialized object</typeparam>
        /// <param name="yamlData">The YAML data to deserialize</param>
        /// <returns>The deserialized object</returns>
        public static Type Deserialize <Type>(string yamlData)
        {
            ArgAssert.NotNull(yamlData, "yamlData");

            var stringReader = new StringReader(yamlData);

            var deserializer = new Deserializer();

            return(deserializer.Deserialize <Type>(stringReader));
        }
        /// <summary>
        /// Serializes an object into a YAML string. For more details see the YamlDotNet lib.
        /// </summary>
        /// <typeparam name="Type">The type of the serialized object</typeparam>
        /// <param name="objectToSerialize">The object to serialize</param>
        /// <returns>The serialized object. Contains Windows-style line endidng.</returns>
        public static string Serialize <Type>(Type objectToSerialize)
        {
            ArgAssert.NotNull(objectToSerialize, "objectToSerialize");

            var stringWriter = new StringWriter();
            var serializer   = new Serializer();

            serializer.Serialize(stringWriter, objectToSerialize);

            return(stringWriter.ToString());
        }
Example #4
0
        public static string Repeat(this string @this, int times)
        {
            ArgAssert.NotNull(@this, "this");
            ArgAssert.AtLeast(times, "times", 0);

            if (@this == "" || times == 0)
            {
                return("");
            }

            if (times == 1)
            {
                return(@this);
            }

            var result = new StringBuilder(@this.Length * times);

            for (var i = 0; i < times; i++)
            {
                result.Append(@this);
            }

            return(result.ToString());
        }
 public void NotNull_null_throws_NullReferenceException()
 {
     ArgAssert.NotNull(null, "someArg");
 }
 public void NotNull_not_null_does_nothing()
 {
     ArgAssert.NotNull("foo", "someArg");
 }