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


C# DomNode.GetChild方法代码示例

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


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

示例1: GetColor

        /// <summary>
        /// Returns DomNode's color components in array</summary>
        /// <param name="domNode">DomNode whose color is obtained</param>
        /// <returns>Array of DomNode's color components</returns>
        public static float[] GetColor(DomNode domNode)
        {
            float[] value = null;
            if (domNode != null)
            {
                DomNode color = domNode.GetChild(Schema.common_color_or_texture_type.colorChild);
                if (color != null)
                    value = DoubleToFloat(color.GetAttribute(Schema.common_color_or_texture_type_color.Attribute) as double[]);
            }

            return value;
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:16,代码来源:Tools.cs

示例2: CreateEffectDictionary

        /// <summary>
        /// Creates effects dictionary</summary>
        /// <param name="bindMtrl">Bind material DomNode</param>
        /// <returns>Effects dictionary of string/Effect pairs</returns>
        public static Dictionary<string, Effect> CreateEffectDictionary(DomNode bindMtrl)
        {
            if (bindMtrl == null)
                return null;

            var result = new Dictionary<string, Effect>();

            DomNode techCommon = bindMtrl.GetChild(Schema.bind_material.technique_commonChild);

            IList<DomNode> instMtrls = techCommon.GetChildList(Schema.bind_material_technique_common.instance_materialChild);
            foreach (DomNode instMtrl in instMtrls)
            {
                DomNode material = instMtrl.GetAttribute(Schema.instance_material.targetAttribute).As<DomNode>();
                DomNode instEffect = material.GetChild(Schema.material.instance_effectChild);
                Effect effect = instEffect.GetAttribute(Schema.instance_effect.urlAttribute).As<Effect>();

                string symbol = instMtrl.GetAttribute(Schema.instance_material.symbolAttribute) as string;
                if (!String.IsNullOrEmpty(symbol))
                    result.Add(symbol, effect);
            }

            return (result.Count > 0) ? result : null;
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:27,代码来源:Tools.cs

示例3: WriteChildElementsRecursive

 /// <summary>
 /// Writes the child elements recursively</summary>
 /// <param name="node">DomNode to write</param>
 /// <param name="writer">The XML writer. See <see cref="T:System.Xml.XmlWriter"/>.</param>
 protected virtual void WriteChildElementsRecursive(DomNode node, XmlWriter writer)
 {
     // write child elements
     foreach (ChildInfo childInfo in node.Type.Children)
     {
         if (childInfo.IsList)
         {
             foreach (DomNode child in node.GetChildList(childInfo))
                 WriteElement(child, writer);
         }
         else
         {
             DomNode child = node.GetChild(childInfo);
             if (child != null)
                 WriteElement(child, writer);
         }
     }
 }
开发者ID:vincenthamm,项目名称:ATF,代码行数:22,代码来源:DomXmlWriter.cs

示例4: Equals

        private bool Equals(DomNode n1, DomNode n2)
        {
            if (n1 == null || n2 == null)
                return n1 == n2;
            if (n1.Type != n2.Type)
                return false;
            if (n1.ChildInfo != n2.ChildInfo)
                return false;

            foreach (AttributeInfo info in n1.Type.Attributes)
            {
                object val1 = n1.GetLocalAttribute(info);
                object val2 = n2.GetLocalAttribute(info);
                if (val1 == null || val2 == null)
                    if (val1 != val2)
                        return false;
            }

            foreach (ChildInfo info in n1.Type.Children)
            {
                if (info.IsList)
                {
                    IList<DomNode> children1 = n1.GetChildList(info);
                    IList<DomNode> children2 = n1.GetChildList(info);
                    if (children1.Count != children2.Count)
                        return false;
                    for (int i = 0; i < children1.Count; i++)
                        if (!Equals(children1[i], children2[i]))
                            return false;
                }
                else
                {
                    DomNode child1 = n1.GetChild(info);
                    DomNode child2 = n2.GetChild(info);
                    if (!Equals(child1, child2))
                        return false;
                }
            }

            return true;
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:41,代码来源:TestDomNode.cs

示例5: TestRemoveFromParent

        public void TestRemoveFromParent()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type);
            type.Define(childInfo);
            DomNode parent = new DomNode(type);
            DomNode child = new DomNode(type);
            parent.SetChild(childInfo, child);
            child.RemoveFromParent();
            Assert.Null(parent.GetChild(childInfo));
            Assert.Null(child.Parent);

            // Make sure the removed child has a null Parent. http://tracker.ship.scea.com/jira/browse/WWSATF-1336
            parent.SetChild(childInfo, child);
            DomNode newChild = new DomNode(type);
            parent.SetChild(childInfo, newChild);
            Assert.Null(child.Parent);
            Assert.True(newChild.Parent == parent);
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:19,代码来源:TestDomNode.cs

示例6: TestGetChildList

        public void TestGetChildList()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type, true);
            type.Define(childInfo);

            DomNode parent = new DomNode(type);
            IList<DomNode> list = parent.GetChildList(childInfo);
            Assert.NotNull(list);
            Assert.Throws<InvalidOperationException>(delegate { parent.GetChild(childInfo); });
            CollectionAssert.IsEmpty(list);
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:12,代码来源:TestDomNode.cs

示例7: TestGetChild

        public void TestGetChild()
        {
            DomNodeType type = new DomNodeType("type");
            ChildInfo childInfo = new ChildInfo("child", type);
            type.Define(childInfo);

            DomNode parent = new DomNode(type);
            DomNode child = new DomNode(type);
            parent.SetChild(childInfo, child);
            Assert.AreSame(parent.GetChild(childInfo), child);
            Assert.Throws<InvalidOperationException>(delegate { parent.GetChildList(childInfo); });
        }
开发者ID:cococo111111,项目名称:ATF,代码行数:12,代码来源:TestDomNode.cs

示例8: Serialize

        private static void Serialize(DomNode node, Dictionary<DomNode, int> nodeIds, BinaryWriter writer)
        {
            writer.Write(node.Type.Name);

            foreach (AttributeInfo info in node.Type.Attributes)
            {
                object value = node.GetLocalAttribute(info);

                // references are serialized as an integer id
                if (info.Type.Type == AttributeTypes.Reference)
                {
                    DomNode reference = value as DomNode;
                    int refId;
                    if (reference == null ||
                        !nodeIds.TryGetValue(reference, out refId))
                    {
                        // null, or reference was external to top level nodes and their subtrees
                        writer.Write(false);
                    }
                    else
                    {
                        writer.Write(true);
                        writer.Write(refId);
                    }
                }
                else
                {
                    if (value == null)
                    {
                        writer.Write(false);
                    }
                    else
                    {
                        writer.Write(true);
                        writer.Write(info.Type.Convert(value));
                    }
                }
            }

            foreach (ChildInfo info in node.Type.Children)
            {
                if (info.IsList)
                {
                    IList<DomNode> children = node.GetChildList(info);
                    writer.Write(children.Count);
                    foreach (DomNode child in children)
                        Serialize(child, nodeIds, writer);
                }
                else
                {
                    DomNode child = node.GetChild(info);
                    if (child == null)
                    {
                        writer.Write(false);
                    }
                    else
                    {
                        writer.Write(true);
                        Serialize(child, nodeIds, writer);
                    }
                }
            }
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:63,代码来源:DomNodeSerializer.cs

示例9: ProcessValueInfo

            private void ProcessValueInfo(DomNode valInfo, string propName,
                List<System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string typeName = (string)valInfo.GetAttribute(SkinSchema.valueInfoType.typeAttribute);
                Type type = SkinUtil.GetType(typeName);


                if (type == typeof(Font))
                {
                    FontDescriptor descr
                        = new FontDescriptor(valInfo, propName, null, null, null, null);
                    descriptors.Add(descr);
                }
                else
                {

                    TypeConverter converter;
                    object editor;
                    GetEditorAndConverter(type, out editor, out converter);
                    if (editor != null)
                    {
                        var descr = new SkinSetterAttributePropertyDescriptor(valInfo
                            , propName, SkinSchema.valueInfoType.valueAttribute, null, null, false, editor, converter);
                        descriptors.Add(descr);
                    }
                    else
                    {
                        DomNode ctorParams = valInfo.GetChild(SkinSchema.valueInfoType.constructorParamsChild);
                        if (ctorParams != null)
                        {
                            var vInfoChildList = ctorParams.GetChildList(SkinSchema.constructorParamsType.valueInfoChild);
                            if (vInfoChildList.Count == 1)
                            {
                                ProcessValueInfo(vInfoChildList[0], propName, descriptors);
                            }
                            else
                            {

                                // special handling for SyntaxEditorControl
                                if (typeName == "Sce.Atf.Controls.SyntaxEditorControl.TextHighlightStyle")
                                {
                                    string argName =
                                    (string)vInfoChildList[0].GetAttribute(SkinSchema.valueInfoType.valueAttribute);

                                    string name = propName + "->" + argName;
                                    ProcessValueInfo(vInfoChildList[1], name, descriptors);
                                }
                                else
                                {
                                    int k = 1;
                                    string paramName = propName + " : Arg_";
                                    foreach (DomNode vInfoChild in vInfoChildList)
                                    {
                                        string name = paramName + k;
                                        ProcessValueInfo(vInfoChild, name, descriptors);
                                        k++;
                                    }
                                }
                            }
                        }

                        foreach (DomNode setterChild in valInfo.GetChildList(SkinSchema.valueInfoType.setterChild))
                        {
                            ProcessSetterType(setterChild, propName, descriptors);
                        }
                    }
                }
            }
开发者ID:Joxx0r,项目名称:ATF,代码行数:68,代码来源:SkinEditor.cs

示例10: ProcessSetterType

            private void ProcessSetterType(DomNode setter, string parentPropName,
                List<System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string curPropName = (string)setter.GetAttribute(SkinSchema.setterType.propertyNameAttribute);
                if (string.IsNullOrWhiteSpace(curPropName)) return;
                string propName = !string.IsNullOrEmpty(parentPropName)
                    ? parentPropName + "->" + curPropName : curPropName;

                DomNode valInfo = setter.GetChild(SkinSchema.setterType.valueInfoChild);
                if (valInfo != null)
                {
                    ProcessValueInfo(valInfo, propName, descriptors);
                }

                DomNode listInfo = setter.GetChild(SkinSchema.setterType.listInfoChild);
                if (listInfo != null)
                {
                    foreach (var vInfo in listInfo.GetChildList(SkinSchema.listInfoType.valueInfoChild))
                        ProcessValueInfo(vInfo, propName, descriptors);
                }
            }
开发者ID:Joxx0r,项目名称:ATF,代码行数:21,代码来源:SkinEditor.cs

示例11: TestAddChildAndModifyInTransaction

        public void TestAddChildAndModifyInTransaction()
        {
            DomNode child = m_root.GetChild(ChildInfo);
            DomNode grandchild = child.GetChild(ChildInfo);
            var greatGrandchild = new DomNode(ChildType, ChildInfo);

            // Add a great-grandchild and then modify it. The attribute changed events should be ignored.
            m_transactionContext.DoTransaction(() =>
            {
                grandchild.SetChild(ChildInfo, greatGrandchild);
                greatGrandchild.SetAttribute(StringAttrInfo, "foo1");
            }, "test transaction 1");

            Assert.IsTrue(m_events.Count == 1);
            CheckChildInsertedEvent(m_events[0], grandchild, greatGrandchild);

            // Make sure the TransactionReporter's state gets cleared for the next transaction.
            m_events.Clear();
            m_transactionContext.DoTransaction(() =>
            {
                grandchild.SetChild(ChildInfo, null);//remove great-grandchild
                greatGrandchild.SetChild(ChildInfo, new DomNode(ChildType));
                grandchild.SetChild(ChildInfo, greatGrandchild);//insert great-grandchild (and its child)
                greatGrandchild.SetAttribute(StringAttrInfo, "foo2");
                greatGrandchild.GetChild(ChildInfo).SetAttribute(StringAttrInfo, "child foo2");
            }, "test transaction 2");
            Assert.IsTrue(m_events.Count == 2);
            CheckChildRemovedEvent(m_events[0], grandchild, greatGrandchild);
            CheckChildInsertedEvent(m_events[1], grandchild, greatGrandchild);

            // This time, make sure that removing the child of a newly inserted tree doesn't generate new events.
            greatGrandchild.RemoveFromParent();
            var great2Grandchild = new DomNode(ChildType);
            greatGrandchild.SetChild(ChildInfo, great2Grandchild);
            m_events.Clear();
            m_transactionContext.DoTransaction(() =>
            {
                grandchild.SetChild(ChildInfo, greatGrandchild);//insert great-grandchild and great2Grandchild
                greatGrandchild.SetAttribute(StringAttrInfo, "foo3");
                great2Grandchild.SetAttribute(StringAttrInfo, "foo3");
                great2Grandchild.RemoveFromParent();
            }, "test transaction 3");
            Assert.IsTrue(m_events.Count == 1);
            CheckChildInsertedEvent(m_events[0], grandchild, greatGrandchild);

            // This time, make sure that removing two children of a newly inserted tree doesn't generate new events.
            grandchild.SetChild(ChildInfo, null);
            greatGrandchild.SetChild(ChildInfo, great2Grandchild);
            var great3Grandchild = new DomNode(ChildType);
            great2Grandchild.SetChild(ChildInfo, great3Grandchild);
            m_events.Clear();
            m_transactionContext.DoTransaction(() =>
            {
                grandchild.SetChild(ChildInfo, greatGrandchild);
                greatGrandchild.SetAttribute(StringAttrInfo, "foo4");
                great2Grandchild.SetAttribute(StringAttrInfo, "foo4");
                great3Grandchild.SetAttribute(StringAttrInfo, "foo4");
                great3Grandchild.RemoveFromParent();
                great2Grandchild.RemoveFromParent();
            }, "test transaction 4");
            Assert.IsTrue(m_events.Count == 1);
            CheckChildInsertedEvent(m_events[0], grandchild, greatGrandchild);

            // Check that removing all the inserted children generates no events.
            grandchild.SetChild(ChildInfo, null);
            greatGrandchild.SetChild(ChildInfo, great2Grandchild);
            great2Grandchild.SetChild(ChildInfo, great3Grandchild);
            m_events.Clear();
            m_transactionContext.DoTransaction(() =>
            {
                grandchild.SetChild(ChildInfo, greatGrandchild);
                greatGrandchild.SetAttribute(StringAttrInfo, "foo5");
                great2Grandchild.SetAttribute(StringAttrInfo, "foo5");
                great3Grandchild.SetAttribute(StringAttrInfo, "foo5");
                great3Grandchild.RemoveFromParent();
                great2Grandchild.RemoveFromParent();
                greatGrandchild.RemoveFromParent();
            }, "test transaction 5");
            Assert.IsTrue(m_events.Count == 0);
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:80,代码来源:TestTransactionReporter.cs

示例12: Prototype

 public Prototype(DomNode node, Uri ur)
 {
     m_node = node;
     m_uri = ur;
     IGameObject gob = m_node.GetChild(Schema.prototypeType.gameObjectChild).As<IGameObject>();
     gob.Name = Type + "_" + Path.GetFileNameWithoutExtension(ur.LocalPath);
 }
开发者ID:ldh9451,项目名称:XLE,代码行数:7,代码来源:PrototypingService.cs

示例13: WriteElement


//.........这里部分代码省略.........
                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNS);

                // define the xsi namespace
                writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);

                // define schema namespaces
                foreach (XmlQualifiedName name in m_typeCollection.Namespaces)
                    if (name.Name != elementPrefix) // don't redefine the element namespace
                        writer.WriteAttributeString("xmlns", name.Name, null, name.Namespace);
            }
            else
            {
                // not the root, so all schema namespaces have been defined
                elementPrefix = writer.LookupPrefix(elementNS);
                if (elementPrefix == null)
                    elementPrefix = GeneratePrefix(elementNS);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNS);
            }

            // write type name if this is a polymorphic type
            DomNodeType type = node.Type;
            if (node.ChildInfo.Type != type)
            {
                string name = type.Name;
                index = name.LastIndexOf(':');
                if (index >= 0)
                {
                    string typeName = name.Substring(index + 1, type.Name.Length - index - 1);
                    string typeNS = name.Substring(0, index);
                    string typePrefix = writer.LookupPrefix(typeNS);
                    if (typePrefix == null)
                    {
                        typePrefix = GeneratePrefix(typeNS);
                        writer.WriteAttributeString("xmlns", typePrefix, null, typeNS);
                    }

                    name = typeName;
                    if (typePrefix != string.Empty)
                        name = typePrefix + ":" + typeName;
                }

                writer.WriteAttributeString("xsi", "type", XmlSchema.InstanceNamespace, name);
            }

            // write attributes
            AttributeInfo valueAttribute = null;
            foreach (AttributeInfo attributeInfo in type.Attributes)
            {
                // if attribute is required, or not the default, write it
                if (/*attributeInfo.Required ||*/ !node.IsAttributeDefault(attributeInfo))
                {
                    if (attributeInfo.Name == string.Empty)
                    {
                        valueAttribute = attributeInfo;
                    }
                    else
                    {
                        object value = node.GetAttribute(attributeInfo);
                        string valueString = null;
                        if (attributeInfo.Type.Type == AttributeTypes.Reference)
                        {
                            // if reference is a valid node, convert to string
                            DomNode refNode = value as DomNode;
                            if (refNode != null)
                                valueString = GetNodeReferenceString(refNode, m_root, m_uri);
                        }
                        if (valueString == null)
                            valueString = attributeInfo.Type.Convert(value);

                        writer.WriteAttributeString(attributeInfo.Name, valueString);
                    }
                }
            }

            // write value if not the default
            if (valueAttribute != null)
            {
                object value = node.GetAttribute(valueAttribute);
                writer.WriteString(valueAttribute.Type.Convert(value));
            }

            // write child elements
            foreach (ChildInfo childInfo in type.Children)
            {
                if (childInfo.IsList)
                {
                    foreach (DomNode child in node.GetChildList(childInfo))
                        WriteElement(child, writer);
                }
                else
                {
                    DomNode child = node.GetChild(childInfo);
                    if (child != null)
                        WriteElement(child, writer);
                }
            }

            writer.WriteEndElement();
        }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:101,代码来源:XmlPersister.cs

