示例#1
0
        /// <summary>
        ///     Patches the configuration elements with type attribute.
        /// </summary>
        /// <param name="root">The assembly binding.</param>
        private static void PatchConfigElementsWithTypeAttribute(XmlNode root)
        {
            if (root == null)
            {
                return;
            }

            foreach (XmlNode node in root.ChildNodes)
            {
                PatchConfigElementsWithTypeAttribute(node);
            }

            if (knowTypes.ContainsKey(root.Name) && !XmlUtil.HasAttribute("type", root))
            {
                var type = knowTypes[root.Name];

                var attributes = XmlUtil.GetAttributes(root);

                var keys = attributes.AllKeys.Where(k => type.GetProperty(k, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase) != null);
                foreach (var name in keys)
                {
                    XmlUtil.AddElement(name, root, attributes[name]);
                }

                XmlUtil.AddAttribute("type", type.AssemblyQualifiedName, root);
            }
        }