protected string GetUnderlyingObjectText(object rowObject, OLVColumn column) { if (rowObject == null || column == null) { return(null); } // This code works solely because we do not use aspect getters. var cellValue = column.GetAspectByName(rowObject); var cellInfo = rowObject.GetType().GetField(column.AspectName); if (cellInfo.FieldType == typeof(string)) { return(cellInfo.GetValue(rowObject) as string); } if (cellInfo.GetCustomAttribute(typeof(StoragePresenceAttribute), false) == null) { return(null); } var result = (cellInfo.GetValue(rowObject) as Array).Cast <object>().ToArray(); return(@"[ " + String.Join(", ", result) + @" ]"); }
/// <summary> /// Generate aspect getters and putters for any columns that are missing them (and for which we have /// enough information to actually generate a getter) /// </summary> protected virtual void CreateMissingAspectGettersAndPutters() { foreach (OLVColumn x in this.ListView.AllColumns) { OLVColumn column = x; // stack based variable accessible from closures if (column.AspectGetter == null && !String.IsNullOrEmpty(column.AspectName)) { column.AspectGetter = delegate(object row) { // In most cases, rows will be DataRowView objects DataRowView drv = row as DataRowView; if (drv == null) { return(column.GetAspectByName(row)); } return((drv.Row.RowState == DataRowState.Detached) ? null : drv[column.AspectName]); }; } if (column.IsEditable && column.AspectPutter == null && !String.IsNullOrEmpty(column.AspectName)) { column.AspectPutter = delegate(object row, object newValue) { // In most cases, rows will be DataRowView objects DataRowView drv = row as DataRowView; if (drv == null) { column.PutAspectByName(row, newValue); } else { if (drv.Row.RowState != DataRowState.Detached) { drv[column.AspectName] = newValue; } } }; } } }
/// <summary> /// Generate aspect getters and putters for any columns that are missing them (and for which we have /// enough information to actually generate a getter) /// </summary> protected virtual void CreateMissingAspectGettersAndPutters() { for (int i = 0; i < this.Columns.Count; i++) { OLVColumn column = this.GetColumn(i); if (column.AspectGetter == null && !String.IsNullOrEmpty(column.AspectName)) { column.AspectGetter = delegate(object row) { // In most cases, rows will be DataRowView objects DataRowView drv = row as DataRowView; if (drv != null) { return(drv[column.AspectName]); } else { return(column.GetAspectByName(row)); } }; } if (column.IsEditable && column.AspectPutter == null && !String.IsNullOrEmpty(column.AspectName)) { column.AspectPutter = delegate(object row, object newValue) { // In most cases, rows will be DataRowView objects DataRowView drv = row as DataRowView; if (drv != null) { drv[column.AspectName] = newValue; } else { column.PutAspectByName(row, newValue); } }; } } }
protected string GetUnderlyingObjectText(object rowObject, OLVColumn column) { if (rowObject == null || column == null) return null; // This code works solely because we do not use aspect getters. var cellValue = column.GetAspectByName(rowObject); var cellInfo = rowObject.GetType().GetField(column.AspectName); if (cellInfo.FieldType == typeof(string)) return cellInfo.GetValue(rowObject) as string; if (cellInfo.GetCustomAttribute(typeof(StoragePresenceAttribute), false) == null) return null; var result = (cellInfo.GetValue(rowObject) as Array).Cast<object>().ToArray(); return @"[ " + String.Join(", ", result) + @" ]"; }