Skip to content

Commit

Permalink
fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio committed Jul 18, 2022
1 parent dfab7f1 commit 2862c29
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 667 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface IODataInstanceAnnotationContainer
/// Get All Annotations from CLR Type
/// </summary>
/// <returns>Dictionary of string(annotation name) and object value(annotation value)</returns>
IDictionary<string,object> GetResourceAnnotations();
IDictionary<string, object> GetResourceAnnotations();

/// <summary>
/// Get all Annotations for a Property
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.AspNet.OData.Shared/Common/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ internal static ArgumentNullException PropertyNull()
/// Creates an <see cref="ArgumentException"/> with a default message.
/// </summary>
/// <returns>The logged <see cref="Exception"/>.</returns>
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
internal static ArgumentException PropertyNullOrWhiteSpace()
{
return new ArgumentException(CommonWebApiResources.PropertyNullOrWhiteSpace, "value");
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/Microsoft.AspNet.OData.Shared/Common/SRResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -988,4 +988,22 @@
<data name="ShouldHaveNavigationPropertyInNavigationExpandPath" xml:space="preserve">
<value>A navigation property expand path should have navigation property in the path.</value>
</data>
<data name="ResourcesShouldbePresent" xml:space="preserve">
<value>ResourceSetWrapper should have ResourceWrappers in it</value>
</data>
<data name="ResourceSetWrapperSupported" xml:space="preserve">
<value>Can only add ResourceWrapper to ResourceSetWrapper</value>
</data>
<data name="ChangedObjectTypeMismatch" xml:space="preserve">
<value>Cannot use Changed Object of type '{0}' on an entity of type '{1}'.</value>
</data>
<data name="DataModificationException" xml:space="preserve">
<value>Core.DataModificationException</value>
</data>
<data name="ContentID" xml:space="preserve">
<value>Core.ContentID</value>
</data>
<data name="DeltaLinkNotSupported" xml:space="preserve">
<value>DeltaLinks are not supported</value>
</data>
</root>
275 changes: 137 additions & 138 deletions src/Microsoft.AspNet.OData.Shared/DeltaOfTStructuralType.cs

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/Microsoft.AspNet.OData.Shared/EdmStructuredObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.OData.Common;
using Microsoft.AspNet.OData.Formatter;
using Microsoft.OData.Edm;
Expand Down Expand Up @@ -224,8 +225,15 @@ internal static object GetDefaultValue(IEdmTypeReference propertyType)
if (propertyType.IsPrimitive() ||
(isCollection && propertyType.AsCollection().ElementType().IsPrimitive()))
{

bool hasDefaultConstructor = (!clrType.IsClass) || clrType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).
Any(x => x.GetParameters().Count() == 0);

// primitive or primitive collection
return Activator.CreateInstance(clrType);
if (hasDefaultConstructor)
{
return Activator.CreateInstance(clrType);
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.OData.Shared/EdmTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static bool IsDeltaFeed(this IEdmType type)
{
throw Error.ArgumentNull("type");
}
return (type.GetType() == typeof(EdmDeltaCollectionType));
return (type.GetType() == typeof(EdmDeltaCollectionType)) || (type.GetType() == typeof(IDeltaSet));
}

/// <summary>
/// Method to determine whether the current Edm object is a Delta Entry
/// </summary>
Expand Down
25 changes: 20 additions & 5 deletions src/Microsoft.AspNet.OData.Shared/Formatter/EdmLibHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
#if NETFX // System.Data.Linq.Binary is only supported in the AspNet version.
using System.Data.Linq;
Expand Down Expand Up @@ -134,13 +135,23 @@ private static IEdmType GetEdmType(IEdmModel edmModel, Type clrType, bool testCo
{
if (testCollections)
{
Type entityType;

if (IsDeltaSetWrapper(clrType, out entityType))
{
IEdmType elementType = GetEdmType(edmModel, entityType, testCollections: false);
if (elementType != null)
{
return new EdmCollectionType(elementType.ToEdmTypeReference(IsNullable(entityType)));
}
}

Type enumerableOfT = ExtractGenericInterface(clrType, typeof(IEnumerable<>));
if (enumerableOfT != null)
{
Type elementClrType = enumerableOfT.GetGenericArguments()[0];

// IEnumerable<SelectExpandWrapper<T>> is a collection of T.
Type entityType;
// IEnumerable<SelectExpandWrapper<T>> is a collection of T.
if (IsSelectExpandWrapper(elementClrType, out entityType))
{
elementClrType = entityType;
Expand Down Expand Up @@ -790,7 +801,7 @@ public static PropertyInfo GetDynamicPropertyDictionary(IEdmStructuredType edmTy
if (edmModel == null)
{
throw Error.ArgumentNull("edmModel");
}
}

DynamicPropertyDictionaryAnnotation annotation =
edmModel.GetAnnotationValue<DynamicPropertyDictionaryAnnotation>(edmType);
Expand Down Expand Up @@ -977,14 +988,17 @@ internal static IEdmTypeReference GetExpectedPayloadType(Type type, ODataPath pa
{
IEdmTypeReference expectedPayloadType = null;

if (typeof(IEdmObject).IsAssignableFrom(type))
if (typeof(IEdmObject).IsAssignableFrom(type) || typeof(IDeltaSet).IsAssignableFrom(type))
{
// typeless mode. figure out the expected payload type from the OData Path.
IEdmType edmType = path.EdmType;
if (edmType != null)
{
expectedPayloadType = EdmLibHelpers.ToEdmTypeReference(edmType, isNullable: false);
if (expectedPayloadType.TypeKind() == EdmTypeKind.Collection)

//This loop should execute only if its not a type of edmchangedobjectcollection, In case of edmchangedobjectcollection,
//Expectedpayloadtype should not be of elementytype, but of collection.
if (expectedPayloadType.TypeKind() == EdmTypeKind.Collection && !(typeof(ICollection).IsAssignableFrom(type) || typeof(IDeltaSet).IsAssignableFrom(type)))
{
IEdmTypeReference elementType = expectedPayloadType.AsCollection().ElementType();
if (elementType.IsEntity())
Expand Down Expand Up @@ -1117,6 +1131,7 @@ private static IEdmPrimitiveType GetPrimitiveType(EdmPrimitiveTypeKind primitive
}

private static bool IsSelectExpandWrapper(Type type, out Type entityType) => IsTypeWrapper(typeof(SelectExpandWrapper<>), type, out entityType);
private static bool IsDeltaSetWrapper(Type type, out Type entityType) => IsTypeWrapper(typeof(DeltaSet<>), type, out entityType);

internal static bool IsComputeWrapper(Type type, out Type entityType) => IsTypeWrapper(typeof(ComputeWrapper<>), type, out entityType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ internal static string SelectActionImpl(ODataPath odataPath, IWebApiControllerCo
"Post" + entitySet.EntityType().Name,
"Post");
}
else if (ODataRequestMethod.Patch == controllerContext.Request.Method)
{
// e.g. Try PatchCustomers first, then fall back to Patch action name
return actionMap.FindMatchingAction(
"Patch" + entitySet.Name,
"Patch");
}
}
else if (odataPath.PathTemplate == "~/entityset/$count" &&
ODataRequestMethod.Get == controllerContext.Request.GetRequestMethodOrPreflightMethod())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ internal static string SelectActionImpl(ODataPath odataPath, IWebApiControllerCo
return null;
}

// It is not valid to *Put/Patch" to any collection-valued navigation property.
// It is not valid to *Put" to any collection-valued navigation property.
if (navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many &&
(ODataRequestMethod.Put == method || ODataRequestMethod.Patch == method))
ODataRequestMethod.Put == method)
{
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.AspNet.OData.Shared/Routing/ODataPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,10 @@ public override string ToString()
/// Gets the ODL path.
/// </summary>
public Semantic.ODataPath Path { get; internal set; }

internal IList<ODataPathSegment> SegmentList
{
get { return _segments.ToList(); }
}
}
}
Loading

0 comments on commit 2862c29

Please sign in to comment.