Skip to content

Commit 8c77190

Browse files
authored
Reduce the number of members on ModelMetadataIdentity (#15280)
* Reduce the number of members on ModelMetadataIdentity ModelMetadataIdentity is a discriminated union. We recently introduced an additional member on this type, but are concerned about the performance implication of doing this. This change uses a discriminated field to reset the member count to 3.0.
1 parent 9bb9fc3 commit 8c77190

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.netcoreapp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ protected ModelBindingMessageProvider() { }
882882
public Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ModelMetadataKind MetadataKind { get { throw null; } }
883883
public System.Type ModelType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
884884
public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
885-
public System.Reflection.ParameterInfo ParameterInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
886-
public System.Reflection.PropertyInfo PropertyInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
885+
public System.Reflection.ParameterInfo ParameterInfo { get { throw null; } }
886+
public System.Reflection.PropertyInfo PropertyInfo { get { throw null; } }
887887
public bool Equals(Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ModelMetadataIdentity other) { throw null; }
888888
public override bool Equals(object obj) { throw null; }
889889
public static Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ModelMetadataIdentity ForParameter(System.Reflection.ParameterInfo parameter) { throw null; }

src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelMetadataIdentity.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ private ModelMetadataIdentity(
1717
Type modelType,
1818
string name = null,
1919
Type containerType = null,
20-
ParameterInfo parameterInfo = null,
21-
PropertyInfo propertyInfo = null)
20+
object fieldInfo = null)
2221
{
2322
ModelType = modelType;
2423
Name = name;
2524
ContainerType = containerType;
26-
ParameterInfo = parameterInfo;
27-
PropertyInfo = propertyInfo;
25+
FieldInfo = fieldInfo;
2826
}
2927

3028
/// <summary>
@@ -100,7 +98,7 @@ public static ModelMetadataIdentity ForProperty(
10098
throw new ArgumentNullException(nameof(containerType));
10199
}
102100

103-
return new ModelMetadataIdentity(modelType, propertyInfo.Name, containerType, propertyInfo: propertyInfo);
101+
return new ModelMetadataIdentity(modelType, propertyInfo.Name, containerType, fieldInfo: propertyInfo);
104102
}
105103

106104
/// <summary>
@@ -130,7 +128,7 @@ public static ModelMetadataIdentity ForParameter(ParameterInfo parameter, Type m
130128
throw new ArgumentNullException(nameof(modelType));
131129
}
132130

133-
return new ModelMetadataIdentity(modelType, parameter.Name, parameterInfo: parameter);
131+
return new ModelMetadataIdentity(modelType, parameter.Name, fieldInfo: parameter);
134132
}
135133

136134
/// <summary>
@@ -172,17 +170,19 @@ public ModelMetadataKind MetadataKind
172170
/// </summary>
173171
public string Name { get; }
174172

173+
private object FieldInfo { get; }
174+
175175
/// <summary>
176176
/// Gets a descriptor for the parameter, or <c>null</c> if this instance
177177
/// does not represent a parameter.
178178
/// </summary>
179-
public ParameterInfo ParameterInfo { get; }
179+
public ParameterInfo ParameterInfo => FieldInfo as ParameterInfo;
180180

181181
/// <summary>
182182
/// Gets a descriptor for the property, or <c>null</c> if this instance
183183
/// does not represent a property.
184184
/// </summary>
185-
public PropertyInfo PropertyInfo { get; }
185+
public PropertyInfo PropertyInfo => FieldInfo as PropertyInfo;
186186

187187
/// <inheritdoc />
188188
public bool Equals(ModelMetadataIdentity other)

0 commit comments

Comments
 (0)