Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle untyped collections in context's getedmtype method #1607

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.OData.Common;
using Microsoft.AspNet.OData.Interfaces;
using Microsoft.OData.Edm;
Expand Down Expand Up @@ -161,6 +163,29 @@ internal IEdmTypeReference GetEdmType(object instance, Type type)
typeof(IEdmObject).Name);
}
}
else if (typeof(IEnumerable).IsAssignableFrom(type) &&
typeof(IEdmObject).IsAssignableFrom(type.GetGenericArguments().FirstOrDefault()))
Copy link
Member

@xuzhg xuzhg Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Web API recommends to use "EdmEnittyObjectCollection, EdmComplexObjectCollection, EdmEnumObjectCollection" for the collection. #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my approach is consistent with the approaches used in this class and others in webapi.


In reply to: 215081845 [](ancestors = 215081845)

{
edmType = null;
IEnumerable list = instance as IEnumerable;
if (list != null)
{
IEnumerator enumerator = list.GetEnumerator();
if (enumerator.MoveNext())
{
IEdmObject edo = (IEdmObject)enumerator.Current;
IEdmCollectionType edmCollection = new EdmCollectionType(edo.GetEdmType());
edmType = new EdmCollectionTypeReference(edmCollection);
}
}

if (edmType == null)
{
Type innerType = type.GetGenericArguments().FirstOrDefault();
string innerTypeName = innerType == null ? null : innerType.Name;
throw Error.InvalidOperation(SRResources.EdmTypeCannotBeNull, type.FullName, innerTypeName);
}
}
else
{
if (Model == null)
Expand Down