Esempio n. 1
0
        internal T GetValue <T>(XmlAttribute attribute)
        {
            if (attribute == null)
            {
                return(default(T));
            }

            string[] names = GetNames(attribute.Value);
            if (names == null)
            {
                return(XmlHelper.GetValue <T>(attribute));
            }

            if (typeof(T) == typeof(string))
            {
                string newValue = attribute.Value;
                foreach (string name in names)
                {
                    newValue = newValue.Replace(newValue, MagickConverter.Convert <string>(_Variables[name]));
                }

                return((T)(object)newValue);
            }
            else
            {
                string name = names[0];

                if (TypeHelper.IsValueType(typeof(T)))
                {
                    Throw.IfNull(nameof(attribute), _Variables[name], "The variable {0} should be set.", name);
                }

                return(MagickConverter.Convert <T>(_Variables[name]));
            }
        }
Esempio n. 2
0
        internal bool TryGetValue <T>(XmlAttribute attribute, out T value)
        {
            string[] names = GetNames(attribute.Value);
            if (names == null)
            {
                value = default(T);
                return(false);
            }

            if (typeof(T) == typeof(string))
            {
                string newValue = attribute.Value;
                foreach (string name in names)
                {
                    newValue = newValue.Replace(newValue, MagickConverter.Convert <string>(_variables[name]));
                }

                value = (T)(object)newValue;
                return(true);
            }
            else
            {
                string name = names[0];

                if (TypeHelper.IsValueType(typeof(T)))
                {
                    Throw.IfNull(nameof(attribute), _variables[name], $"The variable '{name}' should be set.");
                }

                value = MagickConverter.Convert <T>(_variables[name]);
                return(true);
            }
        }
Esempio n. 3
0
        public static T GetValue <T>(XmlAttribute attribute)
        {
            if (attribute == null)
            {
                return(default(T));
            }

            return(MagickConverter.Convert <T>(attribute.Value));
        }
Esempio n. 4
0
        public static T GetAttribute <T>(XmlElement element, string name)
        {
            if (element == null || !element.HasAttribute(name))
            {
                return(default(T));
            }

            return(MagickConverter.Convert <T>(element.GetAttribute(name)));
        }