XmlSerializerFormatAttribute.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel
  5. {
  6. using System;
  7. [AttributeUsage(ServiceModelAttributeTargets.ServiceContract | ServiceModelAttributeTargets.OperationContract, Inherited = false, AllowMultiple = false)]
  8. public sealed class XmlSerializerFormatAttribute : Attribute
  9. {
  10. bool supportFaults = false;
  11. OperationFormatStyle style;
  12. bool isStyleSet;
  13. OperationFormatUse use;
  14. public bool SupportFaults
  15. {
  16. get { return supportFaults; }
  17. set { supportFaults = value; }
  18. }
  19. public OperationFormatStyle Style
  20. {
  21. get { return style; }
  22. set
  23. {
  24. ValidateOperationFormatStyle(value);
  25. style = value;
  26. isStyleSet = true;
  27. }
  28. }
  29. public OperationFormatUse Use
  30. {
  31. get { return use; }
  32. set
  33. {
  34. ValidateOperationFormatUse(value);
  35. use = value;
  36. if (!isStyleSet && IsEncoded)
  37. Style = OperationFormatStyle.Rpc;
  38. }
  39. }
  40. internal bool IsEncoded
  41. {
  42. get { return use == OperationFormatUse.Encoded; }
  43. set { use = value ? OperationFormatUse.Encoded : OperationFormatUse.Literal; }
  44. }
  45. static internal void ValidateOperationFormatStyle(OperationFormatStyle value)
  46. {
  47. if (!OperationFormatStyleHelper.IsDefined(value))
  48. {
  49. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  50. }
  51. }
  52. static internal void ValidateOperationFormatUse(OperationFormatUse value)
  53. {
  54. if (!OperationFormatUseHelper.IsDefined(value))
  55. {
  56. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  57. }
  58. }
  59. }
  60. }