[Fixes #3952] ViewComponentDescriptor.Type should be a TypeInfo instance instead of a Type instance
This commit is contained in:
parent
354400f12b
commit
357f4a00b7
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var componentType = context.ViewComponentDescriptor.Type.GetTypeInfo();
|
||||
var componentType = context.ViewComponentDescriptor.TypeInfo;
|
||||
|
||||
if (componentType.IsValueType ||
|
||||
componentType.IsInterface ||
|
||||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
|
||||
var viewComponent = _typeActivatorCache.CreateInstance<object>(
|
||||
context.ViewContext.HttpContext.RequestServices,
|
||||
context.ViewComponentDescriptor.Type);
|
||||
context.ViewComponentDescriptor.TypeInfo.AsType());
|
||||
|
||||
return viewComponent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
{
|
||||
FullName = ViewComponentConventions.GetComponentFullName(typeInfo),
|
||||
ShortName = ViewComponentConventions.GetComponentName(typeInfo),
|
||||
Type = type,
|
||||
TypeInfo = typeInfo,
|
||||
MethodInfo = FindMethod(type)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Html;
|
||||
|
|
@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
for (var i = 0; i < descriptors.Items.Count; i++)
|
||||
{
|
||||
var descriptor = descriptors.Items[i];
|
||||
if (descriptor.Type == componentType)
|
||||
if (descriptor.TypeInfo == componentType?.GetTypeInfo())
|
||||
{
|
||||
return descriptor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
foreach (var candidate in matches)
|
||||
{
|
||||
matchedTypes.Add(Resources.FormatViewComponent_AmbiguousTypeMatch_Item(
|
||||
candidate.Type.FullName,
|
||||
candidate.TypeInfo.FullName,
|
||||
candidate.FullName));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
{
|
||||
if (_displayName == null)
|
||||
{
|
||||
_displayName = Type?.FullName;
|
||||
_displayName = TypeInfo?.FullName;
|
||||
}
|
||||
|
||||
return _displayName;
|
||||
|
|
@ -116,9 +116,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
public string ShortName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="System.Type"/>.
|
||||
/// Gets or sets the <see cref="System.Reflection.TypeInfo"/>.
|
||||
/// </summary>
|
||||
public Type Type { get; set; }
|
||||
public TypeInfo TypeInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="System.Reflection.MethodInfo"/> to invoke.
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -194,7 +194,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.AsyncText",
|
||||
ShortName = "AsyncText",
|
||||
Type = typeof(AsyncTextViewComponent),
|
||||
TypeInfo = typeof(AsyncTextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(AsyncTextViewComponent).GetMethod(nameof(AsyncTextViewComponent.InvokeAsync)),
|
||||
};
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -320,7 +320,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -349,7 +349,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke))
|
||||
};
|
||||
|
||||
|
|
@ -407,7 +407,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -445,7 +445,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
@ -482,7 +482,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
FullName = "Full.Name.Text",
|
||||
ShortName = "Text",
|
||||
Type = typeof(TextViewComponent),
|
||||
TypeInfo = typeof(TextViewComponent).GetTypeInfo(),
|
||||
MethodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Http.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
|
@ -53,7 +54,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
var viewComponentDescriptor = new ViewComponentDescriptor()
|
||||
{
|
||||
Type = typeof(object),
|
||||
TypeInfo = typeof(object).GetTypeInfo(),
|
||||
};
|
||||
|
||||
var viewComponentContext = new ViewComponentContext(
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
|
|
@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
// Arrange
|
||||
var actionDescriptor = new ViewComponentDescriptor
|
||||
{
|
||||
Type = type
|
||||
TypeInfo = type.GetTypeInfo()
|
||||
};
|
||||
|
||||
var context = new ViewComponentContext
|
||||
|
|
@ -103,7 +104,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
{
|
||||
ViewComponentDescriptor = new ViewComponentDescriptor
|
||||
{
|
||||
Type = componentType
|
||||
TypeInfo = componentType.GetTypeInfo()
|
||||
},
|
||||
ViewContext = new ViewContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
|
||||
// Assert
|
||||
var descriptor = Assert.Single(descriptors);
|
||||
Assert.Same(typeof(ConventionsViewComponent), descriptor.Type);
|
||||
Assert.Same(typeof(ConventionsViewComponent).GetTypeInfo(), descriptor.TypeInfo);
|
||||
Assert.Equal("Microsoft.AspNetCore.Mvc.ViewComponents.Conventions", descriptor.FullName);
|
||||
Assert.Equal("Conventions", descriptor.ShortName);
|
||||
Assert.Same(typeof(ConventionsViewComponent).GetMethod("Invoke"), descriptor.MethodInfo);
|
||||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
|
||||
// Assert
|
||||
var descriptor = Assert.Single(descriptors);
|
||||
Assert.Equal(typeof(AttributeViewComponent), descriptor.Type);
|
||||
Assert.Equal(typeof(AttributeViewComponent).GetTypeInfo(), descriptor.TypeInfo);
|
||||
Assert.Equal("AttributesAreGreat", descriptor.FullName);
|
||||
Assert.Equal("AttributesAreGreat", descriptor.ShortName);
|
||||
Assert.Same(typeof(AttributeViewComponent).GetMethod("InvokeAsync"), descriptor.MethodInfo);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent("Suffix");
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.SuffixViewComponent), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.SuffixViewComponent).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent($"{Namespace}.Suffix");
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.SuffixViewComponent), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.SuffixViewComponent).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent("WithoutSuffix");
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.WithoutSuffix), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.WithoutSuffix).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent($"{Namespace}.WithoutSuffix");
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.WithoutSuffix), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.WithoutSuffix).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent("ByAttribute");
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.ByAttribute), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.ByAttribute).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent("ByNamingConvention");
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.ByNamingConventionViewComponent), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.ByNamingConventionViewComponent).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent("Namespace1.Ambiguous");
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.Ambiguous1), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.Ambiguous1).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
|||
var result = selector.SelectComponent(name);
|
||||
|
||||
// Assert
|
||||
Assert.Same(typeof(ViewComponentContainer.FullNameInAttribute), result.Type);
|
||||
Assert.Same(typeof(ViewComponentContainer.FullNameInAttribute).GetTypeInfo(), result.TypeInfo);
|
||||
}
|
||||
|
||||
private IViewComponentSelector CreateSelector()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Http.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
|
@ -52,7 +53,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
var viewComponentDescriptor = new ViewComponentDescriptor()
|
||||
{
|
||||
Type = typeof(object),
|
||||
TypeInfo = typeof(object).GetTypeInfo(),
|
||||
};
|
||||
|
||||
var viewComponentContext = new ViewComponentContext(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Internal;
|
||||
|
|
@ -81,7 +82,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
var viewComponentDescriptor = new ViewComponentDescriptor()
|
||||
{
|
||||
Type = typeof(object),
|
||||
TypeInfo = typeof(object).GetTypeInfo(),
|
||||
};
|
||||
|
||||
var viewComponentContext = new ViewComponentContext(
|
||||
|
|
|
|||
|
|
@ -536,7 +536,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var viewComponentDescriptor = new ViewComponentDescriptor()
|
||||
{
|
||||
ShortName = "Invoke",
|
||||
Type = typeof(object),
|
||||
TypeInfo = typeof(object).GetTypeInfo(),
|
||||
MethodInfo = typeof(object).GetTypeInfo().DeclaredMethods.First()
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
|
@ -52,7 +53,7 @@ namespace MvcSample.Web.Components
|
|||
|
||||
var viewComponentDescriptor = new ViewComponentDescriptor()
|
||||
{
|
||||
Type = typeof(TagCloudViewComponentTagHelper),
|
||||
TypeInfo = typeof(TagCloudViewComponentTagHelper).GetTypeInfo(),
|
||||
ShortName = "TagCloudViewComponentTagHelper",
|
||||
FullName = "TagCloudViewComponentTagHelper",
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue