AddressHeaderCollectionElement.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.Configuration;
  8. using System.ServiceModel.Channels;
  9. using System.Xml;
  10. using System.Security;
  11. using System.Runtime;
  12. public sealed partial class AddressHeaderCollectionElement : ServiceModelConfigurationElement
  13. {
  14. public AddressHeaderCollectionElement()
  15. {
  16. }
  17. internal void Copy(AddressHeaderCollectionElement source)
  18. {
  19. if (source == null)
  20. {
  21. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
  22. }
  23. PropertyInformationCollection properties = source.ElementInformation.Properties;
  24. if (properties[ConfigurationStrings.Headers].ValueOrigin != PropertyValueOrigin.Default)
  25. {
  26. this.Headers = source.Headers;
  27. }
  28. }
  29. [ConfigurationProperty(ConfigurationStrings.Headers, DefaultValue = null)]
  30. public AddressHeaderCollection Headers
  31. {
  32. get
  33. {
  34. AddressHeaderCollection retVal = (AddressHeaderCollection)base[ConfigurationStrings.Headers];
  35. if (null == retVal)
  36. {
  37. retVal = AddressHeaderCollection.EmptyHeaderCollection;
  38. }
  39. return retVal;
  40. }
  41. set
  42. {
  43. if (value == null)
  44. {
  45. value = AddressHeaderCollection.EmptyHeaderCollection;
  46. }
  47. base[ConfigurationStrings.Headers] = value;
  48. }
  49. }
  50. [Fx.Tag.SecurityNote(Critical = "Uses the critical helper SetIsPresent.",
  51. Safe = "Controls how/when SetIsPresent is used, not arbitrarily callable from PT (method is protected and class is sealed).")]
  52. [SecuritySafeCritical]
  53. protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
  54. {
  55. SetIsPresent();
  56. DeserializeElementCore(reader);
  57. }
  58. private void DeserializeElementCore(XmlReader reader)
  59. {
  60. this.Headers = AddressHeaderCollection.ReadServiceParameters(XmlDictionaryReader.CreateDictionaryReader(reader));
  61. }
  62. [Fx.Tag.SecurityNote(Critical = "Uses the critical helper SetIsPresent which elevates in order to set a property.",
  63. Safe = "Only passes 'this', does not let caller influence parameter.")]
  64. [SecurityCritical]
  65. void SetIsPresent()
  66. {
  67. ConfigurationHelpers.SetIsPresent(this);
  68. }
  69. protected override bool SerializeToXmlElement(XmlWriter writer, String elementName)
  70. {
  71. bool dataToWrite = this.Headers.Count != 0;
  72. if (dataToWrite && writer != null)
  73. {
  74. writer.WriteStartElement(elementName);
  75. this.Headers.WriteContentsTo(XmlDictionaryWriter.CreateDictionaryWriter(writer));
  76. writer.WriteEndElement();
  77. }
  78. return dataToWrite;
  79. }
  80. internal void InitializeFrom(AddressHeaderCollection headers)
  81. {
  82. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Headers, headers);
  83. }
  84. }
  85. }