示例14: GetFloat

 /// <summary>
 /// Gets float value associated with DomNode</summary>
 /// <param name="domNode">DomNode whose value is obtained</param>
 /// <returns>Float value associated with DomNode</returns>
 public static float GetFloat(DomNode domNode)
 {
     float value = default(float);
     if (domNode != null)
     {
         DomNode floatChild = domNode.GetChild(Schema.common_float_or_param_type.floatChild);
         if (floatChild != null)
         {
             double v = (double)floatChild.GetAttribute(Schema.common_float_or_param_type_float.Attribute);
             value = (float)v;
         }                
     }
     return value;
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:18,代码来源:Tools.cs

示例15: WriteElement


//.........这里部分代码省略.........
                // define schema namespaces
                foreach (var name in m_typeCollection.Namespaces)
                {
                    if (string.Compare(name.Name, elementPrefix) != 0)
                        writer.WriteAttributeString("xmlns", name.Name, null, name.Namespace);
                }
            }
            else
            {
                // not the root, so all schema namespaces have been defined
                elementPrefix = writer.LookupPrefix(elementNs) ?? GeneratePrefix(elementNs);

                writer.WriteStartElement(elementPrefix, node.ChildInfo.Name, elementNs);
            }

            // write type name if this is a polymorphic type
            var type = node.Type;
            if (node.ChildInfo.Type != type)
            {
                var name = type.Name;
                index = name.LastIndexOf(':');
                if (index >= 0)
                {
                    var typeName = name.Substring(index + 1, type.Name.Length - index - 1);
                    var typeNs = name.Substring(0, index);
                    var typePrefix = writer.LookupPrefix(typeNs);
                    if (typePrefix == null)
                    {
                        typePrefix = GeneratePrefix(typeNs);
                        writer.WriteAttributeString("xmlns", typePrefix, null, typeNs);
                    }

                    name = typeName;
                    if (typePrefix != string.Empty)
                        name = typePrefix + ":" + typeName;
                }

                writer.WriteAttributeString("xsi", "type", XmlSchema.InstanceNamespace, name);
            }

            // write attributes
            AttributeInfo valueAttribute = null;
            foreach (var attributeInfo in type.Attributes)
            {
                // if attribute is required, or not the default, write it
                if (/*attributeInfo.Required ||*/ !node.IsAttributeDefault(attributeInfo))
                {
                    if (attributeInfo.Name == string.Empty)
                    {
                        valueAttribute = attributeInfo;
                    }
                    else
                    {
                        var value = node.GetAttribute(attributeInfo);
                        string valueString = null;
                        if (attributeInfo.Type.Type == AttributeTypes.Reference)
                        {
                            // if reference is a valid node, convert to string
                            var refNode = value as DomNode;
                            if (refNode != null)
                                valueString = GetNodeReferenceString(refNode, m_root);
                        }
                        if (valueString == null)
                            valueString = attributeInfo.Type.Convert(value);

                        var bWriteAttribute = true;
                        if (!m_bWritingUserSettings)
                            bWriteAttribute = !s_lstExcludeAttributes.Contains(attributeInfo.Name);

                        if (bWriteAttribute)
                            writer.WriteAttributeString(attributeInfo.Name, valueString);
                    }
                }
            }

            // write value if not the default
            if (valueAttribute != null)
            {
                var value = node.GetAttribute(valueAttribute);
                writer.WriteString(valueAttribute.Type.Convert(value));
            }

            // write child elements
            foreach (var childInfo in type.Children)
            {
                if (childInfo.IsList)
                {
                    foreach (var child in node.GetChildList(childInfo))
                        WriteElement(child, writer);
                }
                else
                {
                    var child = node.GetChild(childInfo);
                    if (child != null)
                        WriteElement(child, writer);
                }
            }

            writer.WriteEndElement();
        }
开发者ID:arsaccol,项目名称:SLED,代码行数:101,代码来源:SledSpfReaderWriter.cs


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