~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.StateEngine/AspNetDom.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
using ICSharpCode.NRefactory.CSharp;
36
36
using ICSharpCode.NRefactory.TypeSystem;
37
37
using ICSharpCode.NRefactory;
 
38
using System.Linq;
38
39
 
39
40
namespace MonoDevelop.AspNet.StateEngine
40
41
{
230
231
                        get { return "<% %>"; }
231
232
                }
232
233
        }
 
234
 
 
235
        public static class AspNetDomExtensions
 
236
        {
 
237
                static XName scriptName = new XName ("script");
 
238
                static XName runatName = new XName ("runat");
 
239
                static XName idName = new XName ("id");
 
240
 
 
241
                public static bool IsRunatServer (this XElement el)
 
242
                {
 
243
                        var val = el.Attributes.GetValue (runatName, true);
 
244
                        return string.Equals (val, "server", StringComparison.OrdinalIgnoreCase);
 
245
                }
 
246
 
 
247
                public static string GetId (this IAttributedXObject el)
 
248
                {
 
249
                        return el.Attributes.GetValue (idName, true);
 
250
                }
 
251
 
 
252
                public static bool IsServerScriptTag (this XElement el)
 
253
                {
 
254
                        return XName.Equals (el.Name, scriptName, true) && IsRunatServer (el);
 
255
                }
 
256
 
 
257
                public static IEnumerable<T> WithName<T> (this IEnumerable<XNode> nodes, XName name, bool ignoreCase) where T : XNode, INamedXObject
 
258
                {
 
259
                        return nodes.OfType<T> ().Where (el => XName.Equals (el.Name, name, true));
 
260
                }
 
261
 
 
262
                public static IEnumerable<string> GetAllPlaceholderIds (this XDocument doc)
 
263
                {
 
264
                        return doc.AllDescendentNodes
 
265
                                .WithName<XElement> (new XName ("asp", "ContentPlaceHolder"), true)
 
266
                                .Where (x => x.IsRunatServer ())
 
267
                                .Select (x => x.GetId ())
 
268
                                .Where (id => !string.IsNullOrEmpty (id));
 
269
                }
 
270
        }
233
271
}