NamedCssStyleCollection.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Authors:
  3. // Marek Habersack <[email protected]>
  4. //
  5. // (C) 2010 Novell, Inc (http://novell.com)
  6. //
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Web.UI;
  30. namespace System.Web.UI.WebControls
  31. {
  32. sealed class NamedCssStyleCollection
  33. {
  34. CssStyleCollection collection;
  35. public CssStyleCollection Collection {
  36. get {
  37. if (collection == null)
  38. collection = new CssStyleCollection ();
  39. return collection;
  40. }
  41. }
  42. public string Name { get; private set; }
  43. public NamedCssStyleCollection (string name)
  44. {
  45. if (name == null)
  46. name = String.Empty;
  47. Name = name;
  48. }
  49. public NamedCssStyleCollection CopyFrom (CssStyleCollection coll)
  50. {
  51. if (coll == null)
  52. return this;
  53. CssStyleCollection collection = Collection;
  54. foreach (string key in coll.Keys)
  55. collection.Add (key, coll [key]);
  56. return this;
  57. }
  58. public NamedCssStyleCollection Add (HtmlTextWriterStyle key, string value)
  59. {
  60. Collection.Add (key, value);
  61. return this;
  62. }
  63. public NamedCssStyleCollection Add (string key, string value)
  64. {
  65. Collection.Add (key, value);
  66. return this;
  67. }
  68. public NamedCssStyleCollection Add (Style style)
  69. {
  70. if (style != null)
  71. CopyFrom (style.GetStyleAttributes (null));
  72. return this;
  73. }
  74. }
  75. }