Skip to content

Commit

Permalink
Fixes the build warning.
Browse files Browse the repository at this point in the history
1) Change EntityType() to EntityType
2) Skip the return value for RequestDelegate
3) Obsolete the ReadUntypedAsString
  • Loading branch information
xuzhg committed Aug 27, 2024
1 parent a45702f commit 32172ec
Show file tree
Hide file tree
Showing 45 changed files with 108 additions and 105 deletions.
2 changes: 1 addition & 1 deletion sample/BenchmarkServer/BenchmarkServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override bool TryTranslate(ODataTemplateTranslateContext context)
if (edmEntitySet != null)
{
EntitySetSegment entitySet = new EntitySetSegment(edmEntitySet);
IEdmEntityType entityType = entitySet.EntitySet.EntityType();
IEdmEntityType entityType = entitySet.EntitySet.EntityType;

IEdmProperty keyProperty = entityType.Key().First();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static IServiceCollection AddDefaultWebApiServices(this IServiceCollectio

// ReaderSettings and WriterSettings are registered as prototype services.
// There will be a copy (if it is accessed) of each prototype for each request.
#pragma warning disable CS0618 // ReadUntypedAsString is obsolete in ODL 8.
services.AddSingleton(new ODataMessageReaderSettings
{
EnableMessageStreamDisposal = false,
Expand All @@ -50,6 +51,7 @@ public static IServiceCollection AddDefaultWebApiServices(this IServiceCollectio
EnablePropertyNameCaseInsensitive = true,
EnableReadingODataAnnotationWithoutPrefix = true
});
#pragma warning restore CS0618 // Type or member is obsolete

services.AddSingleton(new ODataMessageWriterSettings
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.OData/Batch/ODataBatchContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ODataBatchContent(IEnumerable<ODataBatchResponseItem> responses, IService
Headers = new HeaderDictionary();
Headers["Content-Type"] = contentType;
ODataVersion version = _writerSettings.Version ?? ODataVersionConstraint.DefaultODataVersion;
Headers.Add(ODataVersionConstraint.ODataServiceVersionHeader, ODataUtils.ODataVersionToString(version));
Headers.Append(ODataVersionConstraint.ODataServiceVersionHeader, ODataUtils.ODataVersionToString(version));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private static HttpContext CreateHttpContext(HttpContext originalContext)
string preferencesToInherit = GetPreferencesToInheritFromBatch(header.Value);
if (!string.IsNullOrEmpty(preferencesToInherit))
{
context.Request.Headers.Add(header.Key, preferencesToInherit);
context.Request.Headers.Append(header.Key, preferencesToInherit);
}
}
// do not copy already existing headers, such as Cookie
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.AspNetCore.OData/Edm/ContainmentPathBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ private static IEdmEntityType GetTargetEntityType(ODataPathSegment segment)
EntitySetSegment entitySetSegment = segment as EntitySetSegment;
if (entitySetSegment != null)
{
return entitySetSegment.EntitySet.EntityType();
return entitySetSegment.EntitySet.EntityType;
}

SingletonSegment singletonSegment = segment as SingletonSegment;
if (singletonSegment != null)
{
return singletonSegment.Singleton.EntityType();
return singletonSegment.Singleton.EntityType;
}

NavigationPropertySegment navigationPropertySegment = segment as NavigationPropertySegment;
if (navigationPropertySegment != null)
{
return navigationPropertySegment.NavigationSource.EntityType();
return navigationPropertySegment.NavigationSource.EntityType;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static IEnumerable<IEdmStructuralProperty> GetConcurrencyProperties(this
}

IList<IEdmStructuralProperty> results = new List<IEdmStructuralProperty>();
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
IEdmVocabularyAnnotatable annotatable = navigationSource as IEdmVocabularyAnnotatable;
if (annotatable != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public NavigationSourceLinkBuilderAnnotation(IEdmNavigationSource navigationSour
throw Error.ArgumentNull(nameof(model));
}

IEdmEntityType elementType = navigationSource.EntityType();
IEdmEntityType elementType = navigationSource.EntityType;
IEnumerable<IEdmEntityType> derivedTypes = model.FindAllDerivedTypes(elementType).Cast<IEdmEntityType>();

// Add navigation link builders for all navigation properties of entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Uri GenerateSelfLink(this ResourceContext resourceContext, bool in

IList<ODataPathSegment> idLinkPathSegments = resourceContext.GenerateBaseODataPathSegments();

bool isSameType = resourceContext.StructuredType == resourceContext.NavigationSource.EntityType();
bool isSameType = resourceContext.StructuredType == resourceContext.NavigationSource.EntityType;
if (includeCast && !isSameType)
{
idLinkPathSegments.Add(new TypeSegment(resourceContext.StructuredType, navigationSource: null));
Expand Down Expand Up @@ -257,7 +257,7 @@ internal static Uri GenerateActionLink(this ResourceContext resourceContext,
IList<ODataPathSegment> actionPathSegments = resourceContext.GenerateBaseODataPathSegments();

// generate link with cast if the navigation source doesn't match the entity type the action is bound to.
if (resourceContext.NavigationSource.EntityType() != bindingParameterType.Definition)
if (resourceContext.NavigationSource.EntityType != bindingParameterType.Definition)
{
actionPathSegments.Add(new TypeSegment((IEdmEntityType)bindingParameterType.Definition, null));
// entity set can be null
Expand Down Expand Up @@ -305,7 +305,7 @@ internal static Uri GenerateFunctionLink(this ResourceContext resourceContext,
IList<ODataPathSegment> functionPathSegments = resourceContext.GenerateBaseODataPathSegments();

// generate link with cast if the navigation source type doesn't match the entity type the function is bound to.
if (resourceContext.NavigationSource.EntityType() != bindingParameterType.Definition)
if (resourceContext.NavigationSource.EntityType != bindingParameterType.Definition)
{
functionPathSegments.Add(new TypeSegment(bindingParameterType.Definition, null));
}
Expand Down Expand Up @@ -443,7 +443,7 @@ private static void GenerateBaseODataPathSegments(
{
EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
IEdmEntitySet entitySet = new EdmEntitySet(container, navigationSource.Name,
navigationSource.EntityType());
navigationSource.EntityType);
odataPath.Add(new EntitySetSegment(entitySet));
}
else
Expand Down Expand Up @@ -487,7 +487,7 @@ private static IList<ODataPathSegment> GenerateContainmentODataPathSegments(this
if (currentResourceContext.NavigationSource is IEdmContainedEntitySet containedEntitySet)
{
// Type-cast segment for the expanded resource that is passed into the method is added by the caller
if (currentResourceContext != resourceContext && currentResourceContext.StructuredType != containedEntitySet.EntityType())
if (currentResourceContext != resourceContext && currentResourceContext.StructuredType != containedEntitySet.EntityType)
{
navigationPathSegments.Add(new TypeSegment(currentResourceContext.StructuredType, currentResourceContext.NavigationSource));
}
Expand All @@ -506,7 +506,7 @@ private static IList<ODataPathSegment> GenerateContainmentODataPathSegments(this
else if (currentResourceContext.NavigationSource is IEdmEntitySet entitySet)
{
// We will get here if there's a non-contained entity set on the $expand expression
if (currentResourceContext.StructuredType != entitySet.EntityType())
if (currentResourceContext.StructuredType != entitySet.EntityType)
{
navigationPathSegments.Add(new TypeSegment(currentResourceContext.StructuredType, currentResourceContext.NavigationSource));
}
Expand All @@ -527,7 +527,7 @@ private static IList<ODataPathSegment> GenerateContainmentODataPathSegments(this
else if (currentResourceContext.NavigationSource is IEdmSingleton singleton)
{
// We will get here if there's a singleton on the $expand expression
if (currentResourceContext.StructuredType != singleton.EntityType())
if (currentResourceContext.StructuredType != singleton.EntityType)
{
navigationPathSegments.Add(new TypeSegment(currentResourceContext.StructuredType, currentResourceContext.NavigationSource));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public virtual ODataResource CreateResource(SelectExpandNode selectExpandNode, R
ODataResourceSerializationInfo serializationInfo = new ODataResourceSerializationInfo();
serializationInfo.NavigationSourceName = resourceContext.NavigationSource.Name;
serializationInfo.NavigationSourceKind = resourceContext.NavigationSource.NavigationSourceKind();
IEdmEntityType sourceType = resourceContext.NavigationSource.EntityType();
IEdmEntityType sourceType = resourceContext.NavigationSource.EntityType;
if (sourceType != null)
{
serializationInfo.NavigationSourceEntityTypeName = sourceType.Name;
Expand Down Expand Up @@ -1708,7 +1708,7 @@ private static IEdmStructuredType GetODataPathType(ODataSerializerContext serial
// figure out the type from the navigation source
if (serializerContext.NavigationSource != null)
{
edmType = serializerContext.NavigationSource.EntityType();
edmType = serializerContext.NavigationSource.EntityType;
if (edmType.TypeKind == EdmTypeKind.Collection)
{
edmType = (edmType as IEdmCollectionType).ElementType.Definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8668,7 +8668,7 @@
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.GetODataQueryContext(System.Object,System.Linq.IQueryable,Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor,Microsoft.AspNetCore.Http.HttpRequest)">
<summary>
Get the ODaya query context.
Get the OData query context.
</summary>
<param name="responseValue">The response value.</param>
<param name="singleResultCollection">The content as SingleResult.Queryable.</param>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.OData/Query/ODataQueryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static IEdmNavigationSource GetNavigationSource(IEdmModel model, IEdmTyp
}

List<IEdmEntitySet> matchedNavigationSources =
entityContainer.EntitySets().Where(e => e.EntityType() == elementType).ToList();
entityContainer.EntitySets().Where(e => e.EntityType == elementType).ToList();

return (matchedNavigationSources.Count != 1) ? null : matchedNavigationSources[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private void GetAutoSelectExpandItems(IEdmEntityType baseEntityType, IEdmModel m
}

GetAutoSelectExpandItems(
currentEdmNavigationSource.EntityType(),
currentEdmNavigationSource.EntityType,
model,
item.NavigationSource,
true,
Expand Down Expand Up @@ -577,7 +577,7 @@ private ExpandedNavigationSelectItem ProcessLevels(
SelectExpandClause selectExpandClause = null;
bool levelsEncounteredInInnerExpand = false;
bool isMaxLevelInInnerExpand = false;
var entityType = expandItem.NavigationSource.EntityType();
var entityType = expandItem.NavigationSource.EntityType;
IEdmNavigationProperty navigationProperty =
(expandItem.PathToNavigationProperty.LastSegment as NavigationPropertySegment).NavigationProperty;
ModelBoundQuerySettings nestQuerySettings = Context.Model.GetModelBoundQuerySettings(navigationProperty, navigationProperty.ToEntityType());
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.AspNetCore.OData/Results/ResultHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void AddEntityId(HttpResponse response, Func<Uri> entityId)
{
if (response.StatusCode == (int)HttpStatusCode.NoContent)
{
response.Headers.Add(EntityIdHeaderName, entityId().AbsoluteUri);
response.Headers.Append(EntityIdHeaderName, entityId().AbsoluteUri);
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ private static Uri GenerateContainmentODataPathSegments(ResourceContext resource
if (entitySet == null)
{
EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
entitySet = new EdmEntitySet(container, resourceContext.NavigationSource.Name, resourceContext.NavigationSource.EntityType());
entitySet = new EdmEntitySet(container, resourceContext.NavigationSource.Name, resourceContext.NavigationSource.EntityType);
}

odataPath.Add(new EntitySetSegment(entitySet));
Expand All @@ -157,7 +157,7 @@ private static Uri GenerateContainmentODataPathSegments(ResourceContext resource

if (!isEntityId)
{
bool isSameType = resourceContext.StructuredType == resourceContext.NavigationSource.EntityType();
bool isSameType = resourceContext.StructuredType == resourceContext.NavigationSource.EntityType;
if (!isSameType)
{
odataPath.Add(new TypeSegment(resourceContext.StructuredType, resourceContext.NavigationSource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override bool AppliesToAction(ODataControllerActionContext context)
}

IEdmNavigationSource navigationSource = context.NavigationSource;
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;

// action should have the [HttpPost]
if (!context.Action.Attributes.Any(a => a is HttpPostAttribute))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public virtual bool AppliesToAction(ODataControllerActionContext context)

ActionModel action = context.Action;
IEdmEntitySet entitySet = context.EntitySet;
IEdmEntityType entityType = entitySet.EntityType();
IEdmEntityType entityType = entitySet.EntityType;

// if the action has no key parameter, skip it.
if (!action.HasODataKeyParameter(entityType, context.Options?.RouteOptions?.EnablePropertyNameCaseInsensitive ?? false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public virtual bool AppliesToAction(ODataControllerActionContext context)

ActionModel action = context.Action;
IEdmEntitySet entitySet = context.EntitySet;
IEdmEntityType entityType = entitySet.EntityType();
IEdmEntityType entityType = entitySet.EntityType;

// if the action has key parameter, skip it.
if (action.HasODataKeyParameter(entityType, context.Options?.RouteOptions?.EnablePropertyNameCaseInsensitive ?? false))
Expand Down Expand Up @@ -110,7 +110,7 @@ private bool ProcessEntitySetAction(string actionName, IEdmEntitySet entitySet,
castCollectionType = castType.ToCollection(true);
}

IEdmCollectionType entityCollectionType = entitySet.EntityType().ToCollection(true);
IEdmCollectionType entityCollectionType = entitySet.EntityType.ToCollection(true);

// GET ~/Customers or GET ~/Customers/Ns.VipCustomer
IList<ODataSegmentTemplate> segments = new List<ODataSegmentTemplate>
Expand Down Expand Up @@ -147,7 +147,7 @@ private bool ProcessEntitySetAction(string actionName, IEdmEntitySet entitySet,

return true;
}
else if (actionName.Equals("Post", actionNameComparison) || actionName.Equals($"Post{entitySet.EntityType().Name}", actionNameComparison))
else if (actionName.Equals("Post", actionNameComparison) || actionName.Equals($"Post{entitySet.EntityType.Name}", actionNameComparison))
{
// POST ~/Customers
IList<ODataSegmentTemplate> segments = new List<ODataSegmentTemplate>
Expand All @@ -158,7 +158,7 @@ private bool ProcessEntitySetAction(string actionName, IEdmEntitySet entitySet,
if (castType != null)
{
IEdmCollectionType castCollectionType = castType.ToCollection(true);
IEdmCollectionType entityCollectionType = entitySet.EntityType().ToCollection(true);
IEdmCollectionType entityCollectionType = entitySet.EntityType.ToCollection(true);
segments.Add(new CastSegmentTemplate(castCollectionType, entityCollectionType, entitySet));
}
ODataPathTemplate template = new ODataPathTemplate(segments);
Expand All @@ -176,7 +176,7 @@ private bool ProcessEntitySetAction(string actionName, IEdmEntitySet entitySet,
if (castType != null)
{
IEdmCollectionType castCollectionType = castType.ToCollection(true);
IEdmCollectionType entityCollectionType = entitySet.EntityType().ToCollection(true);
IEdmCollectionType entityCollectionType = entitySet.EntityType.ToCollection(true);
segments.Add(new CastSegmentTemplate(castCollectionType, entityCollectionType, entitySet));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override bool AppliesToAction(ODataControllerActionContext context)
}

IEdmNavigationSource navigationSource = context.NavigationSource;
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;

// function should have the [HttpGet]
if (!context.Action.Attributes.Any(a => a is HttpGetAttribute))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public virtual bool AppliesToAction(ODataControllerActionContext context)
IEdmNavigationSource navigationSource = context.NavigationSource;

// filter by action parameter
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;
bool hasKeyParameter = action.HasODataKeyParameter(entityType, context.Options?.RouteOptions?.EnablePropertyNameCaseInsensitive ?? false);
if (!(context.Singleton != null ^ hasKeyParameter))
{
Expand Down Expand Up @@ -154,7 +154,7 @@ private void AddSelector(string httpMethod, ODataControllerActionContext context
IEdmNavigationProperty navigationProperty, bool hasKey, bool dollarCount)
{
IEdmEntitySet entitySet = context.EntitySet;
IEdmEntityType entityType = navigationSource.EntityType();
IEdmEntityType entityType = navigationSource.EntityType;

// Starts the routing template
IList<ODataSegmentTemplate> segments = new List<ODataSegmentTemplate>();
Expand Down
Loading

0 comments on commit 32172ec

Please sign in to comment.