in class/Microsoft.SilverlightControls/:
[moon.git] / tools / generators / FieldInfo.cs
blobc91c8428e47868369a5cdfa4ec7d189123e590d7
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 bool GenerateManagedEventField {
49 get {
50 string val = Annotations.GetValue ("GenerateManagedEventField");
51 if (val == null || val == "false")
52 return false;
53 if (val == "true")
54 return true;
56 throw new Exception ("Invalid value for 'GenerateManagedEventField'. Must be 'true' or 'false'");
60 public string EventDelegateType {
61 get {
62 string val = Annotations.GetValue ("DelegateType");
63 return val ?? "EventHandler";
67 public string DPAutoCreator {
68 get {
69 if (Annotations.ContainsKey ("AutoCreator"))
70 return Annotations.GetValue ("AutoCreator");
71 else if (Annotations.ContainsKey ("AutoCreateValue"))
72 return "AutoCreators::default_autocreator";
73 else
74 return null;
78 public bool IsDPReadOnly {
79 get { return Annotations.ContainsKey ("ReadOnly"); }
82 public bool IsDPAlwaysChange {
83 get { return Annotations.ContainsKey ("AlwaysChange"); }
86 public bool IsDPAttached {
87 get { return Annotations.ContainsKey ("Attached"); }
90 public bool IsDPNullable {
91 get { return Annotations.ContainsKey ("Nullable"); }
94 public bool IsCustom {
95 get {
96 string val = Annotations.GetValue ("IsCustom");
97 if (val == null || val == "false")
98 return false;
99 if (val == "true")
100 return true;
102 throw new Exception ("Invalid value for 'SetsParent'. Must be 'true' or 'false'");
106 public string DPPropertyType {
107 get {
108 string result = Annotations.GetValue ("PropertyType");
110 if (result != null) {
111 switch (result) {
112 case "string":
113 return "char*";
114 case "PixelFormat":
115 return "PixelFormats";
119 return result;
123 public string DPDefaultValue {
124 get { return Annotations.GetValue ("DefaultValue"); }
127 public string DPValidator {
128 get { return Annotations.GetValue ("Validator"); }
131 public bool GenerateManagedAccessors {
132 get {
133 string val = Annotations.GetValue ("GenerateManagedAccessors");
134 if (val == null || val == "true")
135 return true;
136 if (val == "false")
137 return false;
139 throw new Exception ("Invalid value for 'GenerateManagedAccessors'. Must be 'true' or 'false'");
143 public TypeInfo GetDPPropertyType (GlobalInfo all)
145 string property_type = DPPropertyType;
146 TypeInfo propertyType = null;
148 if (!string.IsNullOrEmpty (property_type)) {
149 if (all.Children.ContainsKey (property_type)) {
150 propertyType = (TypeInfo) all.Children [property_type];
151 } else {
152 Console.WriteLine ("{0}'s PropertyType '{1}' was not recognized. Do not use the Kind value, but the real type name.", FullName, property_type);
154 } else {
155 Console.WriteLine ("{0} does not have a PropertyType defined.", FullName);
158 return propertyType;
161 public string GetAccess ()
163 string result = Annotations.GetValue ("Access");
164 return string.IsNullOrEmpty (result) ? "Public" : result;
167 public string GetManagedAccess ()
169 string result = Annotations.GetValue ("ManagedAccess");
170 return string.IsNullOrEmpty (result) ? GetAccess () : result;
173 public string GetManagedFieldAccess ()
175 string result = Annotations.GetValue ("ManagedFieldAccess");
176 return string.IsNullOrEmpty (result) ? GetManagedAccess () : result;
179 public string GetManagedGetterAccess ()
181 string result = Annotations.GetValue ("ManagedGetterAccess");
182 return string.IsNullOrEmpty (result) ? GetManagedAccessorAccess () : result;
185 public string GetManagedSetterAccess ()
187 string result = Annotations.GetValue ("ManagedSetterAccess");
188 return string.IsNullOrEmpty (result) ? GetManagedAccessorAccess () : result;
191 public string GetManagedAccessorAccess ()
193 string result = Annotations.GetValue ("ManagedAccessorAccess");
194 return string.IsNullOrEmpty (result) ? GetManagedAccess () : result;
197 public string GetDPManagedPropertyType (GlobalInfo all)
199 string property_type = Annotations.GetValue ("ManagedPropertyType");
201 if (property_type != null)
202 return property_type;
204 property_type = Annotations.GetValue ("PropertyType");
206 if (property_type == null)
207 return null;
209 switch (property_type) {
210 case "char*":
211 property_type = "string"; break;
212 case "gint32":
213 property_type = "int"; break;
214 case "Managed":
215 property_type = "object"; break;
218 if (IsDPNullable)
219 return "Nullable<" + property_type + ">";
220 else
221 return property_type;
224 public string GetDependencyPropertyName ()
226 return Name.Substring (0, Name.LastIndexOf ("Property"));