Exemple #1
0
        public void ConversionUtility_ConvertTo_4()
        {
            // targetType.IsAssignableFrom(sourceType)
            MemoryStream memoryStream = new MemoryStream();
            Stream       stream       = memoryStream;

            Assert.AreSame(stream, ConversionUtility.ConvertTo <Stream>(memoryStream));
        }
        /// <summary>
        /// Get value of the switch.
        /// </summary>
        public T GetValue <T>
        (
            [NotNull] string name,
            [CanBeNull] T defaultValue
        )
        {
            Code.NotNullNorEmpty(name, "name");

            CommandLineSwitch found = GetSwitch(name);
            T result = ReferenceEquals(found, null)
                ? defaultValue
                : ConversionUtility.ConvertTo <T>(found.Value);

            return(result);
        }
        public static T GetValueSensitive <T>
        (
            [NotNull] this MenuFile menu,
            [NotNull] string code,
            T defaultValue
        )
        {
            Sure.NotNull(menu, nameof(menu));
            Sure.NotNull(code, nameof(code));

            MenuEntry found = menu.FindEntrySensitive(code);

            return(found == null
                ? defaultValue
                : ConversionUtility.ConvertTo <T>(found.Comment));
        }
        public static T GetParameter <T>
        (
            [NotNull] this Parameter[] parameters,
            [NotNull] string name,
            [CanBeNull] T defaultValue
        )
        {
            Sure.NotNull(parameters, nameof(parameters));
            Sure.NotNullNorEmpty(name, nameof(name));

            Parameter found = parameters
                              .FirstOrDefault(p => p.Name.SameString(name));

            T result = ReferenceEquals(found, null)
                ? defaultValue
                : ConversionUtility.ConvertTo <T>(found.Value);

            return(result);
        }
Exemple #5
0
            public T GetValue <T>
            (
                [NotNull] string key,
                [CanBeNull] T defaultValue
            )
            {
                Code.NotNullNorEmpty(key, "key");

                string value = GetValue(key, null);

                if (string.IsNullOrEmpty(value))
                {
                    return(defaultValue);
                }

                T result = ConversionUtility.ConvertTo <T>(value);

                return(result);
            }
Exemple #6
0
            public Section SetValue <T>
            (
                [NotNull] string key,
                T value
            )
            {
                CheckKeyName(key);

                if (ReferenceEquals(value, null))
                {
                    SetValue(key, null);
                }
                else
                {
                    string text
                        = ConversionUtility.ConvertTo <string>(value);
                    SetValue(key, text);
                }

                return(this);
            }
        /// <summary>
        /// Adds the typed value with specified code.
        /// </summary>
        public static MenuFile Add <T>
        (
            [NotNull] this MenuFile menu,
            [NotNull] string code,
            [CanBeNull] T value
        )
        {
            Sure.NotNull(menu, nameof(menu));
            Sure.NotNull(code, nameof(code));

            if (ReferenceEquals(value, null))
            {
                menu.Add(code, string.Empty);
            }
            else
            {
                string textValue = ConversionUtility.ConvertTo <string>(value);
                menu.Add(code, textValue);
            }

            return(menu);
        }
Exemple #8
0
 public void ConversionUtility_ConvertTo_8()
 {
     ConversionUtility.ConvertTo <TargetType>(new SourceType2());
 }
Exemple #9
0
 public void ConversionUtility_ConvertTo_7()
 {
     // change type operator
     Assert.IsNotNull(ConversionUtility.ConvertTo <TargetType2>(new SourceType3()));
 }
Exemple #10
0
 public void ConversionUtility_ConvertTo_6()
 {
     // converterTo.CanConvertFrom(sourceType)
     Assert.IsNotNull(ConversionUtility.ConvertTo <TargetType2>(new SourceType2()));
 }
Exemple #11
0
 public void ConversionUtility_ConvertTo_5()
 {
     // converterFrom.CanConvertTo(targetType)
     Assert.IsNotNull(ConversionUtility.ConvertTo <TargetType>(new SourceType()));
 }
Exemple #12
0
 public void ConversionUtility_ConvertTo_3()
 {
     // targetType == typeof(string)
     Assert.AreEqual("False", ConversionUtility.ConvertTo <string>(false));
     Assert.AreEqual("0", ConversionUtility.ConvertTo <string>(0));
 }
Exemple #13
0
 public void ConversionUtility_ConvertTo_2()
 {
     // ReferenceEquals(value, null)
     Assert.AreEqual(false, ConversionUtility.ConvertTo <bool>(null));
     Assert.AreEqual(0, ConversionUtility.ConvertTo <int>(null));
 }
Exemple #14
0
 public void ConversionUtility_ConvertTo_1()
 {
     Assert.AreEqual(true, ConversionUtility.ConvertTo <bool>(1));
     Assert.AreEqual(1, ConversionUtility.ConvertTo <int>("1"));
 }