New tests.
[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                         {
40                         }
41                 }
42
43                 public XamlDirective (string xamlNamespace, string name)
44                         : this (new string [] {xamlNamespace}, name, new XamlType (typeof (object), new XamlSchemaContext (new XamlSchemaContextSettings ())), null, AllowedMemberLocations.Any)
45                 {
46                         if (xamlNamespace == null)
47                                 throw new ArgumentNullException ("xamlNamespace");
48                         is_unknown = true;
49                 }
50
51                 public XamlDirective (IEnumerable<string> xamlNamespaces, string name, XamlType xamlType, XamlValueConverter<TypeConverter> typeConverter, AllowedMemberLocations allowedLocation)
52                         : base (true, xamlNamespaces != null ? xamlNamespaces.FirstOrDefault () : null, name)
53                 {
54                         if (xamlNamespaces == null)
55                                 throw new ArgumentNullException ("xamlNamespaces");
56                         if (xamlType == null)
57                                 throw new ArgumentNullException ("xamlType");
58
59                         type = xamlType;
60                         xaml_namespaces = new List<string> (xamlNamespaces);
61                         AllowedLocation = allowedLocation;
62                         type_converter = typeConverter;
63                         
64                         invoker = new DirectiveMemberInvoker (this);
65                 }
66
67                 public AllowedMemberLocations AllowedLocation { get; private set; }
68                 XamlValueConverter<TypeConverter> type_converter;
69                 XamlType type;
70                 XamlMemberInvoker invoker;
71                 bool is_unknown;
72                 IList<string> xaml_namespaces;
73
74                 // this is for XamlLanguage.UnknownContent
75                 internal bool InternalIsUnknown {
76                         set { is_unknown = value; }
77                 }
78
79                 public override int GetHashCode ()
80                 {
81                         throw new NotImplementedException ();
82                 }
83
84                 public override IList<string> GetXamlNamespaces ()
85                 {
86                         return xaml_namespaces;
87                 }
88
89                 protected override sealed ICustomAttributeProvider LookupCustomAttributeProvider ()
90                 {
91                         return null; // as documented.
92                 }
93
94                 protected override sealed XamlValueConverter<XamlDeferringLoader> LookupDeferringLoader ()
95                 {
96                         return null; // as documented.
97                 }
98
99                 protected override sealed IList<XamlMember> LookupDependsOn ()
100                 {
101                         return null; // as documented.
102                 }
103
104                 protected override sealed XamlMemberInvoker LookupInvoker ()
105                 {
106                         return invoker;
107                 }
108
109                 protected override sealed bool LookupIsAmbient ()
110                 {
111                         return false;
112                 }
113
114                 protected override sealed bool LookupIsEvent ()
115                 {
116                         return false;
117                 }
118
119                 protected override sealed bool LookupIsReadOnly ()
120                 {
121                         return false;
122                 }
123
124                 protected override sealed bool LookupIsReadPublic ()
125                 {
126                         return true;
127                 }
128
129                 protected override sealed bool LookupIsUnknown ()
130                 {
131                         return is_unknown;
132                 }
133
134                 protected override sealed bool LookupIsWriteOnly ()
135                 {
136                         return false;
137                 }
138
139                 protected override sealed bool LookupIsWritePublic ()
140                 {
141                         return true;
142                 }
143
144                 protected override sealed XamlType LookupTargetType ()
145                 {
146                         return null;
147                 }
148
149                 protected override sealed XamlType LookupType ()
150                 {
151                         return type;
152                 }
153
154                 protected override sealed XamlValueConverter<TypeConverter> LookupTypeConverter ()
155                 {
156                         if (type_converter == null)
157                                 type_converter = base.LookupTypeConverter ();
158                         return type_converter;
159                 }
160
161                 protected override sealed MethodInfo LookupUnderlyingGetter ()
162                 {
163                         return null;
164                 }
165
166                 protected override sealed MemberInfo LookupUnderlyingMember ()
167                 {
168                         return null;
169                 }
170
171                 protected override sealed MethodInfo LookupUnderlyingSetter ()
172                 {
173                         return null;
174                 }
175
176                 public override string ToString ()
177                 {
178                         return String.IsNullOrEmpty (PreferredXamlNamespace) ? Name : String.Concat ("{", PreferredXamlNamespace, "}", Name);
179                 }
180         }
181 }