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


C# XAttribute.SetValue方法代码示例

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


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

示例1: ExecuteXAttributeVariation

 public void ExecuteXAttributeVariation(XAttribute toChange, object newValue)
 {
     XElement xElem = new XElement("root", toChange);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.SetValue(newValue);
             Assert.True(newValue.Equals(toChange.Value), "Value did not change");
             xElem.Verify();
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:19,代码来源:EventsValue.cs

示例2: CopyData

        private static void CopyData(string providerName, DataTypeChangeDescriptor dataTypeChangeDescriptor, DataScopeConfigurationElement oldDataScopeConfigurationElement, DataScopeConfigurationElement newDataScopeConfigurationElement, Dictionary<string, object> newFieldValues, bool deleteOldFile = true)
        {
            string oldFilename = ResolvePath(oldDataScopeConfigurationElement.Filename, providerName);
            string newFilename = ResolvePath(newDataScopeConfigurationElement.Filename, providerName);

            XDocument oldDocument = XDocumentUtils.Load(PathUtil.Resolve(oldFilename));

            List<XElement> newElements = new List<XElement>();

            foreach (XElement oldElement in oldDocument.Root.Elements())
            {
                List<XAttribute> newChildAttributes = new List<XAttribute>();

                foreach (XAttribute oldChildAttribute in oldElement.Attributes())
                {
                    var existingFieldInfo = GetExistingFieldInfo(dataTypeChangeDescriptor, oldChildAttribute.Name.LocalName);

                    if (existingFieldInfo != null)
                    {
                        if (existingFieldInfo.OriginalField.Name != existingFieldInfo.AlteredField.Name)
                        {
                            XAttribute newChildAttribute = new XAttribute(existingFieldInfo.AlteredField.Name, oldChildAttribute.Value);

                            newChildAttributes.Add(newChildAttribute);
                        }
                        else
                        {
                            newChildAttributes.Add(oldChildAttribute);
                        }
                    }
                    // It may happen that some data were added before data descriptors are updated, in the case of using 
                    // [AutoUpdateable] attribute. 
                    else if (dataTypeChangeDescriptor.AddedFields.Any(addedField => addedField.Name == oldChildAttribute.Name))
                    {
                        newChildAttributes.Add(oldChildAttribute);
                    }
                }

                // Adding default value for fields that are NULL and become required
                foreach (var existingFieldInfo in dataTypeChangeDescriptor.ExistingFields)
                {
                    bool fieldBecomeRequired = existingFieldInfo.OriginalField.IsNullable && !existingFieldInfo.AlteredField.IsNullable;

                    string fieldName = existingFieldInfo.AlteredField.Name;

                    if (fieldBecomeRequired && !newChildAttributes.Any(attr => attr.Name.LocalName == fieldName))
                    {
                        newChildAttributes.Add(new XAttribute(fieldName, GetDefaultValue(existingFieldInfo.AlteredField)));
                    }
                }

                foreach (DataFieldDescriptor fieldDescriptor in dataTypeChangeDescriptor.AddedFields)
                {
                    if (fieldDescriptor.IsNullable == false
                        && !newChildAttributes.Any(attr => attr.Name == fieldDescriptor.Name))
                    {
                        XAttribute newChildAttribute = new XAttribute(fieldDescriptor.Name, GetDefaultValue(fieldDescriptor));

                        if (newFieldValues.ContainsKey(fieldDescriptor.Name))
                        {
                            newChildAttribute.SetValue(newFieldValues[fieldDescriptor.Name]);
                        }

                        newChildAttributes.Add(newChildAttribute);
                    }
                    else if (newFieldValues.ContainsKey(fieldDescriptor.Name))
                    {
                        XAttribute attribute = newChildAttributes.SingleOrDefault(attr => attr.Name == fieldDescriptor.Name);
                        if (attribute != null)
                        {
                            attribute.SetValue(newFieldValues[fieldDescriptor.Name]);
                        }
                    }
                }

                XElement newElement = new XElement(newDataScopeConfigurationElement.ElementName, newChildAttributes);

                newElements.Add(newElement);
            }

            if (deleteOldFile)
            {
                C1File.Delete(oldFilename);
            }

            XElement newRoot = new XElement(XmlDataProviderDocumentWriter.GetRootElementName(newDataScopeConfigurationElement.ElementName));
            newRoot.Add(newElements);

            XDocument newDocument = new XDocument();
            newDocument.Add(newRoot);

            XDocumentUtils.Save(newDocument, newFilename);
        }
开发者ID:hitesh97,项目名称:C1-CMS,代码行数:93,代码来源:XmlDataProviderStoreManipulator.cs

示例3: SetValueNullAttr

 //[Variation(Desc = "XAttribute.SetValue(null)")]
 public void SetValueNullAttr()
 {
     XAttribute a = new XAttribute("a", "A");
     try
     {
         a.SetValue(null);
         throw new TestException(TestResult.Failed, "");
     }
     catch (ArgumentNullException) { }
 }
开发者ID:gitter-badger,项目名称:corefx,代码行数:11,代码来源:ImplicitConversionsRoundTrip.cs

示例4: CreateContainer

                private XObject CreateContainer()
                {
                    if (_nodeCreateType == NodeCreateType.Constructor)
                    {
                        if (_nodeType.Name.Equals("XElement"))
                        {
                            return new XElement(XName.Get("name"), _data);
                        }

                        if (_nodeType.Name.Equals("XAttribute"))
                        {
                            return new XAttribute(XName.Get("name"), _data);
                        }
                    }
                    else if (_nodeCreateType == NodeCreateType.SetValue)
                    {
                        if (_nodeType.Name.Equals("XElement"))
                        {
                            var node = new XElement(XName.Get("name"), "");
                            node.SetValue(_data);
                            return node;
                        }

                        if (_nodeType.Name.Equals("XAttribute"))
                        {
                            var node = new XAttribute(XName.Get("name"), "");
                            node.SetValue(_data);
                            return node;
                        }
                    }

                    throw new ArgumentOutOfRangeException("Unknown NodeCreateType: " + _nodeCreateType);
                }
开发者ID:gitter-badger,项目名称:corefx,代码行数:33,代码来源:ImplicitConversionsRoundTrip.cs

示例5: ChangeVersionInfo

 private static void ChangeVersionInfo( XAttribute t )
 {
     Group version = Regex.Match( t.Value, "Version=(?<1>[\\d\\.]+)" ).Groups[1];
     var current = new Version( version.Value );
     var next = new Version( current.Major + 1, current.Minor + 1, current.Build, current.Revision );
     string newTypeName = t.Value.Remove( version.Index, version.Length ).Insert( version.Index, next.ToString() );
     t.SetValue( newTypeName );
 }
开发者ID:Nementon,项目名称:ck-desktop,代码行数:8,代码来源:StructuredReadWrites.cs


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