5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2008 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
14 using System
.Collections
.Generic
;
18 class GlobalInfo
: MemberInfo
{
19 private List
<FieldInfo
> dependency_properties
;
20 private List
<MethodInfo
> cppmethods_to_bind
;
21 private List
<MethodInfo
> jsmethods_to_bind
;
22 private List
<TypeInfo
> dependency_objects
;
25 /// A list of all the types that inherits from DependencyObject
27 public List
<TypeInfo
> GetDependencyObjects () {
28 if (dependency_objects
== null) {
29 dependency_objects
= new List
<TypeInfo
> ();
31 foreach (MemberInfo member
in Children
.Values
) {
32 TypeInfo type
= member
as TypeInfo
;
33 TypeInfo current
, parent
;
40 if (type
.IsEnum
|| type
.IsStruct
)
47 if (current
.Base
== null || string.IsNullOrEmpty (current
.Base
.Value
))
50 if (!Children
.ContainsKey (current
.Base
.Value
))
53 parent
= Children
[current
.Base
.Value
] as TypeInfo
;
58 if (parent
.Name
== "DependencyObject") {
67 // throw new Exception (string.Format ("Infinite loop while checking if '{0}' inherits from DependencyObject.", type.FullName));
70 dependency_objects
.Add (type
);
73 dependency_objects
.Sort (new Members
.MembersSortedByManagedFullName
<TypeInfo
> ());
75 return dependency_objects
;
78 public List
<FieldInfo
> DependencyProperties
{
80 if (dependency_properties
== null) {
81 // Check annotations against a list of known properties
82 // to catch typos (DefaulValue, etc).
83 Dictionary
<string, string> known_annotations
= new Dictionary
<string, string> ();
85 known_annotations
.Add ("ReadOnly", null);
86 known_annotations
.Add ("AlwaysChange", null);
87 known_annotations
.Add ("Version", null);
88 known_annotations
.Add ("PropertyType", null);
89 known_annotations
.Add ("AutoCreateValue", null);
90 known_annotations
.Add ("DefaultValue", null);
91 known_annotations
.Add ("Access", null);
92 known_annotations
.Add ("ManagedAccess", null);
93 known_annotations
.Add ("Nullable", null);
94 known_annotations
.Add ("Attached", null);
95 known_annotations
.Add ("ManagedDeclaringType", null);
96 known_annotations
.Add ("ManagedPropertyType", null);
97 known_annotations
.Add ("ManagedFieldAccess", null);
98 known_annotations
.Add ("ManagedAccessorAccess", null);
99 known_annotations
.Add ("ManagedGetterAccess", null);
100 known_annotations
.Add ("ManagedSetterAccess", null);
101 known_annotations
.Add ("GenerateGetter", null);
102 known_annotations
.Add ("GenerateSetter", null);
103 known_annotations
.Add ("GenerateAccessors", null);
104 known_annotations
.Add ("GenerateManagedDP", null);
105 known_annotations
.Add ("GenerateManagedAccessors", null);
106 known_annotations
.Add ("Validator", null);
107 known_annotations
.Add ("AutoCreator", null);
108 known_annotations
.Add ("IsCustom", null);
110 dependency_properties
= new List
<FieldInfo
> ();
111 foreach (MemberInfo member
in Children
.Values
) {
112 TypeInfo type
= member
as TypeInfo
;
117 foreach (MemberInfo member2
in member
.Children
.Values
) {
118 FieldInfo field
= member2
as FieldInfo
;
123 if (field
.FieldType
== null || field
.FieldType
.Value
!= "int")
129 if (!field
.Name
.EndsWith ("Property"))
132 dependency_properties
.Add (field
);
134 foreach (Annotation p
in field
.Annotations
.Values
) {
135 if (!known_annotations
.ContainsKey (p
.Name
))
136 Console
.WriteLine ("The field {0} in {3} has an unknown property: '{1}' = '{2}'", field
.FullName
, p
.Name
, p
.Value
, Path
.GetFileName (field
.Header
));
140 dependency_properties
.Sort (new Members
.MembersSortedByFullName
<FieldInfo
> ());
142 return dependency_properties
;
147 public List
<MethodInfo
> CPPMethodsToBind
{
149 if (cppmethods_to_bind
== null) {
150 cppmethods_to_bind
= new List
<MethodInfo
> ();
151 foreach (MemberInfo member1
in Children
.Values
) {
152 TypeInfo type
= member1
as TypeInfo
;
156 foreach (MemberInfo member2
in type
.Children
.Values
) {
157 MethodInfo method
= member2
as MethodInfo
;
160 if (method
.Parent
== null) {
161 Console
.WriteLine ("The method {0} in type {1} does not have its parent set.", method
.Name
, type
.Name
);
164 if (!method
.Annotations
.ContainsKey ("GenerateCBinding"))
166 cppmethods_to_bind
.Add (method
);
169 cppmethods_to_bind
.Sort (new Members
.MembersSortedByFullName
<MethodInfo
> ());
171 return cppmethods_to_bind
;
175 public List
<MethodInfo
> JSMethodsToBind
{
177 if (jsmethods_to_bind
== null) {
178 jsmethods_to_bind
= new List
<MethodInfo
> ();
179 foreach (MemberInfo member1
in Children
.Values
) {
180 TypeInfo type
= member1
as TypeInfo
;
184 foreach (MemberInfo member2
in type
.Children
.Values
) {
185 MethodInfo method
= member2
as MethodInfo
;
188 if (method
.Parent
== null) {
189 Console
.WriteLine ("The method {0} in type {1} does not have its parent set.", method
.Name
, type
.Name
);
192 if (!method
.Annotations
.ContainsKey ("GenerateJSBinding"))
195 jsmethods_to_bind
.Add (method
);
198 jsmethods_to_bind
.Sort (new Members
.MembersSortedByFullName
<MethodInfo
> ());
200 return jsmethods_to_bind
;
204 public bool IsEnum (string type
)
209 type
= type
.Replace ("*", "");
211 if (!Children
.TryGetValue (type
, out member
)) {
212 if (type
.Contains ("::")) {
213 string parent
= type
.Substring (0, type
.IndexOf ("::"));
214 string child
= type
.Substring (type
.IndexOf ("::") + 2);
216 if (!Children
.TryGetValue (parent
, out member
))
219 if (!member
.Children
.TryGetValue (child
, out member
))
227 tp
= member
as TypeInfo
;