public override EvaluatorContext GetNestedContext(object source, string propertyPath) { object nestedObject = GetPropertyValue(source, propertyPath, false); if(nestedObject == null) return null; #if !SL IList list = nestedObject as IList; if(list == null) { IListSource listSource = nestedObject as IListSource; if(listSource != null) { if(listSource.ContainsListCollection) list = listSource.GetList(); } } object nestedSource; PropertyDescriptorCollection pdc; if(list != null && list is ITypedList) { switch(list.Count) { case 0: return null; default: throw new ArgumentException("single row expected at '" + propertyPath + "', provided: " + list.Count.ToString()); case 1: break; } nestedSource = list[0]; pdc = ((ITypedList)list).GetItemProperties(null); } else if(nestedObject is ITypedList) { nestedSource = nestedObject; pdc = ((ITypedList)nestedObject).GetItemProperties(null); } else { nestedSource = nestedObject; pdc = null; } EvaluatorContextDescriptor descriptor = new EvaluatorContextDescriptorDefault(pdc, nestedSource.GetType()); return new EvaluatorContext(descriptor, nestedSource); #else EvaluatorContextDescriptor descriptor = new EvaluatorContextDescriptorDefault(nestedObject.GetType()); return new EvaluatorContext(descriptor, nestedObject); #endif }
public override IEnumerable GetCollectionContexts(object source, string collectionName) { object collectionSrc = GetPropertyValue(source, collectionName, false); if(collectionSrc == null) return null; IList list = collectionSrc as IList; #if !SL if(list == null) { IListSource listSource = collectionSrc as IListSource; if(listSource != null) list = listSource.GetList(); } if(list == null) throw new ArgumentException("not a collection: " + collectionName); EvaluatorContextDescriptor descriptor = null; ITypedList pdcSrc = list as ITypedList; if(pdcSrc != null) { descriptor = new EvaluatorContextDescriptorDefault(pdcSrc.GetItemProperties(null)); } return new CollectionContexts(descriptor, list); #else if(list == null) throw new ArgumentException("not a collection: " + collectionName); return new CollectionContexts(null, list); #endif }