コード例 #1
0
 public XmlConfigNode(XmlNode node)
 {
     this.Node          = node;
     this.Name          = ((node.Attributes["name"] != null) ? node.Attributes["name"].Value : "");
     this.Serialized    = (node.Attributes["serialized"] != null && node.Attributes["serialized"].Value == "true");
     this.ClassName     = XmlConfigNode.GetClassNameFromNode(node);
     this.Namespace     = XmlConfigNode.GetNamespaceFromNode(node);
     this.Documentation = XmlConfigNode.FindDescription(node);
     this.Instance      = null;
 }
コード例 #2
0
        private void LoadNodesFromConfig()
        {
            m_nodes.Clear();

            foreach (XPathNavigator navigator in m_document.CreateNavigator().Select("//Variable[@name]"))
            {
                if (!navigator.IsNode)
                {
                    continue;
                }

                var variableNode = new XmlConfigNode(((IHasXmlNode)navigator).GetNode());

                if (string.IsNullOrEmpty(variableNode.Name))
                {
                    logger.Error(string.Format("Variable in {0} has not attribute 'name'", variableNode.Path));
                    continue;
                }

                m_nodes.Add(variableNode.Path, variableNode);
            }
        }
コード例 #3
0
        private void LoadNodesFromAssemblies()
        {
            foreach (var assembly in m_assemblies.Values)
            {
                DotNetDocumentation documentation = null;
                if (m_assembliesDocFile.ContainsKey(assembly))
                {
                    if (File.Exists(m_assembliesDocFile[assembly]))
                    {
                        documentation = DotNetDocumentation.Load(m_assembliesDocFile[assembly]);
                    }
                }

                foreach (var type in assembly.GetTypes())
                {
                    var fields = from field in type.GetFields(BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
                                 where field.GetCustomAttribute <VariableAttribute>() != null
                                 select field;

                    object instance = null;
                    if (m_instances.ContainsKey(type))
                    {
                        instance = m_instances[type];
                    }

                    foreach (var field in fields)
                    {
                        var node     = new XmlConfigNode(field);
                        var isStatic = field.IsStatic;

                        if (!isStatic)
                        {
                            if (instance != null)
                            {
                                node.Instance = instance;
                            }
                            else
                            {
                                throw new Exception(
                                          string.Format(
                                              "{0} is not static. Declare it static or bind an instance to the type {1}",
                                              field.Name, type.Name));
                            }
                        }
                        DocEntry member = null;
                        if (documentation != null)
                        {
                            member = documentation.Members.FirstOrDefault(entry => entry.Name == type.FullName + "." + field.Name);
                        }

                        if (member != null)
                        {
                            node.Documentation = member.Summary;
                        }

                        m_nodes.Add(node.Path, node);
                    }

                    var properties = from property in type.GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
                                     where property.GetCustomAttribute <VariableAttribute>() != null
                                     select property;

                    foreach (var property in properties)
                    {
                        var node     = new XmlConfigNode(property);
                        var isStatic = property.GetGetMethod().IsStatic;

                        if (!isStatic)
                        {
                            if (instance != null)
                            {
                                node.Instance = instance;
                            }
                            else
                            {
                                throw new Exception(
                                          string.Format(
                                              "{0} is not static. Declare it static or bind an instance to the type {1}",
                                              property.Name, type.Name));
                            }
                        }

                        DocEntry member = null;
                        if (documentation != null)
                        {
                            member = documentation.Members.FirstOrDefault(entry => entry.Name == type.FullName + "." + property.Name);
                        }

                        if (member != null)
                        {
                            node.Documentation = member.Summary;
                        }

                        m_nodes.Add(node.Path, node);
                    }
                }
            }
        }