Merge branch 'cecil-light'
[mono.git] / mcs / class / System.Xaml / System.Xaml / XamlDirective.cs
1 //
2 // Copyright (C) 2010 Novell Inc. http://novell.com
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 using System;
24 using System.Collections.Generic;
25 using System.ComponentModel;
26 using System.Linq;
27 using System.Reflection;
28 using System.Xaml.Schema;
29
30 namespace System.Xaml
31 {
32         public class XamlDirective : XamlMember
33         {
34                 class DirectiveMemberInvoker : XamlMemberInvoker
35                 {
36                         XamlDirective directive;
37
38                         public DirectiveMemberInvoker (XamlDirective directive)
39                                 : base (directive)
40                         {
41                         }
42                 }
43
44                 public XamlDirective (string xamlNamespace, string name)
45                         : this (new string [] {xamlNamespace}, name, new XamlType (typeof (object), new XamlSchemaContext (new XamlSchemaContextSettings ())), null, AllowedMemberLocations.Any)
46                 {
47                         if (xamlNamespace == null)
48                                 throw new ArgumentNullException ("xamlNamespace");
49                         is_unknown = true;
50                 }
51
52                 public XamlDirective (IEnumerable<string> xamlNamespaces, string name, XamlType xamlType, XamlValueConverter<TypeConverter> typeConverter, AllowedMemberLocations allowedLocation)
53                         : base (true, xamlNamespaces != null ? xamlNamespaces.FirstOrDefault () : null, name)
54                 {
55                         if (xamlNamespaces == null)
56                                 throw new ArgumentNullException ("xamlNamespaces");
57                         if (xamlType == null)
58                                 throw new ArgumentNullException ("xamlType");
59
60                         type = xamlType;
61                         xaml_namespaces = new List<string> (xamlNamespaces);
62                         AllowedLocation = allowedLocation;
63                         type_converter = typeConverter;
64                         
65                         invoker = new DirectiveMemberInvoker (this);
66                 }
67
68                 public AllowedMemberLocations AllowedLocation { get; private set; }
69                 XamlValueConverter<TypeConverter> type_converter;
70                 XamlType type;
71                 XamlMemberInvoker invoker;
72                 bool is_unknown;
73                 IList<string> xaml_namespaces;
74
75                 // this is for XamlLanguage.UnknownContent
76                 internal bool InternalIsUnknown {
77                         set { is_unknown = value; }
78                 }
79
80                 public override int GetHashCode ()
81                 {
82                         return ToString ().GetHashCode ();
83                 }
84
85                 public override IList<string> GetXamlNamespaces ()
86                 {
87                         return xaml_namespaces;
88                 }
89
90                 protected override sealed ICustomAttributeProvider LookupCustomAttributeProvider ()
91                 {
92                         return null; // as documented.
93                 }
94
95                 protected override sealed XamlValueConverter<XamlDeferringLoader> LookupDeferringLoader ()
96                 {
97                         return null; // as documented.
98                 }
99
100                 protected override sealed IList<XamlMember> LookupDependsOn ()
101                 {
102                         return null; // as documented.
103                 }
104
105                 protected override sealed XamlMemberInvoker LookupInvoker ()
106                 {
107                         return invoker;
108                 }
109
110                 protected override sealed bool LookupIsAmbient ()
111                 {
112                         return false;
113                 }
114
115                 protected override sealed bool LookupIsEvent ()
116                 {
117                         return false;
118                 }
119
120                 protected override sealed bool LookupIsReadOnly ()
121                 {
122                         return false;
123                 }
124
125                 protected override sealed bool LookupIsReadPublic ()
126                 {
127                         return true;
128                 }
129
130                 protected override sealed bool LookupIsUnknown ()
131                 {
132                         return is_unknown;
133                 }
134
135                 protected override sealed bool LookupIsWriteOnly ()
136                 {
137                         return false;
138                 }
139
140                 protected override sealed bool LookupIsWritePublic ()
141                 {
142                         return true;
143                 }
144
145                 protected override sealed XamlType LookupTargetType ()
146                 {
147                         return null;
148                 }
149
150                 protected override sealed XamlType LookupType ()
151                 {
152                         return type;
153                 }
154
155                 protected override sealed XamlValueConverter<TypeConverter> LookupTypeConverter ()
156                 {
157                         if (type_converter == null)
158                                 type_converter = base.LookupTypeConverter ();
159                         return type_converter;
160                 }
161
162                 protected override sealed MethodInfo LookupUnderlyingGetter ()
163                 {
164                         return null;
165                 }
166
167                 protected override sealed MemberInfo LookupUnderlyingMember ()
168                 {
169                         return null;
170                 }
171
172                 protected override sealed MethodInfo LookupUnderlyingSetter ()
173                 {
174                         return null;
175                 }
176
177                 public override string ToString ()
178                 {
179                         return String.IsNullOrEmpty (PreferredXamlNamespace) ? Name : String.Concat ("{", PreferredXamlNamespace, "}", Name);
180                 }
181         }
182 }