當前位置: 首頁>>代碼示例>>C#>>正文


C# XElement.ReplaceWith方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XElement.ReplaceWith方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.ReplaceWith方法的具體用法?C# XElement.ReplaceWith怎麽用?C# XElement.ReplaceWith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.ReplaceWith方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Execute

		public override void Execute(XElement el){
			string code = el.Attr("code");
			Type type = Type.GetType(code, false);
			if (null == type){
				_project.Log.Error("Не могу найти расширение - генератор с именем " + code);
				return;
			}
			var gen = Activator.CreateInstance(type) as ISourceCodeGenerator;
			if (null == gen){
				_project.Log.Error("Указанный класс " + code + " не соответствует интерфейсу ISourceCodeGenerator");
				return;
			}
			IEnumerable<XNode> replaces = null;
			try{
				replaces = gen.Execute(_project, el, null).ToArray();
			}
			catch (Exception ex){
				_project.Log.Error("Ошибка при вызове " + gen.GetType().Name + " на " + el, ex);
				return;
			}
			if (!replaces.Any()){
				el.Remove();
			}
			else{
				el.ReplaceWith(replaces.OfType<object>().ToArray());
			}
		}
開發者ID:Qorpent,項目名稱:qorpent.sys,代碼行數:27,代碼來源:ExecuteCodeGenerator.cs

示例2: HandleStringElement

        private static void HandleStringElement(XElement element)
        {
            XAttribute attribute = element.Attribute("key");
            if (attribute == null) throw new InvalidOperationException(string.Format("Missing attibute named 'key' at {0}", element));

            string newValue = StringResourceSystemFacade.ParseString(string.Format("${{{0}}}", attribute.Value));

            element.ReplaceWith(newValue);
        }
開發者ID:DBailey635,項目名稱:C1-CMS,代碼行數:9,代碼來源:LocalizationParser.cs

示例3: ResolveCondition

		/// <summary>
		/// 	Resolves the condition.
		/// </summary>
		/// <param name="e"> The e. </param>
		/// <param name="id"> The id. </param>
		/// <remarks>
		/// </remarks>
		private void ResolveCondition(XElement e, string id) {
			if (!Match(id)) {
				e.Remove();
				return;
			}
			foreach (var a in e.Attributes()) {
				SetParentAttribute(e, a);
			}
			e.ReplaceWith(e.Elements());
		}
開發者ID:comdiv,項目名稱:qorpent.themas,代碼行數:17,代碼來源:ResolveConditionalCompilationStep.cs

示例4: MergeIncludeFile

 private static void MergeIncludeFile(XElement inc)
 {
     var xdoc = LoadIncludeFile(inc);
     if (xdoc != null)
     {
         inc.ReplaceWith(xdoc.Root);
     }
 }
開發者ID:rolandzwaga,項目名稱:randori-tools,代碼行數:8,代碼來源:Program.cs

示例5: Execute

		/// <summary>
		/// 	executes generator
		/// </summary>
		/// <param name="context"> </param>
		/// <param name="callelement"> </param>
		public void Execute(ThemaCompilerContext context, XElement callelement) {
			var generator = Activator.CreateInstance(Type) as IThemaXmlGenerator;
			if (generator is IThemaCompileTimeGenerator) {
				callelement.ReplaceWith(((IThemaCompileTimeGenerator) generator).Generate(callelement, context).ToArray());
			}
			else {
				if (generator != null) {
					callelement.ReplaceWith(generator.Generate(callelement).ToArray());
				}
			}
		}
開發者ID:comdiv,項目名稱:qorpent.themas,代碼行數:16,代碼來源:GeneratorDescriptor.cs

