Esempio n. 1
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var name  = GetName(binder.Name);//TODO@personball deal with numbers
            var child = new XElement(name);

            Element.Add(child);
            result = new XmlDynamicConstructor(child, _root);
            return(true);
        }
Esempio n. 2
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var name  = GetName(binder.Name);//TODO deal with numbers
            var child = new XElement(name);

            if (args.Length == 1)
            {
                var arg = args[0];
                if (arg is string)
                {
                    child.Value = arg as string;
                }
                else
                {
                    XDC.SetAttributes(child, arg);
                }
            }
            else if (args.Length == 2)
            {
                var firstArg = args[0];
                if (firstArg is string)
                {
                    child.Value = firstArg as string;

                    var secondArg = args[1];
                    XDC.SetAttributes(child, secondArg);
                }
                else
                {
                    XDC.SetAttributes(child, firstArg);
                }
            }
            else
            {
                throw new NotSupportedException("only support two input parameters. first one as inner text(optional) and second one as attributes(optional).");
            }

            Element.Add(child);
            result = new XmlDynamicConstructor(child, _root);
            return(true);
        }
Esempio n. 3
0
 public XmlDynamicConstructor(XElement element, XmlDynamicConstructor root)
 {
     Element = element;
     _root   = root;
 }
Esempio n. 4
0
 public XmlDynamicConstructor(XElement element)
 {
     Element = element;
     _root   = this;
 }