当前位置: 首页>>代码示例>>C#>>正文


C# DomNode.GetId方法代码示例

本文整理汇总了C#中DomNode.GetId方法的典型用法代码示例。如果您正苦于以下问题:C# DomNode.GetId方法的具体用法?C# DomNode.GetId怎么用?C# DomNode.GetId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DomNode的用法示例。


在下文中一共展示了DomNode.GetId方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNodeReferenceString

        /// <summary>
        /// Converts a node to a string reference when writing</summary>
        /// <param name="refNode">Node that is referenced</param>
        /// <param name="root">Root node of data that is being written</param>
        /// <param name="uri">URI of data that is being written</param>
        /// <returns>String encoding the reference to the node</returns>
        protected virtual string GetNodeReferenceString(DomNode refNode, DomNode root, Uri uri)
        {
            string id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            if (!refNode.IsDescendantOf(root))
            {
                DomNode nodeRoot = refNode.GetRoot();
                IResource resource = nodeRoot.As<IResource>();
                if (resource != null)
                {
                    Uri relativeUri = uri.MakeRelativeUri(resource.Uri);
                    id = relativeUri + "#" + id;
                }
            }

            return id;
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:24,代码来源:DomXmlWriter.cs

示例2: TestGetIdDefault

 public void TestGetIdDefault()
 {
     DomNodeType testNoId = new DomNodeType("test");
     DomNode test = new DomNode(testNoId);
     Assert.Null(test.GetId());
 }
开发者ID:cococo111111,项目名称:ATF,代码行数:6,代码来源:TestDomNode.cs

示例3: TestGetId

        public void TestGetId()
        {
            DomNodeType testId = new DomNodeType("test");
            AttributeInfo info = GetStringAttribute("string");
            testId.Define(info);
            testId.SetIdAttribute(info.Name);
            DomNode test = new DomNode(testId);
            Assert.Null(test.GetId());

            test.SetAttribute(info, "foo");
            Assert.AreEqual(test.GetId(), "foo");
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:12,代码来源:TestDomNode.cs

示例4: updateNode

        private void updateNode(DomNode node, ObjectOverride objectOverride)
        {
            if (node == null || objectOverride == null)
                return;
            string nodeId = node.GetId();
            System.Diagnostics.Debug.Assert(nodeId == objectOverride.ObjectName);

            foreach (AttributeOverride attrOverride in objectOverride.AttributeOverrides)
            {
                AttributeInfo attrInfo = node.Type.GetAttributeInfo(attrOverride.Name);
                node.SetAttribute(attrInfo, attrInfo.Type.Convert(attrOverride.AttribValue));
            }
        }
开发者ID:ldh9451,项目名称:XLE,代码行数:13,代码来源:PrefabInstance.cs

示例5: NameNode

 private void NameNode(DomNode node)
 {
     // if the name isn't unique, make it so
     string id = node.GetId();
     
     // DAN: Edit here to allow nodes with no ID attribute to exist!
     if (node.Type.IdAttribute != null)
     {
         string unique = m_uniqueNamer.Name(id);
         if (id != unique)
         {
             node.SetAttribute(node.Type.IdAttribute, unique);
         }
     }
 }
开发者ID:vincenthamm,项目名称:ATF,代码行数:15,代码来源:UniqueIdValidator.cs

示例6: CreateKey

 private string CreateKey(DomNode node, AttributeInfo attrib)
 {
     return string.Format("{0}.{1}", node.GetId(), attrib.Name);
 }
开发者ID:sbambach,项目名称:ATF,代码行数:4,代码来源:ExpressionManager.cs

示例7: NameNode

 private void NameNode(DomNode node)
 {
     // if the name isn't unique, make it so
     string id = node.GetId();
     
     if (node.Type.IdAttribute != null)
     {
         var uniqueNamer = GetUniqueNamer(GetIdCategory(node));
         string unique = uniqueNamer.Name(id);
         if (id != unique)
         {
             node.SetAttribute(node.Type.IdAttribute, unique);
         }
     }
 }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:15,代码来源:CategoryUniqueIdValidator.cs

示例8: ReadElement

        /// <summary>
        /// Reads the node specified by the child metadata</summary>
        /// <param name="nodeInfo">Child metadata for node</param>
        /// <param name="reader">XML reader</param>
        /// <returns>DomNode specified by the child metadata</returns>
        protected virtual DomNode ReadElement(ChildInfo nodeInfo, XmlReader reader)
        {
            // handle polymorphism, if necessary
            DomNodeType type = null;
            var substitutionGroupRule = nodeInfo.Rules.OfType<SubstitutionGroupChildRule>().FirstOrDefault();
            if (substitutionGroupRule != null)
            {
                foreach (var sub in substitutionGroupRule.Substitutions)
                {
                    if (sub.Name == reader.LocalName)
                    {
                        type = sub.Type;
                        break;
                    }
                }

                // Fallback to non-substituted version (for example loading an old schema).
                if (type == null)
                    type = GetChildType(nodeInfo.Type, reader);

                if (type == null)
                    throw new InvalidOperationException("Could not match substitution group for child " + nodeInfo.Name);
            }
            else
            {
                type = GetChildType(nodeInfo.Type, reader);
            }

            int index = type.Name.LastIndexOf(':');
            string typeNS = type.Name.Substring(0, index);

            DomNode node = new DomNode(type, nodeInfo);

            // read attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Prefix == string.Empty ||
                    reader.LookupNamespace(reader.Prefix) == typeNS)
                {
                    AttributeInfo attributeInfo = type.GetAttributeInfo(reader.LocalName);
                    if (attributeInfo != null)
                    {
                        ReadAttribute(node, attributeInfo, reader.Value);
                    }
                }
            }

            // add node to map if it has an id
            if (node.Type.IdAttribute != null)
            {
                string id = node.GetId();
                if (!string.IsNullOrEmpty(id))
                    m_nodeDictionary[id] = node; // don't Add, in case there are multiple DomNodes with the same id
            }

            reader.MoveToElement();

            if (!reader.IsEmptyElement)
            {
                // read child elements
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        // look up metadata for this element
                        ChildInfo childInfo = type.GetChildInfo(reader.LocalName);
                        if (childInfo == null)
                        {
                            // Try and get substitution group
                            childInfo = GetSubsitutionGroup(type, reader.LocalName);
                        }

                        if (childInfo != null)
                        {
                            DomNode childNode = ReadElement(childInfo, reader);
                            if (childNode != null)
                            {
                                // childNode is fully populated sub-tree
                                if (childInfo.IsList)
                                {
                                    node.GetChildList(childInfo).Add(childNode);
                                }
                                else
                                {
                                    node.SetChild(childInfo, childNode);
                                }
                            }
                        }
                        else
                        {
                            // try reading as an attribute
                            AttributeInfo attributeInfo = type.GetAttributeInfo(reader.LocalName);
                            if (attributeInfo != null)
                            {
                                reader.MoveToElement();
//.........这里部分代码省略.........
开发者ID:sbambach,项目名称:ATF,代码行数:101,代码来源:DomXmlReader.cs

示例9: NameNode

 private void NameNode(DomNode node, UniqueNamer namer)
 {
     // if the name isn't unique, make it so
     string id = node.GetId();
     string unique = namer.Name(id);
     if (id != unique)
     {
         node.SetAttribute(node.Type.IdAttribute, unique);
     }
 }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:10,代码来源:UniquePathIdValidator.cs

示例10: GetNodeReferenceString

        /// <summary>
        /// Converts a node to a string reference when writing DomNode</summary>
        /// <param name="refNode">Node that is referenced</param>
        /// <param name="root">Root node of data that is being written</param>
        /// <param name="uri">URI of data that is being written</param>
        /// <returns>String encoding the reference to the node</returns>
        protected virtual string GetNodeReferenceString(DomNode refNode, DomNode root, Uri uri)
        {
            string id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            DomNode nodeRoot = refNode.GetRoot();
            if (nodeRoot != root)
            {
                IResource resource = nodeRoot.As<IResource>();
                if (resource != null)
                    id = resource.Uri.LocalPath + "#" + id;
            }

            return id;
        }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:21,代码来源:XmlPersister.cs

示例11: ReadElement

        /// <summary>
        /// Reads the node specified by the child metadata</summary>
        /// <param name="nodeInfo">Child metadata for node</param>
        /// <param name="reader">XML reader</param>
        /// <returns>DomNode specified by the child metadata</returns>
        protected virtual DomNode ReadElement(ChildInfo nodeInfo, XmlReader reader)
        {
            // handle polymorphism, if necessary
            DomNodeType type = GetChildType(nodeInfo.Type, reader);
            int index = type.Name.LastIndexOf(':');
            string typeNS = type.Name.Substring(0, index);

            DomNode node = new DomNode(type, nodeInfo);

            // read attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Prefix == string.Empty ||
                    reader.LookupNamespace(reader.Prefix) == typeNS)
                {
                    AttributeInfo attributeInfo = type.GetAttributeInfo(reader.LocalName);
                    if (attributeInfo != null)
                    {
                        string valueString = reader.Value;
                        if (attributeInfo.Type.Type == AttributeTypes.Reference)
                        {
                            // save reference so it can be resolved after all nodes have been read
                            m_nodeReferences.Add(new XmlNodeReference(node, attributeInfo, valueString));
                        }
                        else
                        {
                            object value = attributeInfo.Type.Convert(valueString);
                            node.SetAttribute(attributeInfo, value);
                        }
                    }
                }
            }

            // add node to map if it has an id
            if (node.Type.IdAttribute != null)
            {
                string id = node.GetId();
                if (!string.IsNullOrEmpty(id))
                    m_nodeDictionary[id] = node; // don't Add, in case there are multiple DomNodes with the same id
            }

            reader.MoveToElement();

            if (!reader.IsEmptyElement)
            {
                // read child elements
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        // look up metadata for this element
                        ChildInfo childInfo = type.GetChildInfo(reader.LocalName);
                        if (childInfo != null)
                        {
                            DomNode childObject = ReadElement(childInfo, reader);
                            // at this point, child is a fully populated sub-tree

                            if (childInfo.IsList)
                            {
                                node.GetChildList(childInfo).Add(childObject);
                            }
                            else
                            {
                                node.SetChild(childInfo, childObject);
                            }
                        }
                        else
                        {
                            // try reading as an attribute
                            AttributeInfo attributeInfo = type.GetAttributeInfo(reader.LocalName);
                            if (attributeInfo != null)
                            {
                                reader.MoveToElement();

                                if (!reader.IsEmptyElement)
                                {
                                    // read element text
                                    while (reader.Read())
                                    {
                                        if (reader.NodeType == XmlNodeType.Text)
                                        {
                                            object value = attributeInfo.Type.Convert(reader.Value);
                                            node.SetAttribute(attributeInfo, value);
                                            // skip child elements, as this is an attribute value
                                            reader.Skip();
                                            break;
                                        }
                                        if (reader.NodeType == XmlNodeType.EndElement)
                                        {
                                            break;
                                        }
                                    }

                                    reader.MoveToContent();
                                }
//.........这里部分代码省略.........
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:101,代码来源:XmlPersister.cs

示例12: GetNodeReferenceString

        private static string GetNodeReferenceString(DomNode refNode, DomNode root)
        {
            var id = refNode.GetId();

            // if referenced node is in another resource, prepend URI
            if (!refNode.IsDescendantOf(root))
            {
                var nodeRoot = refNode.GetRoot();
                var resource = nodeRoot.As<IResource>();
                if (resource != null)
                    id = resource.Uri.LocalPath + "#" + id;
            }

            return id;
        }
开发者ID:arsaccol,项目名称:SLED,代码行数:15,代码来源:SledSpfReaderWriter.cs


注:本文中的DomNode.GetId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。