Beispiel #1
0
        public T GetAttributeValue <T>(XElement element, string attributeName)
        {
            XAttribute attribute = element.Attribute(attributeName);
            string     value;

            if (attribute == null)
            {
                value = null;
            }
            else
            {
                value = attribute.Value;
            }
            return(TypeConvert.Convert <T>(value));
        }
Beispiel #2
0
        public T GetElementValue <T>(XElement parentElement, string elementName)
        {
            XElement element = parentElement.Element(elementName);
            string   value;

            if (element == null)
            {
                value = null;
            }
            else
            {
                value = element.Value;
            }
            return(TypeConvert.Convert <T>(value));
        }
Beispiel #3
0
        public List <T> ConvertFromElementsToEntities <T>(IEnumerable <XElement> elements) where T : new()
        {
            List <T> result = new List <T>();

            foreach (var element in elements)
            {
                T t = new T();
                foreach (var attribute in element.Attributes())
                {
                    string       propertyName  = attribute.Name.LocalName;
                    string       propertyValue = attribute.Value;
                    PropertyInfo propertyInfo  = typeof(T).GetProperty(propertyName);
                    if (propertyInfo != null)
                    {
                        propertyInfo.SetValue(t, TypeConvert.Convert(propertyValue, propertyInfo.PropertyType), null);
                    }
                }
                result.Add(t);
            }
            return(result);
        }
Beispiel #4
0
 public T GetValue <T>(RegistryKey key, string valueName)
 {
     return(TypeConvert.Convert <T>(key.GetValue(valueName)));
 }