Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e43aa4

Browse filesBrowse files
Default to excluding ad hoc model substitution (more common)
1 parent 0931848 commit 9e43aa4
Copy full SHA for 9e43aa4

File tree

Expand file treeCollapse file tree

1 file changed

+16
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-16
lines changed

‎src/Common/src/Common.OData.ApiExplorer/OData/DefaultModelTypeBuilder.cs

Copy file name to clipboardExpand all lines: src/Common/src/Common.OData.ApiExplorer/OData/DefaultModelTypeBuilder.cs
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,32 @@ public sealed class DefaultModelTypeBuilder : IModelTypeBuilder
3131
* incorrect bucket is picked, then the type mapping will fail. the model type builder detects if a model
3232
* is ad hoc. if it is, then it will recursively create a private instance of itself to handle the ad hoc
3333
* bucket. normal odata cannot opt out of this process because the explored type must match the edm. a type
34-
* mapped via an ad hoc edm is not really odata so it can opt out if desired. the opt out process is more
35-
* of a failsafe and optimization. if the ad hoc edm wasn't customized, then the meta model and type should
36-
* be exactly the same, which will result in no substitution.
34+
* mapped via an ad hoc edm is not really odata so it should opt out by default because without an edm
35+
* there is not away to control member serialization/deserialization easily. such cases will typically
36+
* create a type-per-version, as is common for non-odata, which negates the need for model substitution.
37+
* a user can opt into ad hoc model substitution if they have a way to deal with member filtering.
3738
*/
3839

3940
private static Type? ienumerableOfT;
4041
private readonly bool adHoc;
42+
private readonly bool excludeAdHocModels;
4143
private DefaultModelTypeBuilder? adHocBuilder;
4244
private ConcurrentDictionary<ApiVersion, ModuleBuilder>? modules;
4345
private ConcurrentDictionary<ApiVersion, IDictionary<EdmTypeKey, Type>>? generatedEdmTypesPerVersion;
4446
private ConcurrentDictionary<ApiVersion, ConcurrentDictionary<EdmTypeKey, Type>>? generatedActionParamsPerVersion;
4547

46-
private DefaultModelTypeBuilder( bool adHoc ) => this.adHoc = adHoc;
48+
private DefaultModelTypeBuilder( bool excludeAdHocModels, bool adHoc )
49+
{
50+
this.adHoc = adHoc;
51+
this.excludeAdHocModels = excludeAdHocModels;
52+
}
4753

4854
/// <summary>
4955
/// Initializes a new instance of the <see cref="DefaultModelTypeBuilder"/> class.
5056
/// </summary>
51-
public DefaultModelTypeBuilder() { }
52-
53-
/// <summary>
54-
/// Gets or sets a value indicating whether types from an ad hoc Entity Data Model
55-
/// (EDM) should be excluded.
56-
/// </summary>
57-
/// <value>True if types from an ad hoc EDM are excluded; otherwise, false. The
58-
/// default value is <c>false</c>.</value>
59-
public bool ExcludeAdHocModels { get; set; }
57+
/// <param name="includeAdHocModels">Indicates whether types from an ad hoc Entity
58+
/// Data Model (EDM) should be included.</param>
59+
public DefaultModelTypeBuilder( bool includeAdHocModels = false ) => excludeAdHocModels = !includeAdHocModels;
6060

6161
/// <inheritdoc />
6262
public Type NewStructuredType( IEdmModel model, IEdmStructuredType structuredType, Type clrType, ApiVersion apiVersion )
@@ -68,13 +68,13 @@ public Type NewStructuredType( IEdmModel model, IEdmStructuredType structuredTyp
6868

6969
if ( model.IsAdHoc() )
7070
{
71-
if ( ExcludeAdHocModels )
71+
if ( excludeAdHocModels )
7272
{
7373
return clrType;
7474
}
7575
else if ( !adHoc )
7676
{
77-
adHocBuilder ??= new( adHoc: true );
77+
adHocBuilder ??= new( excludeAdHocModels, adHoc: true );
7878
return adHocBuilder.NewStructuredType( model, structuredType, clrType, apiVersion );
7979
}
8080
}
@@ -111,7 +111,7 @@ public Type NewActionParameters( IEdmModel model, IEdmAction action, string cont
111111

112112
if ( !adHoc && model.IsAdHoc() )
113113
{
114-
adHocBuilder ??= new( adHoc: true );
114+
adHocBuilder ??= new( excludeAdHocModels, adHoc: true );
115115
return adHocBuilder.NewActionParameters( model, action, controllerName, apiVersion );
116116
}
117117

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.