The Labs \ Source Viewer \ SSCLI \ System.Net.Configuration \ SocketElement

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SocketElement.cs" company="Microsoft Corporation">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Net.Configuration
  16. {
  17.     using System;
  18.     using System.Configuration;
  19.     using System.Reflection;
  20.     using System.Security.Permissions;
  21.    
  22.     public sealed class SocketElement : ConfigurationElement
  23.     {
  24.         public SocketElement()
  25.         {
  26.             this.properties.Add(this.alwaysUseCompletionPortsForAccept);
  27.             this.properties.Add(this.alwaysUseCompletionPortsForConnect);
  28.         }
  29.        
  30.         protected override void PostDeserialize()
  31.         {
  32.             // Perf optimization. If the configuration is coming from machine.config
  33.             // It is safe and we don't need to check for permissions.
  34.             if (EvaluationContext.IsMachineLevel)
  35.                 return;
  36.            
  37.             try {
  38.                 ExceptionHelper.UnrestrictedSocketPermission.Demand();
  39.             }
  40.             catch (Exception exception) {
  41.                 throw new ConfigurationErrorsException(SR.GetString(SR.net_config_element_permission, ConfigurationStrings.Socket), exception);
  42.             }
  43.         }
  44.        
  45.         [ConfigurationProperty(ConfigurationStrings.AlwaysUseCompletionPortsForAccept, DefaultValue = false)]
  46.         public bool AlwaysUseCompletionPortsForAccept {
  47.             get { return (bool)this[this.alwaysUseCompletionPortsForAccept]; }
  48.             set { this[this.alwaysUseCompletionPortsForAccept] = value; }
  49.         }
  50.        
  51.         [ConfigurationProperty(ConfigurationStrings.AlwaysUseCompletionPortsForConnect, DefaultValue = false)]
  52.         public bool AlwaysUseCompletionPortsForConnect {
  53.             get { return (bool)this[this.alwaysUseCompletionPortsForConnect]; }
  54.             set { this[this.alwaysUseCompletionPortsForConnect] = value; }
  55.         }
  56.        
  57.         protected override ConfigurationPropertyCollection Properties {
  58.             get { return this.properties; }
  59.         }
  60.        
  61.         ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
  62.        
  63.         readonly ConfigurationProperty alwaysUseCompletionPortsForConnect = new ConfigurationProperty(ConfigurationStrings.AlwaysUseCompletionPortsForConnect, typeof(bool), false, ConfigurationPropertyOptions.None);
  64.        
  65.         readonly ConfigurationProperty alwaysUseCompletionPortsForAccept = new ConfigurationProperty(ConfigurationStrings.AlwaysUseCompletionPortsForAccept, typeof(bool), false, ConfigurationPropertyOptions.None);
  66.        
  67.     }
  68. }

Developer Fusion