public void Initialize(int phase, double state)
        {
            ArgAssert.GreaterThan(state, "state", _downwardsThresholds[phase], string.Format("_downwardsThresholds[{0}]", phase));
            ArgAssert.LessThan(state, "state", _upwardsThresholds[phase], string.Format("_upwardsThresholds[{0}]", phase));

            _phase = phase;
            _state = state;
        }
Exemple #2
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());
        }
        private void ValidateThresholds()
        {
            ArgAssert.AtLeast(_downwardsThresholds.Count, "thresholds.Count", 2);
            ArgAssert.Equal(_downwardsThresholds.Count, "downwardsThreholds.Count", _upwardsThresholds.Count, "upwardsTresholds.Count");

            for (var i = 1; i < PhaseCount; i++)
            {
                ArgAssert.GreaterThan
                    (_upwardsThresholds[i - 1], string.Format("_upwardsThresholds[{0}]", i - 1),
                    _downwardsThresholds[i], string.Format("_downwardsThresholds[{0}]", i));

                ArgAssert.GreaterThan
                    (_upwardsThresholds[i], string.Format("_upwardsThresholds[{0}]", i),
                    _upwardsThresholds[i - 1], string.Format("_upwardsThresholds[{0}]", i - 1));

                ArgAssert.GreaterThan
                    (_downwardsThresholds[i], string.Format("_downwardsThresholds[{0}]", i),
                    _downwardsThresholds[i - 1], string.Format("_downwardsThresholds[{0}]", i - 1));
            }
        }
Exemple #6
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 NoNullIn_array_with_nulls_throws_NullReferenceException()
 {
     ArgAssert.NoNullIn(new string[] { "aa", null, "bb" }, "someArg");
 }
 public void NoNullIn_array_without_nulls_does_nothing()
 {
     ArgAssert.NoNullIn(new string[] { "aa", "bb" }, "someArg");
 }
 public void NoNullIn_empty_array_does_nothing()
 {
     ArgAssert.NoNullIn(new string[0], "someArg");
 }
 public void NoNullIn_null_argument_throws_NullReferenceException()
 {
     string[] arg = null;
     ArgAssert.NoNullIn(arg, "someArg");
 }
 public void NotNull_null_throws_NullReferenceException()
 {
     ArgAssert.NotNull(null, "someArg");
 }
 public void NotNull_not_null_does_nothing()
 {
     ArgAssert.NotNull("foo", "someArg");
 }