Merge pull request #600 from tr8dr/master
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / HttpCookieContainerBindingElement.cs
1 using System;
2 using System.Net;
3 using System.ServiceModel;
4
5 namespace System.ServiceModel.Channels
6 {
7 #if NET_4_0
8         [Obsolete ("Use AllowCookies.")]
9 #endif
10         public class HttpCookieContainerBindingElement : BindingElement
11         {
12                 HttpCookieContainerManager manager;
13
14                 public HttpCookieContainerBindingElement ()
15                 {
16                         manager = new HttpCookieContainerManager ();
17                 }
18
19                 protected HttpCookieContainerBindingElement (HttpCookieContainerBindingElement elementToBeCloned)
20                 {
21                         if (elementToBeCloned == null)
22                                 throw new ArgumentNullException ("elementToBeCloned");
23
24                         manager = new HttpCookieContainerManager (elementToBeCloned.manager);
25                 }
26
27                 public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (BindingContext context)
28                 {
29                         if (context == null)
30                                 throw new ArgumentNullException ("context");
31                         //context.RemainingBindingElements.Add (this);
32                         return base.BuildChannelFactory<TChannel> (context);
33                 }
34
35                 public override BindingElement Clone ()
36                 {
37                         return new HttpCookieContainerBindingElement (this);
38                 }
39
40                 public override T GetProperty<T> (BindingContext context)
41                 {
42                         if (manager is T)
43                                 return (T) (object) manager;
44                         return context.GetInnerProperty<T> ();
45                 }
46         }
47
48         class HttpCookieContainerManager : IHttpCookieContainerManager
49         {
50                 public HttpCookieContainerManager ()
51                 {
52                         CookieContainer = new CookieContainer ();
53                 }
54
55                 public HttpCookieContainerManager (HttpCookieContainerManager original)
56                 {
57                         CookieContainer = original.CookieContainer;
58                 }
59
60                 public CookieContainer CookieContainer { get; set; }
61         }
62 }