New test.
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Metadata / SoapTypeAttribute.cs
1 //
2 // System.Runtime.Remoting.Metadata.SoapTypeAttribute.cs
3 //
4 // Author: Duncan Mak  (duncan@ximian.com)
5 //         Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // 2002 (C) Copyright, Ximian, Inc.
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.Runtime.Remoting;
35 using System.Runtime.Remoting.Metadata;
36
37 namespace System.Runtime.Remoting.Metadata {
38
39         [AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct |
40                          AttributeTargets.Enum | AttributeTargets.Interface)]
41         public sealed class SoapTypeAttribute : SoapAttribute
42         {
43                 SoapOption _soapOption;
44                 bool _useAttribute;
45                 string _xmlElementName;
46                 XmlFieldOrderOption _xmlFieldOrder;
47                 string _xmlNamespace;
48                 string _xmlTypeName;
49                 string _xmlTypeNamespace;
50                 bool _isType;
51                 bool _isElement;
52                 
53                 public SoapTypeAttribute ()
54                 {
55                 }
56
57                 public SoapOption SoapOptions {
58                         get {
59                                 return _soapOption;
60                         }
61
62                         set {
63                                 _soapOption = value;
64                         }
65                 }
66
67                 public override bool UseAttribute {
68                         get {
69                                 return _useAttribute;
70                         }
71
72                         set {
73                                 _useAttribute = value;
74                         }
75                 }
76
77                 public string XmlElementName {
78                         get {
79                                 return _xmlElementName;
80                         }
81
82                         set {
83                                 _isElement = value != null;
84                                 _xmlElementName = value;
85                         }
86                 }
87
88                 public XmlFieldOrderOption XmlFieldOrder {
89                         get {
90                                 return _xmlFieldOrder;
91                         }
92
93                         set {
94                                 _xmlFieldOrder = value;
95                         }
96                 }
97
98                 public override string XmlNamespace {
99                         get {
100                                 return _xmlNamespace;
101                         }
102
103                         set {
104                                 _isElement = value != null;
105                                 _xmlNamespace = value;
106                         }
107                 }
108
109                 public string XmlTypeName {
110                         get {
111                                 return _xmlTypeName;
112                         }
113
114                         set {
115                                 _isType = value != null;
116                                 _xmlTypeName = value;
117                         }
118                 }
119
120                 public string XmlTypeNamespace {
121                         get {
122                                 return _xmlTypeNamespace;
123                         }
124
125                         set {
126                                 _isType = value != null;
127                                 _xmlTypeNamespace = value;
128                         }
129                 }
130                 
131                 internal bool IsInteropXmlElement
132                 {
133                         get { return _isElement; }
134                 }
135                 
136                 internal bool IsInteropXmlType
137                 {
138                         get { return _isType; }
139                 }
140                 
141                 internal override void SetReflectionObject (object reflectionObject)
142                 {
143                         Type type = (Type) reflectionObject;
144                         
145                         if (_xmlElementName == null)
146                                 _xmlElementName = type.Name;
147                                 
148                         if (_xmlTypeName == null)
149                                 _xmlTypeName = type.Name;
150                         
151                         if (_xmlTypeNamespace == null)
152                         {
153                                 string na;
154                                 if (type.Assembly == typeof (object).Assembly) na = string.Empty;
155                                 else na = type.Assembly.GetName().Name;
156                                 _xmlTypeNamespace = SoapServices.CodeXmlNamespaceForClrTypeNamespace (type.Namespace, na);
157                         }
158                         
159                         if (_xmlNamespace == null)
160                                 _xmlNamespace = _xmlTypeNamespace;
161                 }
162         }
163 }