Column.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Reflection;
  7. using System.Runtime.Serialization;
  8. using Newtonsoft.Json;
  9. using Newtonsoft.Json.Linq;
  10. namespace InABox.Core
  11. {
  12. public interface IColumn
  13. {
  14. string Property { get; }
  15. Expression Expression { get; }
  16. Type Type { get; }
  17. }
  18. public static class Column
  19. {
  20. public static IColumn Create(Type concrete, string property)
  21. {
  22. var type = typeof(Column<>).MakeGenericType(concrete);
  23. var result = Activator.CreateInstance(type, property) as IColumn;
  24. return result!;
  25. }
  26. }
  27. public class Column<T> : SerializableExpression<T>, IColumn
  28. {
  29. public Type Type
  30. {
  31. get
  32. {
  33. if (Expression == null)
  34. throw new Exception(string.Format("Expression [{0}] may not be null!", Property));
  35. if (Expression is IndexExpression)
  36. return DatabaseSchema.Property(typeof(T), Property).PropertyType;
  37. return Expression.Type;
  38. }
  39. }
  40. public bool IsEqualTo(string name) =>
  41. !string.IsNullOrWhiteSpace(name) && string.Equals(Property, name);
  42. public bool IsEqualTo(Column<T> column) => string.Equals(Property, column.Property);
  43. public bool IsParentOf(string name) =>
  44. !string.IsNullOrWhiteSpace(name) && name.StartsWith(Property + ".");
  45. public Column()
  46. {
  47. }
  48. public Column(Expression<Func<T, object?>> expression) : base(expression)
  49. {
  50. //String[] parts = expression.ToString().Split(new String[] { "=>" }, StringSplitOptions.RemoveEmptyEntries);
  51. //string property = String.Join(".", parts.Last().Split('.').Skip(1));
  52. //property = property.Replace("Convert(", "").Replace("(","").Replace(")", "");
  53. Property = CoreUtils.GetFullPropertyName(expression, ".");
  54. }
  55. public Column(string property)
  56. {
  57. Property = property;
  58. var iprop = DatabaseSchema.Property(typeof(T), property);
  59. if (iprop != null)
  60. Expression = iprop.Expression();
  61. else
  62. Expression = CoreUtils.CreateMemberExpression(typeof(T), property);
  63. }
  64. public Column<TNew> Cast<TNew>()
  65. where TNew: T
  66. {
  67. return new Column<TNew>(Property);
  68. }
  69. public string Property { get; private set; }
  70. public override void Deserialize(SerializationInfo info, StreamingContext context)
  71. {
  72. }
  73. public override void Serialize(SerializationInfo info, StreamingContext context)
  74. {
  75. }
  76. public static explicit operator Column<T>(Column<Entity> v)
  77. {
  78. var result = new Column<T>();
  79. var exp = CoreUtils.ExpressionToString(typeof(T), v.Expression, true);
  80. result.Expression = CoreUtils.StringToExpression(exp);
  81. result.Property = v.Property;
  82. return result;
  83. }
  84. public override string ToString()
  85. {
  86. var name = Expression.ToString().Replace("x => ", "").Replace("x.", "");
  87. if (Expression.NodeType == System.Linq.Expressions.ExpressionType.Index)
  88. {
  89. var chars = name.SkipWhile(x => !x.Equals('[')).TakeWhile(x => !x.Equals(']'));
  90. name = string.Join("", chars).Replace("[", "").Replace("]", "").Replace("\"", "");
  91. }
  92. return name;
  93. //return Property.ToString();
  94. }
  95. }
  96. public interface IColumns : ISerializeBinary
  97. {
  98. int Count { get; }
  99. bool Any();
  100. IEnumerable<IColumn> GetColumns();
  101. IEnumerable<string> ColumnNames();
  102. Dictionary<String, Type> AsDictionary();
  103. IColumns Add(string column);
  104. IColumns Add(IColumn column);
  105. IColumns Add<T>(Expression<Func<T, object?>> column);
  106. IColumns DefaultColumns(params ColumnType[] types);
  107. }
  108. public enum ColumnType
  109. {
  110. ExcludeVisible,
  111. /// <summary>
  112. /// Do not include <see cref="Entity.ID"/> in the columns.
  113. /// </summary>
  114. ExcludeID,
  115. IncludeOptional,
  116. IncludeForeignKeys,
  117. /// <summary>
  118. /// Include all columns that are accessible through entity links present in the root class.
  119. /// </summary>
  120. IncludeLinked,
  121. IncludeAggregates,
  122. IncludeFormulae,
  123. /// <summary>
  124. /// Include any columns that are a <see cref="CustomProperty"/>.
  125. /// </summary>
  126. IncludeUserProperties,
  127. /// <summary>
  128. /// Include all columns that are accessible through entity links, even nested ones.
  129. /// </summary>
  130. IncludeNestedLinks,
  131. IncludeEditable,
  132. /// <summary>
  133. /// Add all columns that are data actually on the entity, and not on entity links or calculated fields.
  134. /// </summary>
  135. DataColumns,
  136. /// <summary>
  137. /// Add all columns found.
  138. /// </summary>
  139. All
  140. }
  141. public static class Columns
  142. {
  143. public static IColumns Create<T>(Type concrete)
  144. {
  145. if (!typeof(T).IsAssignableFrom(concrete))
  146. throw new Exception($"Columns: {concrete.EntityName()} does not implement {typeof(T).EntityName()}");
  147. var type = typeof(Columns<>).MakeGenericType(concrete);
  148. var result = Activator.CreateInstance(type);
  149. return (result as IColumns)!;
  150. }
  151. public static IColumns Create(Type concrete)
  152. {
  153. var type = typeof(Columns<>).MakeGenericType(concrete);
  154. var result = Activator.CreateInstance(type) as IColumns;
  155. return result!;
  156. }
  157. public static IColumns Create(Type concrete, IEnumerable<string> columns)
  158. {
  159. var type = typeof(Columns<>).MakeGenericType(concrete);
  160. var result = (IColumns)Activator.CreateInstance(type);
  161. foreach (var column in columns)
  162. result.Add(column);
  163. return result;
  164. }
  165. public static IColumns Create(Type concrete, params string[] columns)
  166. {
  167. var type = typeof(Columns<>).MakeGenericType(concrete);
  168. var result = (IColumns)Activator.CreateInstance(type);
  169. foreach (var column in columns)
  170. result.Add(column);
  171. return result;
  172. }
  173. }
  174. public class Columns<T> : IColumns, IEnumerable<Column<T>>
  175. {
  176. private readonly List<Column<T>> columns;
  177. public Columns()
  178. {
  179. columns = new List<Column<T>>();
  180. }
  181. /// <summary>
  182. /// Create a new <see cref="Columns{T}"/>, using <paramref name="columns"/> as the internal list.
  183. /// </summary>
  184. /// <remarks>
  185. /// <paramref name="columns"/> is passed by reference and is stored as the internal list of the <see cref="Columns{T}"/>;
  186. /// hence if one wishes <paramref name="columns"/> to not be modified, one should pass a copy of the list.
  187. /// </remarks>
  188. /// <param name="columns"></param>
  189. public Columns(List<Column<T>> columns)
  190. {
  191. this.columns = columns;
  192. }
  193. public Columns<TNew> Cast<TNew>()
  194. where TNew : T
  195. {
  196. var cols = new Columns<TNew>();
  197. foreach(var column in columns)
  198. {
  199. cols.Add(column.Cast<TNew>());
  200. }
  201. return cols;
  202. }
  203. public override string ToString()
  204. {
  205. return String.Join("; ", columns.Select(x => x.Property));
  206. }
  207. public int IndexOf(String columnname)
  208. {
  209. return ColumnNames().ToList().IndexOf(columnname);
  210. }
  211. public int IndexOf(Expression<Func<T, object>> expression)
  212. {
  213. return ColumnNames().ToList().IndexOf(CoreUtils.GetFullPropertyName(expression,"."));
  214. }
  215. public Columns(params Expression<Func<T, object?>>[] expressions) : this()
  216. {
  217. foreach (var expression in expressions)
  218. columns.Add(new Column<T>(expression));
  219. }
  220. public Columns(IEnumerable<string> properties) : this()
  221. {
  222. foreach (var property in properties)
  223. columns.Add(new Column<T>(property));
  224. }
  225. public Column<T>[] Items
  226. {
  227. get { return columns != null ? columns.ToArray() : new Column<T>[] { }; }
  228. set
  229. {
  230. columns.Clear();
  231. columns.AddRange(value);
  232. }
  233. }
  234. public int Count => columns.Count;
  235. public IEnumerable<IColumn> GetColumns() => columns;
  236. public bool Any() => columns.Any();
  237. public bool Contains(string column) => Items.Any(x => x.IsEqualTo(column));
  238. public bool Contains(Column<T> column) => Items.Any(x => x.IsEqualTo(column));
  239. public IColumns Add(string column)
  240. {
  241. if(CoreUtils.TryGetProperty(typeof(T), column, out var propertyInfo))
  242. {
  243. if (!propertyInfo.PropertyType.GetInterfaces().Contains(typeof(IEnclosedEntity)) &&
  244. !propertyInfo.PropertyType.GetInterfaces().Any(x => x == typeof(IEntityLink)))
  245. {
  246. var exists = columns.Any(x => x.Expression.ToString().Replace("x.", "").Equals(column));
  247. if (!exists)
  248. columns.Add(new Column<T>(column));
  249. }
  250. }
  251. else
  252. {
  253. var prop = DatabaseSchema.Property(typeof(T), column);
  254. if (prop != null)
  255. {
  256. var exists = columns.Any(x => x.Expression.Equals(prop.Expression()));
  257. if (!exists)
  258. columns.Add(new Column<T>(column));
  259. }
  260. }
  261. return this;
  262. }
  263. public Columns<T> AddSubColumns<TSub>(Expression<Func<T, TSub>> super, Columns<TSub>? sub)
  264. {
  265. sub ??= CoreUtils.GetColumns(sub);
  266. var prefix = CoreUtils.GetFullPropertyName(super, ".") + ".";
  267. foreach(var column in sub.ColumnNames())
  268. {
  269. columns.Add(new Column<T>(prefix + column));
  270. }
  271. return this;
  272. }
  273. public IColumns Add<TEntity>(Expression<Func<TEntity, object?>> expression)
  274. {
  275. return Add(CoreUtils.GetFullPropertyName(expression, "."));
  276. }
  277. public Columns<T> Add(Column<T> column)
  278. {
  279. if(!columns.Any(x => x.Property.Equals(column.Property)))
  280. {
  281. columns.Add(column);
  282. }
  283. return this;
  284. }
  285. public IColumns Add(IColumn column)
  286. {
  287. if (column is Column<T> col)
  288. return Add(col);
  289. return this;
  290. }
  291. public IEnumerable<string> ColumnNames()
  292. {
  293. return Items.Select(c => c.Property);
  294. //List<String> result = new List<string>();
  295. //foreach (var col in Items)
  296. // result.Add(col.Property);
  297. //return result;
  298. }
  299. public Dictionary<String, Type> AsDictionary()
  300. {
  301. Dictionary< String, Type> result = new Dictionary< String, Type>();
  302. foreach (var column in Items)
  303. result[column.Property] = column.Type;
  304. return result;
  305. }
  306. public IColumns DefaultColumns(params ColumnType[] types)
  307. {
  308. return Default(types);
  309. }
  310. public Columns<T> Add(IEnumerable<Column<T>> columns)
  311. {
  312. this.columns.AddRange(columns);
  313. return this;
  314. }
  315. public Columns<T> Add(params string[] columnnames)
  316. {
  317. foreach (var name in columnnames)
  318. Add(name);
  319. return this;
  320. }
  321. public Columns<T> Add(IEnumerable<string> columnnames)
  322. {
  323. foreach (var name in columnnames)
  324. Add(name);
  325. return this;
  326. }
  327. public Columns<T> Add(Expression<Func<T, object?>> expression)
  328. {
  329. try
  330. {
  331. var property = CoreUtils.GetFullPropertyName(expression, ".");
  332. var exists = columns.Any(x => x.Expression.ToString().Replace("x.", "").Equals(property));
  333. if (!exists)
  334. columns.Add(new Column<T>(expression));
  335. }
  336. catch (Exception e)
  337. {
  338. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  339. }
  340. return this;
  341. }
  342. public Columns<T> Add<TType>(Expression<Func<T, TType>> expression)
  343. {
  344. try
  345. {
  346. var property = CoreUtils.GetFullPropertyName(expression, ".");
  347. var exists = columns.Any(x => x.Expression.ToString().Replace("x.", "").Equals(property));
  348. if (!exists)
  349. {
  350. columns.Add(new Column<T>(property));
  351. }
  352. }
  353. catch (Exception e)
  354. {
  355. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  356. }
  357. return this;
  358. }
  359. public Columns<T> Remove(string column)
  360. {
  361. var col = new Column<T>(column);
  362. columns.RemoveAll(x => x.ToString() == col.ToString());
  363. return this;
  364. }
  365. public static explicit operator Columns<T>(Columns<Entity> vs)
  366. {
  367. var result = new Columns<T>();
  368. var items = vs.Items.Cast<Column<T>>().ToArray();
  369. result.Items = items;
  370. //List<Column<T>> cols = new List<Column<T>>();
  371. //foreach (var v in vs.Items)
  372. // cols.Add((Column<T>)v);
  373. //result.Items = cols.ToArray();
  374. return result;
  375. }
  376. public Columns<T> Default(params ColumnType[] types)
  377. {
  378. columns.Clear();
  379. var props = DatabaseSchema.Properties(typeof(T))
  380. .Where(x => x.Setter() != null)
  381. .OrderBy(x => x.PropertySequence()).ToList();
  382. if (types.Contains(ColumnType.All))
  383. {
  384. foreach (var prop in props)
  385. columns.Add(new Column<T>(prop.Name));
  386. return this;
  387. }
  388. else if (types.Contains(ColumnType.DataColumns))
  389. {
  390. foreach(var prop in props)
  391. {
  392. if (prop.IsCalculated)
  393. {
  394. continue;
  395. }
  396. if (prop.HasParentEntityLink())
  397. {
  398. if(prop.Parent?.HasParentEntityLink() == true || !prop.Name.EndsWith(".ID"))
  399. {
  400. continue;
  401. }
  402. }
  403. columns.Add(new Column<T>(prop.Name));
  404. }
  405. if(types.Length == 1)
  406. {
  407. return this;
  408. }
  409. }
  410. if (typeof(T).IsSubclassOf(typeof(Entity)) && !types.Contains(ColumnType.ExcludeID))
  411. columns.Add(new Column<T>("ID"));
  412. for (int iCol = 0; iCol < props.Count; iCol++)
  413. {
  414. var prop = props[iCol];
  415. var bOK = true;
  416. var bIsForeignKey = false;
  417. var bNullEditor = prop.Editor is NullEditor;
  418. if (prop is CustomProperty)
  419. {
  420. if (!types.Any(x => x.Equals(ColumnType.IncludeUserProperties)))
  421. bOK = false;
  422. else
  423. columns.Add(new Column<T>(prop.Name));
  424. }
  425. if (bOK)
  426. if (prop.Name.Contains(".") && !(prop is CustomProperty))
  427. {
  428. var ancestors = prop.Name.Split('.');
  429. var anclevel = 2;
  430. for (var i = 1; i < ancestors.Length; i++)
  431. {
  432. var ancestor = string.Join(".", ancestors.Take(i));
  433. var ancprop = CoreUtils.GetProperty(typeof(T), ancestor);
  434. bNullEditor = bNullEditor || ancprop.GetCustomAttribute<NullEditor>() != null;
  435. if (ancprop.PropertyType.GetInterfaces().Contains(typeof(IEnclosedEntity)))
  436. anclevel++;
  437. else if (ancprop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink)))
  438. {
  439. if (types.Contains(ColumnType.IncludeLinked) || types.Contains(ColumnType.IncludeForeignKeys))
  440. {
  441. if (types.Contains(ColumnType.IncludeNestedLinks) || ancestors.Length <= anclevel)
  442. {
  443. if (prop.Name.EndsWith(".ID") && types.Contains(ColumnType.IncludeForeignKeys))
  444. {
  445. bIsForeignKey = true;
  446. break;
  447. }
  448. if (!types.Contains(ColumnType.IncludeLinked))
  449. {
  450. bOK = false;
  451. break;
  452. }
  453. }
  454. else
  455. {
  456. bOK = false;
  457. break;
  458. }
  459. }
  460. else
  461. {
  462. bOK = false;
  463. break;
  464. }
  465. }
  466. }
  467. }
  468. if (bOK)
  469. {
  470. var visible = prop.Editor != null
  471. ? bNullEditor
  472. ? Visible.Hidden
  473. : prop.Editor.Visible
  474. : Visible.Optional;
  475. var editable = prop.Editor != null
  476. ? bNullEditor
  477. ? Editable.Hidden
  478. : prop.Editor.Editable
  479. : Editable.Enabled;
  480. bOK = (types.Any(x => x.Equals(ColumnType.IncludeForeignKeys)) && bIsForeignKey) ||
  481. (!types.Any(x => x.Equals(ColumnType.ExcludeVisible)) && visible.Equals(Visible.Default)) ||
  482. (types.Any(x => x.Equals(ColumnType.IncludeOptional)) && visible.Equals(Visible.Optional)) ||
  483. (types.Any(x => x.Equals(ColumnType.IncludeEditable)) && editable.ColumnVisible());
  484. }
  485. var property = bOK ? DatabaseSchema.Property(typeof(T), prop.Name) : null;
  486. if (property is StandardProperty)
  487. {
  488. if (bOK && !types.Any(x => x.Equals(ColumnType.IncludeAggregates)))
  489. bOK = CoreUtils.GetProperty(typeof(T), prop.Name).GetCustomAttribute<AggregateAttribute>() == null;
  490. if (bOK && !types.Any(x => x.Equals(ColumnType.IncludeFormulae)))
  491. bOK = CoreUtils.GetProperty(typeof(T), prop.Name).GetCustomAttribute<FormulaAttribute>() == null;
  492. }
  493. if (bOK && !columns.Any(x => string.Equals(x.Property?.ToUpper(), prop.Name?.ToUpper())))
  494. {
  495. if (prop.Editor is LookupEditor le)
  496. {
  497. if (le.OtherColumns != null)
  498. {
  499. var prefix = String.Join(".",prop.Name.Split('.').Reverse().Skip(1).Reverse());
  500. foreach (var col in le.OtherColumns)
  501. {
  502. String newcol = prefix + "." + col.Key;
  503. if (!columns.Any(x => String.Equals(newcol, x.Property)))
  504. columns.Add(new Column<T>(newcol));
  505. }
  506. }
  507. }
  508. if (!columns.Any(x => String.Equals(prop.Name, x.Property)))
  509. columns.Add(new Column<T>(prop.Name));
  510. }
  511. }
  512. return this;
  513. }
  514. #region Binary Serialization
  515. public void SerializeBinary(CoreBinaryWriter writer)
  516. {
  517. writer.Write(columns.Count);
  518. foreach(var column in columns)
  519. {
  520. writer.Write(column.Property);
  521. }
  522. }
  523. public void DeserializeBinary(CoreBinaryReader reader)
  524. {
  525. columns.Clear();
  526. var nColumns = reader.ReadInt32();
  527. for(int i = 0; i < nColumns; ++i)
  528. {
  529. var property = reader.ReadString();
  530. columns.Add(new Column<T>(property));
  531. }
  532. }
  533. #endregion
  534. public IEnumerator<Column<T>> GetEnumerator()
  535. {
  536. return columns.GetEnumerator();
  537. }
  538. IEnumerator IEnumerable.GetEnumerator()
  539. {
  540. return columns.GetEnumerator();
  541. }
  542. }
  543. public static class ColumnsExtensions
  544. {
  545. public static Columns<T> ToColumns<T>(this IEnumerable<Column<T>> columns)
  546. {
  547. return new Columns<T>(columns.ToList());
  548. }
  549. }
  550. public static class ColumnSerialization
  551. {
  552. /// <summary>
  553. /// Inverse of <see cref="Write{T}(CoreBinaryWriter, Columns{T}?)"/>.
  554. /// </summary>
  555. /// <param name="reader"></param>
  556. /// <returns></returns>
  557. public static Columns<T>? ReadColumns<T>(this CoreBinaryReader reader)
  558. {
  559. if (reader.ReadBoolean())
  560. {
  561. var columns = new Columns<T>();
  562. columns.DeserializeBinary(reader);
  563. return columns;
  564. }
  565. return null;
  566. }
  567. /// <summary>
  568. /// Inverse of <see cref="ReadColumns{T}(CoreBinaryReader)"/>.
  569. /// </summary>
  570. /// <param name="filter"></param>
  571. /// <param name="writer"></param>
  572. public static void Write<T>(this CoreBinaryWriter writer, Columns<T>? columns)
  573. {
  574. if (columns is null)
  575. {
  576. writer.Write(false);
  577. }
  578. else
  579. {
  580. writer.Write(true);
  581. columns.SerializeBinary(writer);
  582. }
  583. }
  584. }
  585. public class ColumnJsonConverter : JsonConverter
  586. {
  587. public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
  588. {
  589. if(value is null)
  590. {
  591. writer.WriteNull();
  592. return;
  593. }
  594. var property = (CoreUtils.GetPropertyValue(value, "Expression") as Expression)
  595. ?? throw new Exception("'Column.Expression' may not be null");
  596. var prop = CoreUtils.ExpressionToString(value.GetType().GenericTypeArguments[0], property, true);
  597. var name = CoreUtils.GetPropertyValue(value, "Property") as string;
  598. writer.WriteStartObject();
  599. writer.WritePropertyName("$type");
  600. writer.WriteValue(value.GetType().FullName);
  601. writer.WritePropertyName("Expression");
  602. writer.WriteValue(prop);
  603. writer.WritePropertyName("Property");
  604. writer.WriteValue(name);
  605. writer.WriteEndObject();
  606. }
  607. public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
  608. {
  609. if (reader.TokenType == JsonToken.Null)
  610. return null;
  611. var data = new Dictionary<string, object>();
  612. while (reader.TokenType != JsonToken.EndObject && reader.Read())
  613. if (reader.Value != null)
  614. {
  615. var key = reader.Value.ToString();
  616. reader.Read();
  617. if (String.Equals(key, "$type"))
  618. objectType = Type.GetType(reader.Value.ToString()) ?? objectType;
  619. else
  620. data[key] = reader.Value;
  621. }
  622. var prop = data["Property"].ToString();
  623. var result = Activator.CreateInstance(objectType, prop);
  624. return result;
  625. }
  626. public override bool CanConvert(Type objectType)
  627. {
  628. if (objectType.IsConstructedGenericType)
  629. {
  630. var ot = objectType.GetGenericTypeDefinition();
  631. var tt = typeof(Column<>);
  632. if (ot == tt)
  633. return true;
  634. }
  635. return false;
  636. }
  637. }
  638. }