示例6: ApplySpanFormatting

        /// <summary>
        /// Apply the formatting from a span including all nested spans to each run contained within it
        /// </summary>
        /// <param name="span">The root span from which to start applying formatting</param>
        /// <param name="runProps">The run properties in which to accumulate formatting</param>
        private static void ApplySpanFormatting(XElement span, XElement runProps)
        {
            string spanClass = (string)span.Attribute("class");

            switch(spanClass)
            {
                case null:
                    // Missing class name, ignore it.  Shouldn't see any at this point, but just in case.
                    break;

                case "languageSpecificText":
                    // Replace language-specific text with the neutral text sub-entry.  If not found, remove it.
                    var genericText = span.Elements("span").FirstOrDefault(s => (string)s.Attribute("class") == "nu");

                    if(genericText != null)
                        span.ReplaceWith(new XElement(w + "r", new XElement(w + "t", genericText.Value)));
                    else
                        span.Remove();
                    return;

                case "Bold":
                case "nolink":
                case "NoLink":
                case "selflink":
                case "SelfLink":
                    if(!runProps.Elements(w + "b").Any())
                        runProps.Add(new XElement(w + "b"));
                    break;

                case "Emphasis":
                    if(!runProps.Elements(w + "i").Any())
                        runProps.Add(new XElement(w + "i"));
                    break;

                case "Underline":
                    if(!runProps.Elements(w + "u").Any())
                        runProps.Add(new XElement(w + "u", new XAttribute(w + "val", "single")));
                    break;

                case "Subscript":       // If vertAlign exists, replace it as we can't merge it
                    var subscript = runProps.Elements(w + "vertAlign").FirstOrDefault();

                    if(subscript != null)
                        subscript.Attribute(w + "val").Value = "subscript";
                    else
                        runProps.Add(new XElement(w + "vertAlign", new XAttribute(w + "val", "subscript")));
                    break;

                case "Superscript":     // If vertAlign exists, replace it as we can't merge it
                    var superscript = runProps.Elements(w + "vertAlign").FirstOrDefault();

                    if(superscript != null)
                        superscript.Attribute(w + "val").Value = "superscript";
                    else
                        runProps.Add(new XElement(w + "vertAlign", new XAttribute(w + "val", "superscript")));
                    break;

                default:                // Named style
                    // Correct the casing on code and syntax section style names
                    switch(spanClass)
                    {
                        case "comment":
                        case "identifier":
                        case "keyword":
                        case "literal":
                        case "parameter":
                        case "typeparameter":
                            spanClass = spanClass[0].ToString().ToUpperInvariant() + spanClass.Substring(1);
                            break;

                        default:
                            break;
                    }

                    // If one exists, replace it since we can't merge them
                    var namedStyle = runProps.Elements(w + "rStyle").FirstOrDefault();

                    if(namedStyle != null)
                        namedStyle.Attribute(w + "val").Value = spanClass;
                    else
                        runProps.Add(new XElement(w + "rStyle", new XAttribute(w + "val", spanClass)));
                    break;
            }

            // If the span does not have children but is not empty, it has inner text that needs to be wrapped
            // in a run.
            if(!span.HasElements && !span.IsEmpty)
            {
                var content = new XElement(w + "r", new XElement(w + "t",
                    new XAttribute(XNamespace.Xml + "space", "preserve"), span.Value));
                span.Value = String.Empty;
                span.Add(content);
            }

            // Add the run properties to each child run
//.........這裏部分代碼省略.........
開發者ID:modulexcite,項目名稱:SHFB-1,代碼行數:101,代碼來源:BuildOpenXmlFile.cs

示例7: DeQueueMerges

        private void DeQueueMerges(XDocument main, Dictionary<string, XElement> idDictionary)
        {
            if (idDictionary.Keys.FirstOrDefault() == null)
                return; // We're not needed here.
            Log.Info("Applying base elements.");
            XElement mainElement = main.Root.Elements("RulesElement").First();
            XNode NextElement;
            do
            {
                XNode prev = mainElement.PreviousNode;
                NextElement = mainElement.NextNode;
                while (NextElement != null && !(NextElement is XElement))
                    NextElement = NextElement.NextNode;
                string id = getID(mainElement);
                if (idDictionary.ContainsKey(id))
                {
                    foreach (XElement partElement in idDictionary[id].Elements())
                    {
                        switch (partElement.Name.LocalName)
                        {
                            case "RulesElement": mainElement.ReplaceWith(partElement); break;
                            case "RemoveNodes": removeElement(partElement, mainElement); break;
                            case "AppendNodes": appendToElement(partElement, mainElement); break;
                            case "DeleteElement": deleteElement(partElement, mainElement); break;
                        }
                        mainElement = prev.NextNode as XElement; // Lost Parent
                    }
                    idDictionary.Remove(id);
                }
                if (idDictionary.ContainsKey("nullID"))
                {
                    XElement[] MassAppends = idDictionary["nullID"].Elements().ToArray();
                    for (int i = 0; i < MassAppends.Length; i++)
                    {
                        XElement partElement = MassAppends[i];
                        string[] ids = partElement.Attribute("ids").Value.Trim().Split(',');
                        if (ids.Contains(id))
                            appendToElement(partElement, mainElement);
                    }
                }
                if (idDictionary.Keys.FirstOrDefault() == null)
                    return; // Quick way of aborting if we're done.  Anything more complex isn't really worth it.
            } while ((mainElement = NextElement as XElement) != null);
            Log.Info("Applying new elements");
            foreach (String id in idDictionary.Keys.ToArray())
            {
                XElement RulesCollection = idDictionary[id];
                mainElement = new XElement("RulesElement", new XAttribute("internal-id","deleteme"));
                main.Root.Add(mainElement);

                XNode prev = mainElement.PreviousNode;
                foreach (XElement partElement in RulesCollection.Elements())
                {
                    switch (partElement.Name.LocalName)
                    {
                        case "RulesElement": mainElement.ReplaceWith(partElement); break;
                        case "RemoveNodes": removeElement(partElement, mainElement); break;
                        case "AppendNodes": appendToElement(partElement, mainElement); break;
                        case "DeleteElement": deleteElement(partElement, mainElement); break;
                    }
                    mainElement = prev.NextNode as XElement; // Lost Parent
                }
                if (getID(mainElement) == "deleteme")
                    mainElement.Remove(); // It was only an append.
                idDictionary.Remove(id);
            }
        }
開發者ID:Vhex,項目名稱:CBLoader,代碼行數:67,代碼來源:FileManager.cs

示例8: ControlElement

 private void ControlElement(XElement root, XElement currentElement)
 {
     if (GetLineLength(root) > LengthLimit)
     {
         if (!HasGrandChildren(currentElement))
         {
             currentElement.ReplaceWith(CreateEntirelyFoldedElement(currentElement));
             return;
         }
         var children = currentElement.Elements().ToArray();
         for (int i = children.Count() - 1; i >= 0; i--)
         {
             var child = children.ElementAt(i);
             ControlElement(root, child);
             if (GetLineLength(root) <= LengthLimit) return;
         }
         currentElement.ReplaceWith(CreateEntirelyFoldedElement(currentElement));
     }
 }
開發者ID:spati2,項目名稱:FSE-2012-SANDO,代碼行數:19,代碼來源:XAMLFileParser.cs

示例9: ReplaceColorProfile

		//===========================================================================================
		private void ReplaceColorProfile(XElement annotation)
		{
			XElement restriction = new XElement(_Namespace + "restriction",
											new XAttribute("base", "xs:NMTOKEN"));
			foreach (string name in _GraphicsMagickNET.GetColorProfileNames())
			{
				restriction.Add(new XElement(_Namespace + "enumeration",
										new XAttribute("value", name)));
			}

			annotation.ReplaceWith(CreateVarElement("ColorProfile", restriction));
		}
開發者ID:dlemstra,項目名稱:GraphicsMagick.NET,代碼行數:13,代碼來源:XsdGenerator.cs

示例10: ReplaceIReadDefines

 private void ReplaceIReadDefines(XElement annotation)
 {
   annotation.ReplaceWith(
     from type in _Types.GetInterfaceTypes("IReadDefines")
     let name = MagickTypes.GetXsdName(type)
     select new XElement(_Namespace + "element",
       new XAttribute("name", name),
       new XAttribute("type", name)));
 }
開發者ID:levesque,項目名稱:Magick.NET,代碼行數:9,代碼來源:XsdGenerator.cs

示例11: ReplaceDefines

    private void ReplaceDefines(XElement annotation)
    {
      List<XElement> types = new List<XElement>();

      foreach (Type interfaceType in _Types.GetInterfaceTypes("IDefines"))
      {
        XElement complexType = new XElement(_Namespace + "complexType",
                          new XAttribute("name", MagickTypes.GetXsdName(interfaceType)));
        AddClass(complexType, interfaceType);
        types.Add(complexType);
      }

      annotation.ReplaceWith(types.ToArray());
    }
開發者ID:levesque,項目名稱:Magick.NET,代碼行數:14,代碼來源:XsdGenerator.cs

示例12: ReplaceParameter

		/// <summary>
		/// 	Replaces the parameter.
		/// </summary>
		/// <param name="pr"> The pr. </param>
		/// <param name="code"> The code. </param>
		/// <remarks>
		/// </remarks>
		private void ReplaceParameter(XElement pr, string code) {
			var p = Context.ParameterIndex[code];
			if (null == p.Annotation<UsedInWorkingThemaAnnotation>()) {
				p.AddAnnotation(UsedInWorkingThemaAnnotation.Default);
			}
			p = new XElement(p);
			if (pr.Name.LocalName == "use") {
				var list = p.Attribute("list");
				if (null != list) {
					list.Remove();
				}
			}
			foreach (var a in pr.Attributes()
				.Where(a =>
				       !a.Name.LocalName.EndsWith("list")
				       || pr.Name.LocalName != "use")) {
				p.SetAttributeValue(a.Name, a.Value);
			}
			if (!string.IsNullOrEmpty(pr.Value)) {
				p.Value = pr.Value;
			}
			if (null != p.Attribute("clear")) {
				p.Value = "";
			}
			switch (pr.Name.LocalName) {
				case "ask":
					p.Name = "var";
					break;
				case "use":
					p.Name = "param";
					break;
			}
			pr.ReplaceWith(p);
		}
開發者ID:comdiv,項目名稱:qorpent.themas,代碼行數:41,代碼來源:EmbedItemParametersStep.cs

示例13: ReplaceAbstractPatternInstance

        private static void ReplaceAbstractPatternInstance(Dictionary<string, XElement> dicAPs, XElement xInstance, XmlNamespaceManager nsManager)
        {
            // select is-a
            string isa = xInstance.Attribute(XName.Get("is-a")).Value;

            // select id
            string id = null;
            XAttribute xAttId = xInstance.Attribute(XName.Get("id"));
            if (xAttId != null)
            {
                id = xAttId.Value;
            }

            // select params
            XName paramName = XName.Get("param", Constants.ISONamespace);
            Dictionary<string, Parameter> dicParams = new Dictionary<string, Parameter>();
            foreach (XElement xParam in xInstance.Descendants())
            {
                if (xParam.Name == paramName)
                {
                    Parameter param = new Parameter();
                    param.Name = String.Concat("$", xParam.Attribute(XName.Get("name")).Value);
                    param.Value = xParam.Attribute(XName.Get("value")).Value;
                    dicParams.Add(param.Name, param);
                }
            }

            XElement newPattern = new XElement(dicAPs[isa]);

            // remove abstract attribute
            newPattern.Attribute(XName.Get("abstract")).Remove();

            // alter id attribute
            if (id != null)
            {
                newPattern.SetAttributeValue(XName.Get("id"), id);
            }
            else
            {
                newPattern.Attribute(XName.Get("id")).Remove();
            }

            // transform rules
            foreach (XElement xRule in newPattern.XPathSelectElements("//sch:rule[@context]", nsManager))
            {
                XAttribute xContext = xRule.Attribute(XName.Get("context"));
                string context = xContext.Value;
                foreach (KeyValuePair<string, Parameter> item in dicParams)
                {
                    context = context.Replace(item.Value.Name, item.Value.Value);
                }

                xContext.Value = context;
            }

            // transform asserts
            foreach (XElement xAssert in newPattern.XPathSelectElements("//sch:assert|//sch:report ", nsManager))
            {
                XAttribute xTest = xAssert.Attribute(XName.Get("test"));
                string test = xTest.Value;
                foreach (KeyValuePair<string, Parameter> item in dicParams)
                {
                    test = test.Replace(item.Value.Name, item.Value.Value);
                }

                xTest.Value = test;
            }

            xInstance.ReplaceWith(newPattern);
        }
開發者ID:xpekatt,項目名稱:SchemaTron,代碼行數:70,代碼來源:Preprocessor.cs

示例14: InterpolateDataToElement

        private bool InterpolateDataToElement(XElement source, IScope datasource, out XElement result) {
            result = source;
            if (UseExtensions) {
                if (!MatchCondition(source, datasource, "if")) {
                    return false;
                }
#if !EMBEDQPT
                XmlIncludeProvider = XmlIncludeProvider ?? new XmlIncludeProvider();
#endif
                var globalreplace = source.Attr("xi-replace");
                if (!string.IsNullOrWhiteSpace(globalreplace)) {
                    _stringInterpolation.Interpolate(globalreplace);
                    var xml = XmlIncludeProvider.GetXml(globalreplace, source, datasource);
                    if (null == xml) {
                        xml = XElement.Parse("<span class='no-ex replace'>no replace " + globalreplace + "</span>");
                    }
                    result = xml;
                    if (null != source.Parent) {
                        source.ReplaceWith(xml);
                    }
                    source = xml;
                }


                if (source.Attr("xi-repeat").ToBool()) {
                    XElement[] replace = ProcessRepeat(source, datasource);
                    if (null == replace) {
                        source.Remove();
                    }
                    else {
                        // ReSharper disable once CoVariantArrayConversion
                        source.ReplaceWith(replace);
                    }
                    return false;
                }

                var include = source.Attr("xi-include");
                if (!string.IsNullOrWhiteSpace(include)) {
                    _stringInterpolation.Interpolate(include);
                    var xml = XmlIncludeProvider.GetXml(include, source, datasource);
                    if (null == xml) {
                        xml = XElement.Parse("<span class='no-ex include'>no replace " + include + "</span>");
                    }
                    source.ReplaceAll(xml);
                }
            }

            var processchild = true;
            if (!string.IsNullOrWhiteSpace(StopAttribute)) {
                var stopper = source.Attribute(StopAttribute);
                if (null != stopper) {
                    if (stopper.Value != "0") {
                        if (stopper.Value == "all") {
                            return false;
                        }
                        processchild = false;
                    }
                }
            }
            if (CodeOnly) {
                foreach (var a in source.Attributes()) {
                    if (a.Name.LocalName == "code" || a.Name.LocalName == "id") {
                        var val = a.Value;
                        if (val.Contains(_stringInterpolation.AncorSymbol) &&
                            val.Contains(_stringInterpolation.StartSymbol)) {
                            val = _stringInterpolation.Interpolate(val, datasource, SecondSource);
                            a.Value = val;
                            datasource.Set(a.Name.LocalName, val);
                        }
                    }
                }
            }
            else {
                var changed = true;
                while (changed) {
                    changed = false;
                    foreach (var a in source.Attributes().OrderBy(_ => {
                        if (_.Value.Contains(AncorSymbol+"{") && _.Value.Contains("(")) {
                            return 1000;
                        }
                        return 0;
                    })) {
                        var val = a.Value;
                        if (val.Contains(_stringInterpolation.AncorSymbol) &&
                            val.Contains(_stringInterpolation.StartSymbol)) {
                            val = _stringInterpolation.Interpolate(val, datasource, SecondSource);
                            changed = changed || (val != a.Value);
                            a.Value = val;
                            datasource.Set(a.Name.LocalName, val);
                        }
                    }
                }
                changed = true;
                while (changed) {
                    changed = false;
                    foreach (var t in source.Nodes().OfType<XText>()) {
                        var val = t.Value;
                        if (val.Contains(_stringInterpolation.AncorSymbol) &&
                            val.Contains(_stringInterpolation.StartSymbol)) {
                            val = _stringInterpolation.Interpolate(val, datasource, SecondSource);
//.........這裏部分代碼省略.........
開發者ID:Qorpent,項目名稱:qorpent.sys,代碼行數:101,代碼來源:XmlInterpolation.cs

示例15: HandleSwitchElement

        private static void HandleSwitchElement(XElement element)
        {
            XElement defaultElement = element.Element(((XNamespace)LocalizationXmlConstants.XmlNamespace) + "default");
            Verify.IsNotNull(defaultElement, "Missing element named 'default' at {0}", element);


            XElement newValueParent = defaultElement;

            CultureInfo currentCultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
            foreach (XElement whenElement in element.Elements(((XNamespace)LocalizationXmlConstants.XmlNamespace) + "when"))
            {
                XAttribute cultureAttribute = whenElement.Attribute("culture");
                Verify.IsNotNull(cultureAttribute, "Missing attriubte named 'culture' at {0}", whenElement);

                CultureInfo cultureInfo = new CultureInfo(cultureAttribute.Value);
                if (cultureInfo.Equals(currentCultureInfo))
                {
                    newValueParent = whenElement;
                    break;
                }
            }

            element.ReplaceWith(newValueParent.Nodes());
        }
開發者ID:DBailey635,項目名稱:C1-CMS,代碼行數:24,代碼來源:LocalizationParser.cs


注:本文中的System.Xml.Linq.XElement.ReplaceWith方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。