Beispiel #1
0
 private static void SetString(this XDocument document, string value, string propertyName)
 {
     if (string.IsNullOrWhiteSpace(value))
     {
         document.RemoveElement(propertyName);
     }
     else
     {
         var propertyElement = document.AddOrGetPropertyElement(propertyName);
         propertyElement.SetValue(value);
     }
 }
Beispiel #2
0
        private static void SetDictionaryStringString(this XDocument document, IDictionary <string, string> values, string propertyName)
        {
            document.RemoveElement(propertyName);
            if (values == null || !values.Any())
            {
                return;
            }

            var element = document.AddOrGetPropertyElement(propertyName);

            foreach (var value in values)
            {
                var e = new XElement(ValueNodename, value.Value);
                e.SetAttributeValue(KeyAttributename, value.Key);
                element.Add(e);
            }
        }
Beispiel #3
0
        private static void SetStrings(this XDocument document, IEnumerable <string> values, string propertyName)
        {
            document.RemoveElement(propertyName);
            if (values == null)
            {
                return;
            }

            XElement element = null;

            foreach (var value in values)
            {
                if (element == null)
                {
                    element = document.AddOrGetPropertyElement(propertyName);
                }
                element.Add(new XElement(ValueNodename, value));
            }
        }