2 // SoapHeaderMapping.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Reflection;
33 namespace System.Web.Services.Protocols
36 sealed class SoapHeaderMapping // It used to be HeaderInfo class until Mono 1.2
40 bool is_unknown_header;
41 SoapHeaderDirection direction;
43 internal SoapHeaderMapping (MemberInfo member, SoapHeaderAttribute attributeInfo)
46 direction = attributeInfo.Direction;
47 if (member is PropertyInfo)
48 header_type = ((PropertyInfo) member).PropertyType;
50 header_type = ((FieldInfo) member).FieldType;
52 if (HeaderType == typeof(SoapHeader) || HeaderType == typeof(SoapUnknownHeader) ||
53 HeaderType == typeof(SoapHeader[]) || HeaderType == typeof(SoapUnknownHeader[]))
55 is_unknown_header = true;
57 else if (!typeof(SoapHeader).IsAssignableFrom (HeaderType))
58 throw new InvalidOperationException (string.Format ("Header members type must be a SoapHeader subclass"));
61 internal object GetHeaderValue (object ob)
63 if (member is PropertyInfo)
64 return ((PropertyInfo) member).GetValue (ob, null);
66 return ((FieldInfo) member).GetValue (ob);
69 internal void SetHeaderValue (object ob, SoapHeader header)
71 object value = header;
72 if (Custom && HeaderType.IsArray)
74 SoapUnknownHeader uheader = header as SoapUnknownHeader;
75 SoapUnknownHeader[] array = (SoapUnknownHeader[]) GetHeaderValue (ob);
76 if (array == null || array.Length == 0) {
77 value = new SoapUnknownHeader[] { uheader };
80 SoapUnknownHeader[] newArray = new SoapUnknownHeader [array.Length+1];
81 Array.Copy (array, newArray, array.Length);
82 newArray [array.Length] = uheader;
87 if (member is PropertyInfo)
88 ((PropertyInfo) member).SetValue (ob, value, null);
90 ((FieldInfo) member).SetValue (ob, value);
93 public SoapHeaderDirection Direction
95 get { return direction; }
98 public MemberInfo MemberInfo {
99 get { return member; }
102 public Type HeaderType {
103 get { return header_type; }
107 get { return is_unknown_header; }
111 public bool Repeats {
112 get { throw new NotImplementedException (); }