2009-09-29 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / tools / generators / FieldInfo.cs
blob446affddafa2b6b5bf6a614a85e61245698aa3ab
1 /*
2 * FieldInfo.cs.
4 * Contact:
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.
13 using System;
16 class FieldInfo : MemberInfo {
17 public TypeReference FieldType;
18 public string BitField;
19 public bool IsConst;
20 public bool IsStatic;
21 public bool IsExtern;
22 public string Value;
24 public bool IsEvent {
25 get { return Name.EndsWith ("Event"); }
28 public string EventName {
29 get {
30 if (!IsEvent)
31 throw new System.Exception (string.Format ("The field '{0}' doesn't represent an event", FullName));
32 return Name.Substring (0, Name.LastIndexOf ("Event"));
36 public bool GenerateManagedEvent {
37 get {
38 string val = Annotations.GetValue ("GenerateManagedEvent");
39 if (val == null || val == "true")
40 return true;
41 if (val == "false")
42 return false;
44 throw new Exception ("Invalid value for 'GenerateManagedEvent'. Must be 'true' or 'false'");
48 public string EventDelegateType {
49 get {
50 string val = Annotations.GetValue ("DelegateType");
51 return val ?? "EventHandler";
55 public string DPAutoCreator {
56 get {
57 if (Annotations.ContainsKey ("AutoCreator"))
58 return Annotations.GetValue ("AutoCreator");
59 else if (Annotations.ContainsKey ("AutoCreateValue"))
60 return "AutoCreators::default_autocreator";
61 else
62 return null;
66 public bool IsDPReadOnly {
67 get { return Annotations.ContainsKey ("ReadOnly"); }
70 public bool IsDPAlwaysChange {
71 get { return Annotations.ContainsKey ("AlwaysChange"); }
74 public bool IsDPAttached {
75 get { return Annotations.ContainsKey ("Attached"); }
78 public bool IsDPNullable {
79 get { return Annotations.ContainsKey ("Nullable"); }
82 public bool IsCustom {
83 get {
84 string val = Annotations.GetValue ("IsCustom");
85 if (val == null || val == "false")
86 return false;
87 if (val == "true")
88 return true;
90 throw new Exception ("Invalid value for 'SetsParent'. Must be 'true' or 'false'");
94 public string DPPropertyType {
95 get {
96 string result = Annotations.GetValue ("PropertyType");
98 if (result != null) {
99 switch (result) {
100 case "string":
101 return "char*";
102 case "PixelFormat":
103 return "PixelFormats";
107 return result;
111 public string DPDefaultValue {
112 get { return Annotations.GetValue ("DefaultValue"); }
115 public string DPValidator {
116 get { return Annotations.GetValue ("Validator"); }
119 public bool GenerateManagedAccessors {
120 get {
121 string val = Annotations.GetValue ("GenerateManagedAccessors");
122 if (val == null || val == "true")
123 return true;
124 if (val == "false")
125 return false;
127 throw new Exception ("Invalid value for 'GenerateManagedAccessors'. Must be 'true' or 'false'");
131 public TypeInfo GetDPPropertyType (GlobalInfo all)
133 string property_type = DPPropertyType;
134 TypeInfo propertyType = null;
136 if (!string.IsNullOrEmpty (property_type)) {
137 if (all.Children.ContainsKey (property_type)) {
138 propertyType = (TypeInfo) all.Children [property_type];
139 } else {
140 Console.WriteLine ("{0}'s PropertyType '{1}' was not recognized. Do not use the Kind value, but the real type name.", FullName, property_type);
142 } else {
143 Console.WriteLine ("{0} does not have a PropertyType defined.", FullName);
146 return propertyType;
149 public string GetAccess ()
151 string result = Annotations.GetValue ("Access");
152 return string.IsNullOrEmpty (result) ? "Public" : result;
155 public string GetManagedAccess ()
157 string result = Annotations.GetValue ("ManagedAccess");
158 return string.IsNullOrEmpty (result) ? GetAccess () : result;
161 public string GetManagedFieldAccess ()
163 string result = Annotations.GetValue ("ManagedFieldAccess");
164 return string.IsNullOrEmpty (result) ? GetManagedAccess () : result;
167 public string GetManagedGetterAccess ()
169 string result = Annotations.GetValue ("ManagedGetterAccess");
170 return string.IsNullOrEmpty (result) ? GetManagedAccessorAccess () : result;
173 public string GetManagedSetterAccess ()
175 string result = Annotations.GetValue ("ManagedSetterAccess");
176 return string.IsNullOrEmpty (result) ? GetManagedAccessorAccess () : result;
179 public string GetManagedAccessorAccess ()
181 string result = Annotations.GetValue ("ManagedAccessorAccess");
182 return string.IsNullOrEmpty (result) ? GetManagedAccess () : result;
185 public string GetDPManagedPropertyType (GlobalInfo all)
187 string property_type = Annotations.GetValue ("ManagedPropertyType");
189 if (property_type != null)
190 return property_type;
192 property_type = Annotations.GetValue ("PropertyType");
194 if (property_type == null)
195 return null;
197 switch (property_type) {
198 case "char*":
199 property_type = "string"; break;
200 case "gint32":
201 property_type = "int"; break;
202 case "Managed":
203 property_type = "object"; break;
206 if (IsDPNullable)
207 return "Nullable<" + property_type + ">";
208 else
209 return property_type;
212 public string GetDependencyPropertyName ()
214 return Name.Substring (0, Name.LastIndexOf ("Property"));