2 using System.Collections.Generic;
4 using System.Reflection;
7 using MonoTests.DataSource;
8 using MonoTests.ModelProviders;
10 namespace MonoTests.Common
12 public class TestDataColumn<DataType> : DynamicDataColumn
14 public TestDataColumn (MemberInfo member)
17 throw new ArgumentNullException ("member");
19 string name = this.Name = member.Name;
20 switch (member.MemberType) {
21 case MemberTypes.Field:
22 var fi = member as FieldInfo;
23 this.DataType = fi.FieldType;
26 case MemberTypes.Property:
27 var pi = member as PropertyInfo;
28 this.DataType = pi.PropertyType;
32 throw new ArgumentException ("Member information must refer to either a field or a property.", "member");
35 this.PrimaryKey = name.StartsWith ("PrimaryKeyColumn", StringComparison.Ordinal);
36 this.CustomProperty = name.StartsWith ("CustomProperty", StringComparison.Ordinal);
37 this.Generated = name.StartsWith ("GeneratedColumn", StringComparison.Ordinal);
39 object[] attrs = member.GetCustomAttributes (true);
40 DynamicDataAssociationAttribute associationAttr;
43 associationAttr = attrs.OfType<DynamicDataAssociationAttribute> ().First<DynamicDataAssociationAttribute> ();
44 } catch (InvalidOperationException) {
45 associationAttr = null;
48 if (associationAttr != null) {
49 AssociatedTo = associationAttr.ColumnName;
50 AssociationDirection = associationAttr.Direction;
53 DynamicDataSortableAttribute sortableAttr;
56 sortableAttr = attrs.OfType<DynamicDataSortableAttribute> ().First<DynamicDataSortableAttribute> ();
57 } catch (InvalidOperationException) {
61 if (sortableAttr != null)
62 Sortable = sortableAttr.Sortable;