Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mcs / class / WindowsBase / System.Windows / DependencyObjectType.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // (C) 2005 Iain McCoy
21 // (C) 2007 Novell, Inc.
22 //
23 // Authors:
24 //   Iain McCoy (iain@mccoy.id.au)
25 //   Chris Toshok (toshok@ximian.com)
26 //
27 //
28
29 using System.Collections.Generic;
30
31 namespace System.Windows {
32         public class DependencyObjectType {
33
34                 private static Dictionary<Type,DependencyObjectType> typeMap = new Dictionary<Type,DependencyObjectType>();
35                 private static int current_id;
36
37                 private int id;
38                 private Type systemType;
39                 
40                 private DependencyObjectType (int id, Type systemType)
41                 {
42                         this.id = id;
43                         this.systemType = systemType;
44                 }
45
46                 public DependencyObjectType BaseType { 
47                         get { return DependencyObjectType.FromSystemType (systemType.BaseType); }
48                 }
49
50                 public int Id { 
51                         get { return id; }
52                 }
53
54                 public string Name { 
55                         get { return systemType.Name; }
56                 }
57
58                 public Type SystemType {
59                         get { return systemType; }
60                 }
61
62                 public static DependencyObjectType FromSystemType(Type systemType)
63                 {
64                         if (typeMap.ContainsKey (systemType))
65                                 return typeMap[systemType];
66
67                         DependencyObjectType dot;
68
69                         typeMap[systemType] = dot = new DependencyObjectType (current_id++, systemType);
70
71                         return dot;
72                 }
73
74                 public bool IsInstanceOfType(DependencyObject dependencyObject)
75                 {
76                         return systemType.IsInstanceOfType (dependencyObject);
77                 }
78
79                 public bool IsSubclassOf(DependencyObjectType dependencyObjectType)
80                 {
81                         return systemType.IsSubclassOf (dependencyObjectType.SystemType);
82                 }
83
84                 public override int GetHashCode ()
85                 {
86                         throw new NotImplementedException ();
87                 }
88         }
89 }