912ab8441463f225a742f3af1f0e22cf4336577b
[mono.git] / mcs / class / System.Web.DynamicData / Test / Common / MiscExtensions.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Web;
6 using System.Web.UI;
7
8 namespace MonoTests.Common
9 {
10         public static class MiscExtensions
11         {
12                 public static TChild FindChild <TChild> (this Control parent) where TChild: class
13                 {
14                         return FindChild <TChild> (parent, null);
15                 }
16
17                 public static TChild FindChild<TChild> (this Control parent, string id) where TChild: class
18                 {
19                         if (parent == null)
20                                 return null;
21                         
22                         foreach (Control child in parent.Controls) {
23                                 if (child == null)
24                                         continue;
25
26                                 if (typeof (TChild).IsAssignableFrom (child.GetType ())) {
27                                         if (!String.IsNullOrEmpty (id))
28                                                 return child as TChild;
29                                         if (String.Compare (child.ID, id, StringComparison.OrdinalIgnoreCase) == 0)
30                                                 return child as TChild;
31                                 }
32
33                                 TChild ret = child.FindChild<TChild> (id);
34                                 if (ret != null)
35                                         return ret;
36                         }
37
38                         return null;
39                 }
40         }
41 }