PageRenderTime 144ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/code/NorthWind/Templates/ImplGen.cst

https://bitbucket.org/eglimi/storm
Unknown | 736 lines | 699 code | 37 blank | 0 comment | 0 complexity | 1373e18925349bdb1dfb37c5c0d9b34c MD5 | raw file
  1. <%@ CodeTemplate Language="C#" TargetLanguage="C#" %>
  2. <%@ Property Name="assemblyLoader" Type="Storm.Loader.AssemblyLoader" %>
  3. <%@ Assembly Name="Storm" %>
  4. <%@ Import Namespace="System.Reflection" %>
  5. <%@ Import Namespace="System.Collections" %>
  6. <%@ Import Namespace="System.Text" %>
  7. <%@ Import Namespace="Storm.Attributes" %>
  8. <%@ Import Namespace="Storm.Lib" %>
  9. <%
  10. initType();
  11. processProperties();
  12. processPrimaryKeys();
  13. %>
  14. [DomainObjectImpl]
  15. public class <%= m_type.Name %>Impl : <%= m_type.Name %>
  16. {
  17. #region Factory Implementation
  18. <%if(Factory != null){ %>
  19. public class FactoryImpl : <%= m_factory.Name %>, IFactory
  20. { <%
  21. foreach(MethodInfo mInfo in Factory.GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public))
  22. {
  23. StringBuilder paramFullString = new StringBuilder();
  24. StringBuilder paramString = new StringBuilder();
  25. bool notFirst = false;
  26. foreach(ParameterInfo pInfo in mInfo.GetParameters())
  27. {
  28. if(notFirst)
  29. {
  30. paramFullString.Append(", ");
  31. paramString.Append(", ");
  32. }
  33. paramFullString.Append(pInfo.ParameterType.Name);
  34. paramFullString.Append(" ");
  35. paramFullString.Append(pInfo.Name);
  36. paramString.Append(pInfo.Name);
  37. notFirst = true;
  38. }%>
  39. public override <%= m_type.Name %> <%= mInfo.Name %>(<%= paramFullString.ToString() %>)
  40. {
  41. return new <%= m_type.Name %>Impl(<%= paramString.ToString() %>);
  42. }
  43. <%}
  44. }
  45. else
  46. { %>
  47. public class FactoryImpl : IFactory
  48. {
  49. <%} %>
  50. public DomainObject create()
  51. {
  52. return new <%= m_type.Name %>Impl();
  53. }
  54. public DomainObject createFromParameters(
  55. Key id,
  56. Timestamp timestamp,
  57. params DictionaryEntry[] parameters)
  58. {
  59. return new <%= m_type.Name %>Impl(id, timestamp, parameters);
  60. }
  61. }
  62. #endregion
  63. #region Finder Implementation
  64. <%if(Finder != null){ %>
  65. public class FinderImpl : <%= m_finder.Name %>, IFinder
  66. {
  67. <%
  68. foreach(MethodInfo mInfo in Finder.GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public))
  69. {
  70. if(mInfo.IsAbstract) {
  71. StringBuilder paramFullString = new StringBuilder();
  72. StringBuilder paramString = new StringBuilder();
  73. Hashtable paramEntries = new Hashtable();
  74. bool notFirst = false;
  75. foreach(ParameterInfo pInfo in mInfo.GetParameters())
  76. {
  77. if(notFirst)
  78. {
  79. paramFullString.Append(", ");
  80. paramString.Append(", ");
  81. }
  82. paramFullString.Append(pInfo.ParameterType.Name);
  83. paramFullString.Append(" ");
  84. paramFullString.Append(pInfo.Name);
  85. paramString.Append(pInfo.Name);
  86. foreach(Attribute paramAttr in pInfo.GetCustomAttributes(true))
  87. {
  88. if(paramAttr is Storm.Attributes.ParameterDefAttribute)
  89. {
  90. PropertyInfo colPInfo = m_type.GetProperty(((Storm.Attributes.ParameterDefAttribute)paramAttr).PropertyName);
  91. paramEntries.Add(getColumnName(colPInfo), pInfo.Name);
  92. }
  93. }
  94. notFirst = true;
  95. }%>
  96. public override IList <%= mInfo.Name %>(<%= paramFullString.ToString() %>)
  97. {
  98. QueryObject qo = new QueryObject();
  99. <%
  100. foreach(String crit in paramEntries.Keys)
  101. { %>
  102. qo.addCriteria(new Criteria(Criteria.Operator.Equal, "<%= crit %>", <%= paramEntries[crit] %>));
  103. <% } %>
  104. return Registry.Instance.getMapper(typeof(<%= m_type.Name %>)).find(qo);
  105. }
  106. <%}
  107. }
  108. } else
  109. { %>
  110. public class FinderImpl : IFinder
  111. {
  112. <%} %>
  113. public DomainObject findById(Key id)
  114. {
  115. return Registry.Instance.getMapper(typeof(<%= m_type.Name %>)).findById(id);
  116. }
  117. public IList find(QueryObject qo)
  118. {
  119. return Registry.Instance.getMapper(typeof(<%= m_type.Name %>)).find(qo);
  120. }
  121. public IList findAll()
  122. {
  123. return Registry.Instance.getMapper(typeof(<%= m_type.Name %>)).findAll();
  124. }
  125. }
  126. #endregion
  127. #region Static Attributes
  128. private static FactoryImpl m_FactoryImpl = new FactoryImpl();
  129. private static FinderImpl m_FinderImpl = new FinderImpl();
  130. #endregion
  131. #region Member Variables
  132. <%
  133. //Process all Properties and declare the appropriate member variables.
  134. //First, all To many relations are resolved then all the rest...
  135. foreach(PropertyInfo pInfo in m_properties)
  136. {
  137. if(!m_primaryKeys.Contains(pInfo.Name) || !isSurrogateKey())
  138. {
  139. if(isToMany(pInfo)){ %>
  140. private ToManyRelation m_<%= pInfo.Name %> = null;
  141. <%}
  142. if(isToOne(pInfo)){ %>
  143. private ToOneRelation m_<%= pInfo.Name %> = null;
  144. <%}
  145. else if(isColumn(pInfo) && (!isToOne(pInfo))){ %>
  146. private object m_<%= pInfo.Name %> = null;
  147. <%}
  148. }
  149. } %>
  150. #endregion
  151. #region Constructors
  152. public <%= m_type.Name %>Impl()
  153. {
  154. markNew();
  155. <%
  156. {
  157. foreach(PropertyInfo propInfo in m_properties)
  158. {
  159. if(isToOne(propInfo))
  160. {
  161. //if(notFirst)
  162. // paramString.Append(",\n\t\t\t\t\t\t");
  163. Type relation = null;
  164. String fieldName = String.Empty;
  165. if(isToOne(propInfo))
  166. {
  167. foreach(Attribute toOneAttr in propInfo.GetCustomAttributes(true))
  168. {
  169. if(toOneAttr is Storm.Attributes.ToOneAttribute)
  170. {
  171. relation = ((Storm.Attributes.ToOneAttribute)toOneAttr).RelationTo;
  172. PropertyInfo targetProp = relation.GetProperty(((Storm.Attributes.ToOneAttribute)toOneAttr).RelationName);
  173. foreach(Attribute targetAttr in targetProp.GetCustomAttributes(true))
  174. {
  175. if(targetAttr is Storm.Attributes.ColumnAttribute)
  176. fieldName = ((Storm.Attributes.ColumnAttribute)targetAttr).DbColumn;
  177. }
  178. }
  179. }
  180. %>
  181. m_<%= propInfo.Name %> = new ToOneRelation(typeof(<%= relation.Name %>), "<%= fieldName %>", null);
  182. <%
  183. }
  184. else if(isToMany(propInfo))
  185. {
  186. foreach(Attribute toManyAttr in propInfo.GetCustomAttributes(true))
  187. {
  188. if(toManyAttr is Storm.Attributes.ToManyAttribute)
  189. {
  190. relation = ((Storm.Attributes.ToManyAttribute)toManyAttr).RelationTo;
  191. PropertyInfo targetProp = relation.GetProperty(((Storm.Attributes.ToManyAttribute)toManyAttr).RelationName);
  192. foreach(Attribute targetAttr in targetProp.GetCustomAttributes(true))
  193. {
  194. if(targetAttr is Storm.Attributes.ColumnAttribute)
  195. fieldName = ((Storm.Attributes.ColumnAttribute)targetAttr).DbColumn;
  196. }
  197. }
  198. }
  199. %>
  200. m_<%= propInfo.Name %> = new ToOneRelation(typeof(<%= relation.Name %>), "<%= fieldName %>", null, false);
  201. <%
  202. }
  203. //notFirst = true;
  204. }
  205. } %>
  206. <%} %>
  207. }
  208. <%
  209. if(Factory != null){
  210. foreach(MethodInfo mInfo in Factory.GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public))
  211. {
  212. StringBuilder paramFullString = new StringBuilder();
  213. Hashtable paramEntries = new Hashtable();
  214. bool notFirst = false;
  215. foreach(ParameterInfo pInfo in mInfo.GetParameters())
  216. {
  217. if(notFirst)
  218. paramFullString.Append(", ");
  219. paramFullString.Append(pInfo.ParameterType.Name);
  220. paramFullString.Append(" ");
  221. paramFullString.Append(pInfo.Name);
  222. foreach(Attribute paramAttr in pInfo.GetCustomAttributes(true))
  223. {
  224. if(paramAttr is Storm.Attributes.ParameterDefAttribute)
  225. {
  226. foreach(PropertyInfo propInfo in m_properties)
  227. {
  228. if(((Storm.Attributes.ParameterDefAttribute)paramAttr).PropertyName == propInfo.Name)
  229. {
  230. if(isToOne(propInfo))
  231. {
  232. paramEntries.Add(((Storm.Attributes.ParameterDefAttribute)paramAttr).PropertyName+".Object", pInfo.Name);
  233. }
  234. else
  235. {
  236. paramEntries.Add(((Storm.Attributes.ParameterDefAttribute)paramAttr).PropertyName, pInfo.Name);
  237. }
  238. }
  239. }
  240. }
  241. }
  242. notFirst = true;
  243. } %>
  244. public <%= m_type.Name %>Impl(<%= paramFullString.ToString() %>)
  245. {
  246. markNew();
  247. <% foreach(PropertyInfo propInfo in m_properties)
  248. {
  249. String fieldName = String.Empty;
  250. foreach(Attribute propAttr in propInfo.GetCustomAttributes(true))
  251. {
  252. if(propAttr is Storm.Attributes.ToManyAttribute)
  253. {
  254. Type targetType = ((Storm.Attributes.ToManyAttribute)propAttr).RelationTo;
  255. PropertyInfo targetProp = targetType.GetProperty(((Storm.Attributes.ToManyAttribute)propAttr).RelationName);
  256. foreach(Attribute targetAttr in targetProp.GetCustomAttributes(true))
  257. {
  258. if(targetAttr is Storm.Attributes.ColumnAttribute)
  259. fieldName = ((Storm.Attributes.ColumnAttribute)targetAttr).DbColumn;
  260. }%>
  261. m_<%= propInfo.Name %> = new ToManyRelation(typeof(<%= ((Storm.Attributes.ToManyAttribute)propAttr).RelationTo.Name %>), "<%= fieldName %>", null, true);
  262. <%}
  263. else if(propAttr is Storm.Attributes.ToOneAttribute)
  264. {
  265. Type targetType = ((Storm.Attributes.ToOneAttribute)propAttr).RelationTo;
  266. PropertyInfo targetProp = targetType.GetProperty(((Storm.Attributes.ToOneAttribute)propAttr).RelationName);
  267. foreach(Attribute targetAttr in targetProp.GetCustomAttributes(true))
  268. {
  269. if(targetAttr is Storm.Attributes.ColumnAttribute)
  270. fieldName = ((Storm.Attributes.ColumnAttribute)targetAttr).DbColumn;
  271. }%>
  272. m_<%= propInfo.Name %> = new ToOneRelation(typeof(<%= ((Storm.Attributes.ToOneAttribute)propAttr).RelationTo.Name %>), "<%= fieldName %>", null);
  273. <%}
  274. }
  275. }%>
  276. <%
  277. IDictionaryEnumerator enumerator = paramEntries.GetEnumerator();
  278. while(enumerator.MoveNext()){%>
  279. m_<%= enumerator.Key %> = <%= enumerator.Value %>;
  280. <%} %>
  281. }
  282. <%}
  283. }%>
  284. internal <%= m_type.Name %>Impl(
  285. Key id,
  286. Timestamp timestamp,
  287. params DictionaryEntry[] parameters)
  288. {
  289. markClean();
  290. m_id = id;
  291. m_timestamp = timestamp;
  292. FieldInfo fInfo;
  293. Type thisType = this.GetType();
  294. Type domainObjectType = typeof(<%= m_type.Name %>);
  295. IEnumerator enumerator = parameters.GetEnumerator();
  296. while(enumerator.MoveNext())
  297. {
  298. if(((DictionaryEntry)enumerator.Current).Value != null)
  299. {
  300. if(((DictionaryEntry)enumerator.Current).Value.GetType() == typeof(ToOneRelation))
  301. {
  302. <%
  303. foreach(PropertyInfo propInfo in m_properties)
  304. {
  305. foreach(Attribute propAttr in propInfo.GetCustomAttributes(true))
  306. {
  307. if(propAttr is Storm.Attributes.ToOneAttribute)
  308. { %>
  309. if((String)((DictionaryEntry)enumerator.Current).Key == "<%= propInfo.Name %>")
  310. {
  311. m_<%= propInfo.Name %> = (ToOneRelation)((DictionaryEntry)enumerator.Current).Value;
  312. continue;
  313. }
  314. <%}
  315. }
  316. }%>
  317. }
  318. if(((DictionaryEntry)enumerator.Current).Value.GetType() == typeof(ToManyRelation))
  319. {
  320. <%
  321. foreach(PropertyInfo propInfo in m_properties)
  322. {
  323. foreach(Attribute propAttr in propInfo.GetCustomAttributes(true))
  324. {
  325. if(propAttr is Storm.Attributes.ToManyAttribute)
  326. { %>
  327. if((String)((DictionaryEntry)enumerator.Current).Key == "<%= propInfo.Name %>")
  328. {
  329. m_<%= propInfo.Name %> = (ToManyRelation)((DictionaryEntry)enumerator.Current).Value;
  330. continue;
  331. }
  332. <% }
  333. }
  334. }%>
  335. }
  336. }
  337. if(this.GetType().GetProperty((String)((DictionaryEntry)enumerator.Current).Key) != null)
  338. {
  339. string variable = "m_" + (String)((DictionaryEntry)enumerator.Current).Key;
  340. if((fInfo = thisType.GetField(variable, BindingFlags.DeclaredOnly|BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance)) != null)
  341. {
  342. fInfo.SetValue(this, ((DictionaryEntry)enumerator.Current).Value);
  343. }
  344. }
  345. }
  346. }
  347. #endregion
  348. #region Methods
  349. <%
  350. foreach(MethodInfo mInfo in m_type.GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public))
  351. {
  352. if(mInfo.IsAbstract)
  353. {
  354. foreach(Attribute mAttr in mInfo.GetCustomAttributes(true))
  355. {
  356. if(mAttr is Storm.Attributes.AdderAttribute)
  357. {
  358. ParameterInfo[] parameters = mInfo.GetParameters();
  359. if(parameters.Length != 1)
  360. {
  361. throw new ApplicationException("Parameter Length not 1: Parameter Length of an Adder Method must be 1");
  362. }
  363. String returnType = mInfo.ReturnType.Name;
  364. if(returnType == "Void")
  365. returnType = returnType.ToLower();
  366. foreach(ParameterInfo paramInfo in parameters)
  367. { %>
  368. public override <%= returnType %> <%= mInfo.Name %>(<%= paramInfo.ParameterType.Name %> <%= paramInfo.Name %>)
  369. {
  370. if(<%= paramInfo.Name %> != null)
  371. {
  372. <%= paramInfo.Name %>.<%= ((Storm.Attributes.AdderAttribute)mAttr).TargetProperty %> = this;
  373. m_<%= ((Storm.Attributes.AdderAttribute)mAttr).LocalProperty %>.Add(<%= paramInfo.Name %>);
  374. this.markDirty();
  375. }
  376. else
  377. {
  378. throw new ApplicationException();
  379. }
  380. }
  381. <%}
  382. }
  383. }
  384. }
  385. }
  386. %>
  387. public override void delete()
  388. {
  389. <%
  390. foreach(PropertyInfo propInfo in m_properties)
  391. {
  392. foreach(Attribute propAttr in propInfo.GetCustomAttributes(true))
  393. {
  394. if(propAttr is Storm.Attributes.ToManyAttribute)
  395. { %>
  396. foreach(<%= ((Storm.Attributes.ToManyAttribute)propAttr).RelationTo.Name %> <%= ((Storm.Attributes.ToManyAttribute)propAttr).RelationTo.Name.ToLower() %> in <%= propInfo.Name %>)
  397. {
  398. <%= ((Storm.Attributes.ToManyAttribute)propAttr).RelationTo.Name.ToLower() %>.delete();
  399. }
  400. <% }
  401. }
  402. }%>
  403. this.markRemoved();
  404. }
  405. #endregion
  406. #region Properties
  407. <%
  408. //Process all public and non-public properties and write them out.
  409. foreach(PropertyInfo pInfo in m_type.GetProperties(BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Instance))
  410. {
  411. if(hasAttributes(pInfo))
  412. {
  413. if(pInfo.PropertyType.IsPublic){ %>
  414. public override <%= pInfo.PropertyType.Name %> <%= pInfo.Name %>
  415. <%} else{ %>
  416. protected override <%= pInfo.PropertyType.Name %> <%= pInfo.Name %>
  417. <%} %>
  418. {
  419. <%if(hasGetMethod(pInfo)){ %>
  420. get
  421. {
  422. <%if(!isToMany(pInfo) && !isToOne(pInfo) && (!m_primaryKeys.Contains(pInfo.Name)))
  423. { %>
  424. if(m_<%= pInfo.Name %> == null)
  425. <%
  426. switch(pInfo.PropertyType.Name)
  427. {
  428. case "Int32" : %>
  429. return 0;
  430. <%break;
  431. case "Double" : %>
  432. return 0.0;
  433. <%break;
  434. case "String" : %>
  435. return String.Empty;
  436. <%break;
  437. case "DateTime" : %>
  438. return new DateTime(0);
  439. <%break;
  440. default : %>
  441. throw new NullReferenceException();
  442. <%break;
  443. }
  444. }
  445. if(m_primaryKeys.Contains(pInfo.Name) && !isToOne(pInfo)){%>
  446. if(m_id == null)
  447. <%
  448. switch(pInfo.PropertyType.Name)
  449. {
  450. case "Int32" : %>
  451. return 0;
  452. <%break;
  453. case "Double" : %>
  454. return 0.0;
  455. <%break;
  456. case "String" : %>
  457. return String.Empty;
  458. <%break;
  459. case "DateTime" : %>
  460. return new DateTime(0);
  461. <%break;
  462. default : %>
  463. throw new NullReferenceException();
  464. <%break;
  465. } %>
  466. return (<%= pInfo.PropertyType.Name %>)m_id[<%= m_primaryKeys.IndexOf(pInfo.Name) %>];
  467. <%}
  468. else if(isToOne(pInfo)) { %>
  469. return (<%= pInfo.PropertyType.Name %>)m_<%= pInfo.Name %>.Object;
  470. <%}
  471. else { %>
  472. return (<%= pInfo.PropertyType.Name %>)m_<%= pInfo.Name %>;
  473. <%} %>
  474. }
  475. <%} %>
  476. <%if(hasSetMethod(pInfo)){ %>
  477. set
  478. {
  479. <%if(isToOne(pInfo)) { %>
  480. m_<%= pInfo.Name %>.Object = value;
  481. <%}
  482. else {
  483. if(m_primaryKeys.Contains(pInfo.Name))
  484. {
  485. %>
  486. if(m_id == null)
  487. m_id = new Key(new object[] {value});
  488. else
  489. m_id[<%= m_primaryKeys.IndexOf(pInfo.Name) %>] = value;
  490. <%
  491. }
  492. %>
  493. m_<%= pInfo.Name %> = value;
  494. markDirty();
  495. <%
  496. } %>
  497. }
  498. <%
  499. } %>
  500. }
  501. <%
  502. }
  503. } %>
  504. public static FactoryImpl Factory
  505. {
  506. get
  507. {
  508. return m_FactoryImpl;
  509. }
  510. }
  511. public static FinderImpl Finder
  512. {
  513. get
  514. {
  515. return m_FinderImpl;
  516. }
  517. }
  518. public override bool isNull(string propertyName)
  519. {
  520. switch(propertyName)
  521. {
  522. <%
  523. foreach(PropertyInfo pInfo in m_type.GetProperties(BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Instance))
  524. {
  525. if(hasAttributes(pInfo))
  526. {
  527. if(!isToMany(pInfo) && !isToOne(pInfo) && !m_primaryKeys.Contains(pInfo.Name))
  528. {
  529. %>
  530. case "<%= pInfo.Name %>":
  531. if(m_<%= pInfo.Name %> == null) return true;
  532. break;
  533. <%
  534. }
  535. else if(isToOne(pInfo))
  536. {
  537. %>
  538. case "<%= pInfo.Name %>":
  539. if(m_<%= pInfo.Name %>.Object == null) return true;
  540. break;
  541. <%
  542. }
  543. }
  544. }
  545. %>
  546. default:
  547. break;
  548. }
  549. return false;
  550. }
  551. #endregion
  552. }
  553. <script runat="template">
  554. private Type m_type = null;
  555. private ArrayList m_properties = null;
  556. private ArrayList m_primaryKeys = null;
  557. private Type m_factory = null;
  558. private Type m_finder = null;
  559. void initType()
  560. {
  561. m_type = assemblyLoader.ClassType;
  562. }
  563. bool hasAttributes(PropertyInfo pInfo)
  564. {
  565. return pInfo.GetCustomAttributes(true).Length > 0 ? true : false;
  566. }
  567. bool hasGetMethod(PropertyInfo pInfo)
  568. {
  569. return pInfo.GetGetMethod(true) is MethodInfo ? true : false;
  570. }
  571. bool hasSetMethod(PropertyInfo pInfo)
  572. {
  573. return pInfo.GetSetMethod(true) is MethodInfo ? true : false;
  574. }
  575. string getColumnName(PropertyInfo propInfo)
  576. {
  577. String columnName = String.Empty;
  578. foreach(Attribute propAttr in propInfo.GetCustomAttributes(true))
  579. {
  580. if(propAttr is Storm.Attributes.ColumnAttribute)
  581. columnName = ((Storm.Attributes.ColumnAttribute)propAttr).DbColumn;
  582. }
  583. return columnName;
  584. }
  585. bool isToMany(PropertyInfo pInfo)
  586. {
  587. foreach(Attribute attr in pInfo.GetCustomAttributes(true))
  588. {
  589. if(attr is Storm.Attributes.ToManyAttribute)
  590. return true;
  591. }
  592. return false;
  593. }
  594. bool isToOne(PropertyInfo pInfo)
  595. {
  596. foreach(Attribute attr in pInfo.GetCustomAttributes(true))
  597. {
  598. if(attr is Storm.Attributes.ToOneAttribute)
  599. return true;
  600. }
  601. return false;
  602. }
  603. bool isColumn(PropertyInfo pInfo)
  604. {
  605. foreach(Attribute attr in pInfo.GetCustomAttributes(true))
  606. {
  607. if(attr is Storm.Attributes.ColumnAttribute)
  608. return true;
  609. }
  610. return false;
  611. }
  612. bool isPrimaryKey(PropertyInfo pInfo)
  613. {
  614. foreach(Attribute attr in pInfo.GetCustomAttributes(true))
  615. {
  616. if(attr is Storm.Attributes.PrimaryKeyAttribute)
  617. return true;
  618. }
  619. return false;
  620. }
  621. bool isSurrogateKey()
  622. {
  623. foreach(Attribute attr in m_type.GetCustomAttributes(false))
  624. if(attr is Storm.Attributes.TableAttribute)
  625. return ((Storm.Attributes.TableAttribute)attr).KeyIsSurrogate ? true : false;
  626. return false;
  627. }
  628. void processProperties()
  629. {
  630. if(m_properties == null)
  631. m_properties = new ArrayList();
  632. foreach(PropertyInfo pInfo in m_type.GetProperties(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance))
  633. {
  634. m_properties.Add(pInfo);
  635. }
  636. }
  637. void processPrimaryKeys()
  638. {
  639. if(m_primaryKeys == null)
  640. m_primaryKeys = new ArrayList();
  641. foreach(PropertyInfo pInfo in m_type.GetProperties(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance))
  642. {
  643. foreach(Attribute propAttr in pInfo.GetCustomAttributes(true))
  644. {
  645. if(propAttr is Storm.Attributes.PrimaryKeyAttribute)
  646. m_primaryKeys.Add(pInfo.Name);
  647. }
  648. }
  649. }
  650. //only one factory is allowed
  651. private Type Factory
  652. {
  653. get
  654. {
  655. if(m_factory == null)
  656. {
  657. foreach(Type nType in m_type.GetNestedTypes())
  658. {
  659. if(nType.IsClass && nType.IsAbstract)
  660. {
  661. foreach(Attribute attr in nType.GetCustomAttributes(true))
  662. {
  663. if(attr is Storm.Attributes.FactoryAttribute)
  664. {
  665. m_factory = nType;
  666. return m_factory;
  667. }
  668. }
  669. }
  670. }
  671. }
  672. return m_factory;
  673. }
  674. }
  675. private Type Finder
  676. {
  677. get
  678. {
  679. if(m_finder == null)
  680. {
  681. foreach(Type nType in m_type.GetNestedTypes())
  682. {
  683. if(nType.IsClass && nType.IsAbstract)
  684. {
  685. foreach(Attribute attr in nType.GetCustomAttributes(true))
  686. {
  687. if(attr is Storm.Attributes.FinderAttribute)
  688. {
  689. m_finder = nType;
  690. return m_finder;
  691. }
  692. }
  693. }
  694. }
  695. }
  696. return m_finder;
  697. }
  698. }
  699. </script>