public override object Eval(object row, object context) { object component = context; if (this.parent != null) { component = this.parent.Eval(row, context); } else if ("Fields" == this.name) { return(row); } if (component == null) { return((object)null); } IDataItem dataItem = row as IDataItem; if (dataItem != null) { return(dataItem[this.name]); } PropertyDescriptor propertyDescriptor = (PropertyDescriptor)null; Type type = component.GetType(); if (!this.properties.TryGetValue(type, out propertyDescriptor)) { PropertyDescriptorCollection descriptorCollection = !(component is IDataDescriptor) ? TypeDescriptor.GetProperties(component) : ((IDataDescriptor)component).GetProperties(); if (descriptorCollection != null && descriptorCollection.Count > 0) { bool ignoreCase = !(context is ExpressionContext) || !((ExpressionContext)context).CaseSensitive; this.properties[type] = propertyDescriptor = descriptorCollection.Find(this.name, ignoreCase); } } if (propertyDescriptor != null) { return(propertyDescriptor.GetValue(component)); } throw InvalidExpressionException.UndefinedObject(this.name); }
public override object Eval(object row, object context) { object o = context; if (null != this.parent) { o = this.parent.Eval(row, context); } else if (NameNode.FildsObject == this.name) { return(row); } if (null == o) { return(null); } IDataItem map = row as IDataItem; //changed from IDataMap if (null != map) { return(map[this.name]); //// The "old" field notation when there was no Fields global object //// and fields was referenced by thier name only; ex. =ProductCategory //// instead of =Fields.ProductCategory //try //{ // return map[this.name]; //} //catch (Exception) //{ // // hide this exception; UndefinedObject will be raised after that //} } PropertyDescriptor property = null; Type objectType = o.GetType(); // Sometimes one expression may be evaluated on a different // type of data. Because of the caching of the expression trees // two expression (ex. the report's filters and a textbox // in the group header) may result in a single exp tree. The different // input data (same ex. - the filter operates with DataObject while // for the group sections is passed DataGroup objects) will result // in a different PropertyDescriptor, so we need to chache them // per object type. if (!this.properties.TryGetValue(objectType, out property)) { PropertyDescriptorCollection collection = null; if (o is IDataDescriptor) { collection = ((IDataDescriptor)o).GetProperties(); } else { collection = TypeDescriptor.GetProperties(o); } if (null != collection && collection.Count > 0) { this.properties[objectType] = property = collection.Find(this.name, true); } } if (null != property) { return(property.GetValue(o)); } throw InvalidExpressionException.UndefinedObject(this.name); }