Пример #1
0
        private T CreateItem(XElement target)
        {
            if (target == null)
            {
                throw new InvalidOperationException("elements have been removed");
            }
            T result = CursorCreater <T, XElement> .Create(_cursor, target);

            result.Build = _cursor.Build;
            return(result);
        }
Пример #2
0
        public static T Attribute <T>(this ICursor <XElement> cursor, string localName) where T : ICursor <XAttribute>
        {
            XAttribute resultTarget = cursor.Target.Attribute(localName);             //HACK: почему атрибуты не включены в пространство имен?

            if (resultTarget == null)
            {
                if (!cursor.Build)
                {
                    throw new FormatException(string.Format("attribute `{0}' not found", localName));
                }
                resultTarget = new XAttribute(localName, string.Empty);
                cursor.Target.Add(resultTarget);
            }
            T result = CursorCreater <T, XAttribute> .Create(cursor, resultTarget);

            result.Build = cursor.Build;
            return(result);
        }
Пример #3
0
        public static T Element <T>(this ICursor <XElement> cursor, string localName) where T : ICursor <XElement>
        {
            XElement resultTarget = cursor.Target.Element(cursor.NameSpace + localName);

            if (resultTarget == null)
            {
                if (!cursor.Build)
                {
                    throw new FormatException(string.Format("element `{0}' not found in {1}",
                                                            cursor.NameSpace + localName, cursor.Target.GetAbsoluteXPath()));
                }
                resultTarget = new XElement(cursor.NameSpace + localName);
                cursor.Target.Add(resultTarget);
            }
            T result = CursorCreater <T, XElement> .Create(cursor, resultTarget);

            result.Build = cursor.Build;
            return(result);
        }