@@ -31,32 +31,32 @@ public sealed class DefaultModelTypeBuilder : IModelTypeBuilder
31
31
* incorrect bucket is picked, then the type mapping will fail. the model type builder detects if a model
32
32
* is ad hoc. if it is, then it will recursively create a private instance of itself to handle the ad hoc
33
33
* 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.
37
38
*/
38
39
39
40
private static Type ? ienumerableOfT ;
40
41
private readonly bool adHoc ;
42
+ private readonly bool excludeAdHocModels ;
41
43
private DefaultModelTypeBuilder ? adHocBuilder ;
42
44
private ConcurrentDictionary < ApiVersion , ModuleBuilder > ? modules ;
43
45
private ConcurrentDictionary < ApiVersion , IDictionary < EdmTypeKey , Type > > ? generatedEdmTypesPerVersion ;
44
46
private ConcurrentDictionary < ApiVersion , ConcurrentDictionary < EdmTypeKey , Type > > ? generatedActionParamsPerVersion ;
45
47
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
+ }
47
53
48
54
/// <summary>
49
55
/// Initializes a new instance of the <see cref="DefaultModelTypeBuilder"/> class.
50
56
/// </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 ;
60
60
61
61
/// <inheritdoc />
62
62
public Type NewStructuredType ( IEdmModel model , IEdmStructuredType structuredType , Type clrType , ApiVersion apiVersion )
@@ -68,13 +68,13 @@ public Type NewStructuredType( IEdmModel model, IEdmStructuredType structuredTyp
68
68
69
69
if ( model . IsAdHoc ( ) )
70
70
{
71
- if ( ExcludeAdHocModels )
71
+ if ( excludeAdHocModels )
72
72
{
73
73
return clrType ;
74
74
}
75
75
else if ( ! adHoc )
76
76
{
77
- adHocBuilder ??= new ( adHoc : true ) ;
77
+ adHocBuilder ??= new ( excludeAdHocModels , adHoc : true ) ;
78
78
return adHocBuilder . NewStructuredType ( model , structuredType , clrType , apiVersion ) ;
79
79
}
80
80
}
@@ -111,7 +111,7 @@ public Type NewActionParameters( IEdmModel model, IEdmAction action, string cont
111
111
112
112
if ( ! adHoc && model . IsAdHoc ( ) )
113
113
{
114
- adHocBuilder ??= new ( adHoc : true ) ;
114
+ adHocBuilder ??= new ( excludeAdHocModels , adHoc : true ) ;
115
115
return adHocBuilder . NewActionParameters ( model , action , controllerName , apiVersion ) ;
116
116
}
117
117
0 commit comments