protected virtual Object PostProcessCacheResult(IList <IObjRef> objRefs, IList <Object> cacheResult, Type expectedType, IServiceResult serviceResult, Object[] originalArgs, Attribute annotation) { int cacheResultSize = cacheResult != null ? cacheResult.Count : objRefs.Count; if (typeof(IEnumerable).IsAssignableFrom(expectedType)) { Object targetCollection = ListUtil.CreateCollectionOfType(expectedType); MethodInfo addMethod = targetCollection.GetType().GetMethod("Add"); Object[] parameters = new Object[1]; if (cacheResult != null) { for (int a = 0; a < cacheResultSize; a++) { parameters[0] = cacheResult[a]; addMethod.Invoke(targetCollection, parameters); } } else { for (int a = 0; a < cacheResultSize; a++) { parameters[0] = objRefs[a]; addMethod.Invoke(targetCollection, parameters); } } return(targetCollection); } else if (expectedType.IsArray) { Array array = Array.CreateInstance(expectedType.GetElementType(), cacheResultSize); if (cacheResult != null) { for (int a = 0; a < cacheResultSize; a++) { array.SetValue(cacheResult[a], a); } } else { for (int a = 0; a < cacheResultSize; a++) { array.SetValue(objRefs[a], a); } } return(array); } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(expectedType, true); if (metaData != null) { // It is a simple entity which can be returned directly if (cacheResultSize == 0) { return(null); } else if (cacheResultSize == 1) { return(cacheResult != null ? cacheResult[0] : objRefs[0]); } } Object additionalInformation = serviceResult != null ? serviceResult.AdditionalInformation : null; if (additionalInformation == null) { throw new Exception("Can not convert list of " + cacheResultSize + " results from cache to type " + expectedType.FullName); } IServiceResultProcessor serviceResultProcessor = ServiceResultProcessorRegistry.GetServiceResultProcessor(expectedType); return(serviceResultProcessor.ProcessServiceResult(additionalInformation, objRefs, cacheResult, expectedType, originalArgs, annotation)); }
public void UnregisterServiceResultProcessor(IServiceResultProcessor serviceResultProcessor, Type returnType) { extensions.Unregister(serviceResultProcessor, returnType); }