コード例 #1
0
        /// <summary>Serializes a TargetProcessGroup to XML. </summary>
        /// <param name="group">The group.</param>
        /// <exception cref="ArgumentNullException"></exception>
        private XElement GroupToXml(TargetProcessGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException(nameof(group));
            }

            return(new XElement(GROUP_TAG,
                                new XElement(NAME_TAG, group.Name),
                                new XElement(ARMED_TAG, group.Armed),
                                new XElement(PROCESSES_TAG,
                                             group.ProcessNames.Select(p => new XElement(PROCESS_TAG, p)))));
        }
コード例 #2
0
        /// <summary>Deserializes a TargetProcessGroup from XML. </summary>
        /// <param name="xml">The XML.</param>
        /// <exception cref="ArgumentNullException"></exception>
        private TargetProcessGroup GroupFromXml(XElement xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            var result = new TargetProcessGroup();

            result.Name  = xml.Element(NAME_TAG).Value;
            result.Armed = bool.Parse(xml.Element(ARMED_TAG).Value);

            var processNames = xml.Element(PROCESSES_TAG)
                               .Elements(PROCESS_TAG)
                               .Select(p => p.Value);

            result.ProcessNames.AddRange(processNames);
            return(result);
        }