2 // Copyright (C) 2010 Novell Inc. http://novell.com
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
24 using System.Collections.Generic;
25 using System.ComponentModel;
27 using System.Reflection;
28 using System.Xaml.Schema;
32 public class XamlDirective : XamlMember
34 class DirectiveMemberInvoker : XamlMemberInvoker
36 XamlDirective directive;
38 public DirectiveMemberInvoker (XamlDirective directive)
44 public XamlDirective (string xamlNamespace, string name)
45 : this (new string [] {xamlNamespace}, name, new XamlType (typeof (object), new XamlSchemaContext (new XamlSchemaContextSettings ())), null, AllowedMemberLocations.Any)
47 if (xamlNamespace == null)
48 throw new ArgumentNullException ("xamlNamespace");
52 public XamlDirective (IEnumerable<string> xamlNamespaces, string name, XamlType xamlType, XamlValueConverter<TypeConverter> typeConverter, AllowedMemberLocations allowedLocation)
53 : base (true, xamlNamespaces != null ? xamlNamespaces.FirstOrDefault () : null, name)
55 if (xamlNamespaces == null)
56 throw new ArgumentNullException ("xamlNamespaces");
58 throw new ArgumentNullException ("xamlType");
61 xaml_namespaces = new List<string> (xamlNamespaces);
62 AllowedLocation = allowedLocation;
63 type_converter = typeConverter;
65 invoker = new DirectiveMemberInvoker (this);
68 public AllowedMemberLocations AllowedLocation { get; private set; }
69 XamlValueConverter<TypeConverter> type_converter;
71 XamlMemberInvoker invoker;
73 IList<string> xaml_namespaces;
75 // this is for XamlLanguage.UnknownContent
76 internal bool InternalIsUnknown {
77 set { is_unknown = value; }
80 public override int GetHashCode ()
82 return ToString ().GetHashCode ();
85 public override IList<string> GetXamlNamespaces ()
87 return xaml_namespaces;
90 protected override sealed ICustomAttributeProvider LookupCustomAttributeProvider ()
92 return null; // as documented.
95 protected override sealed XamlValueConverter<XamlDeferringLoader> LookupDeferringLoader ()
97 return null; // as documented.
100 protected override sealed IList<XamlMember> LookupDependsOn ()
102 return null; // as documented.
105 protected override sealed XamlMemberInvoker LookupInvoker ()
110 protected override sealed bool LookupIsAmbient ()
115 protected override sealed bool LookupIsEvent ()
120 protected override sealed bool LookupIsReadOnly ()
125 protected override sealed bool LookupIsReadPublic ()
130 protected override sealed bool LookupIsUnknown ()
135 protected override sealed bool LookupIsWriteOnly ()
140 protected override sealed bool LookupIsWritePublic ()
145 protected override sealed XamlType LookupTargetType ()
150 protected override sealed XamlType LookupType ()
155 protected override sealed XamlValueConverter<TypeConverter> LookupTypeConverter ()
157 if (type_converter == null)
158 type_converter = base.LookupTypeConverter ();
159 return type_converter;
162 protected override sealed MethodInfo LookupUnderlyingGetter ()
167 protected override sealed MemberInfo LookupUnderlyingMember ()
172 protected override sealed MethodInfo LookupUnderlyingSetter ()
177 public override string ToString ()
179 return String.IsNullOrEmpty (PreferredXamlNamespace) ? Name : String.Concat ("{", PreferredXamlNamespace, "}", Name);