PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Data.Linq/src/DbLinq/Schema/Dbml/DbmlSchema.Adapter.cs

https://bitbucket.org/danipen/mono
C# | 340 lines | 221 code | 28 blank | 91 comment | 18 complexity | 37de5e4d53e1fe6ecc1bcd492d213cb0 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. #region MIT license
  2. //
  3. // MIT license
  4. //
  5. // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. #endregion
  26. using System;
  27. using System.Collections.Generic;
  28. using System.ComponentModel;
  29. using System.Reflection;
  30. using System.Xml.Serialization;
  31. using DbLinq.Schema.Dbml.Adapter;
  32. /*
  33. * Here are additional methods and properties to DBML class.
  34. * Those properties are useful to dynamically change arrays
  35. */
  36. namespace DbLinq.Schema.Dbml
  37. {
  38. /// <summary>
  39. /// Adataper for Database
  40. /// </summary>
  41. partial class Database
  42. {
  43. /// <summary>
  44. /// Wraps all tables
  45. /// </summary>
  46. [Browsable(false)]
  47. [XmlIgnore]
  48. public ISimpleList<Table> Tables;
  49. /// <summary>
  50. /// Wraps all stored procedures
  51. /// </summary>
  52. [Browsable(false)]
  53. [XmlIgnore]
  54. public ISimpleList<Function> Functions;
  55. public Database()
  56. {
  57. SpecifiedPropertyUpdater.Register(this);
  58. Tables = new ArrayAdapter<Table>(this, "Table");
  59. Functions = new ArrayAdapter<Function>(this, "Function");
  60. }
  61. }
  62. /// <summary>
  63. /// Adapter for Table
  64. /// </summary>
  65. partial class Table
  66. {
  67. public Table()
  68. {
  69. Type = new Type();
  70. SpecifiedPropertyUpdater.Register(this);
  71. }
  72. public override string ToString()
  73. {
  74. return String.Format("{0} ({1}), {2}", Member, Name, Type);
  75. }
  76. }
  77. /// <summary>
  78. /// Adapter for Type
  79. /// </summary>
  80. partial class Type
  81. {
  82. /// <summary>
  83. /// Wrapper for columns
  84. /// </summary>
  85. [Browsable(false)]
  86. [XmlIgnore]
  87. public readonly ISimpleList<Column> Columns;
  88. /// <summary>
  89. /// Wrapper for associations
  90. /// </summary>
  91. [Browsable(false)]
  92. [XmlIgnore]
  93. public readonly ISimpleList<Association> Associations;
  94. public Type()
  95. {
  96. SpecifiedPropertyUpdater.Register(this);
  97. Columns = new ArrayAdapter<Column>(this, "Items");
  98. Associations = new ArrayAdapter<Association>(this, "Items");
  99. }
  100. public override string ToString()
  101. {
  102. string summary = Columns.Count + " Columns";
  103. if (Associations.Count > 0)
  104. summary += ", " + Associations.Count + " Associations";
  105. return summary;
  106. }
  107. }
  108. /// <summary>
  109. /// Adapter for function
  110. /// </summary>
  111. partial class Function
  112. {
  113. // TODO: remove this attribute
  114. [Browsable(false)]
  115. [XmlIgnore]
  116. public bool BodyContainsSelectStatement;
  117. [Browsable(false)]
  118. [XmlIgnore]
  119. public ISimpleList<Parameter> Parameters;
  120. [Browsable(false)]
  121. [XmlIgnore]
  122. public Return Return
  123. {
  124. get
  125. {
  126. if (Items == null)
  127. return null;
  128. foreach (object item in Items)
  129. {
  130. var r = item as Return;
  131. if (r != null)
  132. return r;
  133. }
  134. return null;
  135. }
  136. set
  137. {
  138. if (Items == null)
  139. {
  140. Items = new[] { value };
  141. return;
  142. }
  143. for (int index = 0; index < Items.Length; index++)
  144. {
  145. if (Items[index] is Return)
  146. {
  147. Items[index] = value;
  148. return;
  149. }
  150. }
  151. List<object> items = new List<object>(Items);
  152. items.Add(value);
  153. Items = items.ToArray();
  154. }
  155. }
  156. [Browsable(false)]
  157. [XmlIgnore]
  158. public object ElementType;
  159. public Function()
  160. {
  161. SpecifiedPropertyUpdater.Register(this);
  162. Parameters = new ArrayAdapter<Parameter>(this, "Parameter");
  163. }
  164. }
  165. /// <summary>
  166. /// Adapter for Association
  167. /// </summary>
  168. partial class Association
  169. {
  170. /// <summary>
  171. /// ThisKey, provided as an array of strings (each string being a key)
  172. /// </summary>
  173. [XmlIgnore]
  174. public ISimpleList<string> TheseKeys;
  175. /// <summary>
  176. /// OtherKey, provided as an array of strings (each string being a key)
  177. /// </summary>
  178. [XmlIgnore]
  179. public ISimpleList<string> OtherKeys;
  180. public Association()
  181. {
  182. SpecifiedPropertyUpdater.Register(this);
  183. TheseKeys = new CsvArrayAdapter(this, "ThisKey");
  184. OtherKeys = new CsvArrayAdapter(this, "OtherKey");
  185. }
  186. public override string ToString()
  187. {
  188. return Name;
  189. }
  190. }
  191. /// <summary>
  192. /// Adapter for Column
  193. /// </summary>
  194. partial class Column
  195. {
  196. private INamedType extendedType;
  197. /// <summary>
  198. /// Extended type, for handling enum types, for example.
  199. /// </summary>
  200. /// <value>The type of the extended.</value>
  201. [Browsable(false)]
  202. [XmlIgnore]
  203. public INamedType ExtendedType
  204. {
  205. get
  206. {
  207. if (extendedType == null)
  208. {
  209. if (EnumType.IsEnum(Type))
  210. extendedType = new EnumType(this, TypeMemberInfo);
  211. }
  212. return extendedType;
  213. }
  214. }
  215. public EnumType SetExtendedTypeAsEnumType()
  216. {
  217. return new EnumType(this, TypeMemberInfo);
  218. }
  219. private MemberInfo TypeMemberInfo
  220. {
  221. get
  222. {
  223. return GetType().GetMember("Type")[0];
  224. }
  225. }
  226. public Column()
  227. {
  228. SpecifiedPropertyUpdater.Register(this);
  229. }
  230. public override string ToString()
  231. {
  232. return String.Format("{0} ({1}): {2} ({3})", Member, Name, Type, DbType);
  233. }
  234. }
  235. partial class Connection
  236. {
  237. public Connection()
  238. {
  239. SpecifiedPropertyUpdater.Register(this);
  240. }
  241. }
  242. /// <summary>
  243. /// Adapter for Parameter
  244. /// </summary>
  245. partial class Parameter
  246. {
  247. public Parameter()
  248. {
  249. SpecifiedPropertyUpdater.Register(this);
  250. }
  251. /// <summary>
  252. /// Gets a value indicating whether [direction in].
  253. /// </summary>
  254. /// <value><c>true</c> if [direction in]; otherwise, <c>false</c>.</value>
  255. [Browsable(false)]
  256. [XmlIgnore]
  257. public bool DirectionIn
  258. {
  259. get { return Direction == ParameterDirection.In || Direction == ParameterDirection.InOut; }
  260. }
  261. /// <summary>
  262. /// Gets a value indicating whether [direction out].
  263. /// </summary>
  264. /// <value><c>true</c> if [direction out]; otherwise, <c>false</c>.</value>
  265. [Browsable(false)]
  266. [XmlIgnore]
  267. public bool DirectionOut
  268. {
  269. get { return Direction == ParameterDirection.Out || Direction == ParameterDirection.InOut; }
  270. }
  271. }
  272. /// <summary>
  273. /// Adapter for Return
  274. /// </summary>
  275. partial class Return
  276. {
  277. public Return()
  278. {
  279. SpecifiedPropertyUpdater.Register(this);
  280. }
  281. }
  282. /// <summary>
  283. /// Adapter for TableFunction
  284. /// </summary>
  285. partial class TableFunction
  286. {
  287. public TableFunction()
  288. {
  289. SpecifiedPropertyUpdater.Register(this);
  290. }
  291. }
  292. /// <summary>
  293. /// Adapter for TableFunctionParameter
  294. /// </summary>
  295. partial class TableFunctionParameter
  296. {
  297. public TableFunctionParameter()
  298. {
  299. SpecifiedPropertyUpdater.Register(this);
  300. }
  301. }
  302. /// <summary>
  303. /// Adapter for TableFunctionReturn
  304. /// </summary>
  305. partial class TableFunctionReturn
  306. {
  307. public TableFunctionReturn()
  308. {
  309. SpecifiedPropertyUpdater.Register(this);
  310. }
  311. }
  312. }