28 lines
866 B
C#
28 lines
866 B
C#
using System.Xml.Linq;
|
|
using XNeedle.Parser.Elements;
|
|
|
|
namespace XNeedle.Transformation.Bangs
|
|
{
|
|
public class AfterBang : BangOperation
|
|
{
|
|
public override string Name => "after";
|
|
|
|
public override Context Execute(Context ctx, IEnumerable<string> arguments)
|
|
{
|
|
if (ctx.Node == null)
|
|
{
|
|
throw new ArgumentNullException("!after needs a reachable node");
|
|
}
|
|
if (arguments.Count() < 1)
|
|
{
|
|
throw new ArgumentException("!after needs at least the tag name as argument.");
|
|
}
|
|
|
|
var tagname = arguments.ElementAt(0);
|
|
var element = new XElement(tagname, "");
|
|
ctx.Node.AddAfterSelf(element);
|
|
|
|
return new Context{ Node = element, SLoc = ctx.SLoc.AsSynthetic(), XPathSelector = tagname};
|
|
}
|
|
}
|
|
} |