CollectionBuilder.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // System.Web.UI.CollectionBuilder.cs
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (c) 2003 Ximian, Inc. (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Reflection;
  12. namespace System.Web.UI
  13. {
  14. sealed class CollectionBuilder : ControlBuilder
  15. {
  16. Type elementType;
  17. internal CollectionBuilder ()
  18. {
  19. }
  20. public override void AppendLiteralString (string s)
  21. {
  22. if (s != null && s.Trim () != "")
  23. throw new HttpException ("Literal content not allowed for " + ControlType);
  24. }
  25. public override Type GetChildControlType (string tagName, IDictionary attribs)
  26. {
  27. Type t = Root.GetChildControlType (tagName, attribs);
  28. if (elementType != null && !elementType.IsAssignableFrom (t))
  29. throw new HttpException ("Cannot add a " + t + " to " + elementType);
  30. return t;
  31. }
  32. public override void Init (TemplateParser parser,
  33. ControlBuilder parentBuilder,
  34. Type type,
  35. string tagName,
  36. string id,
  37. IDictionary attribs)
  38. {
  39. base.Init (parser, parentBuilder, type, tagName, id, attribs);
  40. PropertyInfo prop = parentBuilder.ControlType.GetProperty (tagName, flagsNoCase);
  41. SetControlType (prop.PropertyType);
  42. prop = ControlType.GetProperty ("Item", flagsNoCase & ~BindingFlags.IgnoreCase);
  43. elementType = prop.PropertyType;
  44. }
  45. }
  46. }