SoapTypeAttribute.cs: Set correct value for default namespace.
[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 using System;
11 using System.Runtime.Remoting;
12 using System.Runtime.Remoting.Metadata;
13
14 namespace System.Runtime.Remoting.Metadata {
15
16         [AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct |
17                          AttributeTargets.Enum | AttributeTargets.Interface)]
18         public sealed class SoapTypeAttribute : SoapAttribute
19         {
20                 SoapOption _soapOption;
21                 bool _useAttribute;
22                 string _xmlElementName;
23                 XmlFieldOrderOption _xmlFieldOrder;
24                 string _xmlNamespace;
25                 string _xmlTypeName;
26                 string _xmlTypeNamespace;
27                 bool _isType;
28                 bool _isElement;
29                 
30                 public SoapTypeAttribute ()
31                 {
32                 }
33
34                 public SoapOption SoapOptions {
35                         get {
36                                 return _soapOption;
37                         }
38
39                         set {
40                                 _soapOption = value;
41                         }
42                 }
43
44                 public override bool UseAttribute {
45                         get {
46                                 return _useAttribute;
47                         }
48
49                         set {
50                                 _useAttribute = value;
51                         }
52                 }
53
54                 public string XmlElementName {
55                         get {
56                                 return _xmlElementName;
57                         }
58
59                         set {
60                                 _isElement = value != null;
61                                 _xmlElementName = value;
62                         }
63                 }
64
65                 public XmlFieldOrderOption XmlFieldOrder {
66                         get {
67                                 return _xmlFieldOrder;
68                         }
69
70                         set {
71                                 _xmlFieldOrder = value;
72                         }
73                 }
74
75                 public override string XmlNamespace {
76                         get {
77                                 return _xmlNamespace;
78                         }
79
80                         set {
81                                 _isElement = value != null;
82                                 _xmlNamespace = value;
83                         }
84                 }
85
86                 public string XmlTypeName {
87                         get {
88                                 return _xmlTypeName;
89                         }
90
91                         set {
92                                 _isType = value != null;
93                                 _xmlTypeName = value;
94                         }
95                 }
96
97                 public string XmlTypeNamespace {
98                         get {
99                                 return _xmlTypeNamespace;
100                         }
101
102                         set {
103                                 _isType = value != null;
104                                 _xmlTypeNamespace = value;
105                         }
106                 }
107                 
108                 internal bool IsInteropXmlElement
109                 {
110                         get { return _isElement; }
111                 }
112                 
113                 internal bool IsInteropXmlType
114                 {
115                         get { return _isType; }
116                 }
117                 
118                 internal override void SetReflectionObject (object reflectionObject)
119                 {
120                         Type type = (Type) reflectionObject;
121                         
122                         if (_xmlElementName == null)
123                                 _xmlElementName = type.Name;
124                                 
125                         if (_xmlTypeName == null)
126                                 _xmlTypeName = type.Name;
127                         
128                         if (_xmlTypeNamespace == null)
129                         {
130                                 string na;
131                                 if (type.Assembly == typeof (object).Assembly) na = string.Empty;
132                                 else na = type.Assembly.GetName().Name;
133                                 _xmlTypeNamespace = SoapServices.CodeXmlNamespaceForClrTypeNamespace (type.Namespace, na);
134                         }
135                         
136                         if (_xmlNamespace == null)
137                                 _xmlNamespace = _xmlTypeNamespace;
138                 }
139         }
140 }