private static ODataValue GetComplexValue(InstanceAnnotation entryAnnotation, object annotation, IEdmModel model, ODataComplexTypeSerializer complexSerializer, ODataSerializerContext serializerContext) { Contract.Requires(entryAnnotation != null); Contract.Requires(annotation != null); Contract.Requires(model != null); Contract.Requires(complexSerializer != null); Contract.Requires(serializerContext != null); var complexType = (IEdmComplexType)model.FindDeclaredType(entryAnnotation.AnnotationTypeName); if (complexType == null) { return(null); } var typeRef = new EdmComplexTypeReference(complexType, entryAnnotation.IsNullable); if (!entryAnnotation.IsCollection) { return(complexSerializer.CreateODataComplexValue(annotation, typeRef, serializerContext)); } var typeName = Invariant($"Collection({typeRef.FullName()})"); var items = GetComplexValues(annotation, complexSerializer, typeRef, serializerContext); return(new ODataCollectionValue() { Items = items, TypeName = typeName }); }
private static IEnumerable <ODataComplexValue> GetComplexValues(object value, ODataComplexTypeSerializer complexSerializer, IEdmComplexTypeReference complexType, ODataSerializerContext serializerContext) { Contract.Requires(complexSerializer != null); Contract.Requires(complexType != null); Contract.Requires(serializerContext != null); var items = value as System.Collections.IEnumerable; if (items == null) { yield break; } foreach (var graph in items) { yield return(complexSerializer.CreateODataComplexValue(graph, complexType, serializerContext)); } }