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
40 sealed class SoapHeaderMapping
44 bool is_unknown_header;
45 SoapHeaderDirection direction;
47 internal SoapHeaderMapping (MemberInfo member, SoapHeaderAttribute attributeInfo)
50 direction = attributeInfo.Direction;
51 if (member is PropertyInfo)
52 header_type = ((PropertyInfo) member).PropertyType;
54 header_type = ((FieldInfo) member).FieldType;
56 if (HeaderType == typeof(SoapHeader) || HeaderType == typeof(SoapUnknownHeader) ||
57 HeaderType == typeof(SoapHeader[]) || HeaderType == typeof(SoapUnknownHeader[]))
59 is_unknown_header = true;
61 else if (!typeof(SoapHeader).IsAssignableFrom (HeaderType))
62 throw new InvalidOperationException (string.Format ("Header members type must be a SoapHeader subclass"));
65 internal object GetHeaderValue (object ob)
67 if (member is PropertyInfo)
68 return ((PropertyInfo) member).GetValue (ob, null);
70 return ((FieldInfo) member).GetValue (ob);
73 internal void SetHeaderValue (object ob, SoapHeader header)
75 object value = header;
76 if (Custom && HeaderType.IsArray)
78 SoapUnknownHeader uheader = header as SoapUnknownHeader;
79 SoapUnknownHeader[] array = (SoapUnknownHeader[]) GetHeaderValue (ob);
80 if (array == null || array.Length == 0) {
81 value = new SoapUnknownHeader[] { uheader };
84 SoapUnknownHeader[] newArray = new SoapUnknownHeader [array.Length+1];
85 Array.Copy (array, newArray, array.Length);
86 newArray [array.Length] = uheader;
91 if (member is PropertyInfo)
92 ((PropertyInfo) member).SetValue (ob, value, null);
94 ((FieldInfo) member).SetValue (ob, value);
97 public SoapHeaderDirection Direction
99 get { return direction; }
102 public MemberInfo MemberInfo {
103 get { return member; }
106 public Type HeaderType {
107 get { return header_type; }
111 get { return is_unknown_header; }
115 public bool Repeats {
116 get { throw new NotImplementedException (); }