private IParser <char, XObject> Content(
            Func <IParser <char, XText>, IParser <char, XText> > textSelector,
            bool includeComments = true)
        {
            Contract.Requires(textSelector != null);
            Contract.Ensures(Contract.Result <IParser <char, XObject> >() != null);

            return(Parser.Defer(() =>
            {
#if !SILVERLIGHT || WINDOWS_PHONE
                var content = new List <IParser <char, XObject> >(4)
                {
                    element(_ => true, AnyAttribute.NoneOrMore(), Content(textSelector, includeComments).NoneOrMore()),
                    textSelector(text),
                    cData
                };

                if (includeComments)
                {
                    content.Add(comment);
                }
#else
                var content = new List <IParser <char, XObject> >(4)
                {
                    element(_ => true, AnyAttribute.NoneOrMore(), Content(textSelector, includeComments).NoneOrMore()).Cast <char, XElement, XObject>(),
                    textSelector(text).Cast <char, XText, XObject>(),
                    cData.Cast <char, XCData, XObject>()
                };

                if (includeComments)
                {
                    content.Add(comment.Cast <char, XComment, XObject>());
                }
#endif

                return content.Any();
            }));
        }
Ejemplo n.º 2
0
 public static IParser <T?> Nullable <T>(this IParser <T> parser) where T : struct =>
 parser.Cast <T?>();