ExtensionElement.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.Configuration;
  8. public partial class ExtensionElement : ConfigurationElement
  9. {
  10. string typeName;
  11. public ExtensionElement()
  12. {
  13. }
  14. public ExtensionElement(string name)
  15. : this()
  16. {
  17. if (String.IsNullOrEmpty(name))
  18. {
  19. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name");
  20. }
  21. this.Name = name;
  22. }
  23. public ExtensionElement(string name, string type)
  24. : this(name)
  25. {
  26. if (String.IsNullOrEmpty(type))
  27. {
  28. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("type");
  29. }
  30. this.Type = type;
  31. }
  32. [ConfigurationProperty(ConfigurationStrings.Name, Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
  33. [StringValidator(MinLength = 1)]
  34. public string Name
  35. {
  36. get { return (string)base[ConfigurationStrings.Name]; }
  37. set
  38. {
  39. if (String.IsNullOrEmpty(value))
  40. {
  41. value = String.Empty;
  42. }
  43. base[ConfigurationStrings.Name] = value;
  44. }
  45. }
  46. [ConfigurationProperty(ConfigurationStrings.Type, Options = ConfigurationPropertyOptions.IsRequired)]
  47. [StringValidator(MinLength = 1)]
  48. public string Type
  49. {
  50. get { return (string)base[ConfigurationStrings.Type]; }
  51. set
  52. {
  53. if (String.IsNullOrEmpty(value))
  54. {
  55. value = string.Empty;
  56. }
  57. base[ConfigurationStrings.Type] = value;
  58. }
  59. }
  60. internal string TypeName
  61. {
  62. get
  63. {
  64. if (string.IsNullOrEmpty(this.typeName))
  65. {
  66. this.typeName = GetTypeName(this.Type);
  67. }
  68. return this.typeName;
  69. }
  70. }
  71. internal static string GetTypeName(string fullyQualifiedName)
  72. {
  73. string typeName = fullyQualifiedName.Split(',')[0];
  74. return typeName.Trim();
  75. }
  76. }
  77. }