Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: obsolete or hide TypeInfo/GetTypeInfo #53217

Closed
huoyaoyuan opened this issue May 25, 2021 · 13 comments · Fixed by #89317
Closed

Proposal: obsolete or hide TypeInfo/GetTypeInfo #53217

huoyaoyuan opened this issue May 25, 2021 · 13 comments · Fixed by #89317
Labels
api-approved API was approved in API review, it can be implemented area-System.Reflection breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Milestone

Comments

@huoyaoyuan
Copy link
Member

huoyaoyuan commented May 25, 2021

Background and Motivation

#53113
TypeInfo was introduced in .NET of Windows Store, for limited reflection. Nowadays in .NET Core, it has no feature difference with Type. To avoid confusing, we can hide or obsolete the type and tell people to use Type directly.

Proposed API

namespace System.Reflection
{
+    [Obsolete]
    public class TypeInfo { }
    public static class IntrospectionExtensions
    {
+        [EditorBrowsable(Never)]
        public static TypeInfo GetTypeInfo(this Type type);
    }
}

Usage Examples

N/A

Alternative Designs

N/A

Risks

There is also a public interface IReflectableType. Can there be custom implementation of it? Does it need to be hidden/obsoleted?

@huoyaoyuan huoyaoyuan added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label May 25, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Reflection untriaged New issue has not been triaged by the area owner labels May 25, 2021
@joperezr
Copy link
Member

cc @steveharter @GrabYourPitchforks thoughts?

@steveharter
Copy link
Member

I agree with the proposal, especially given that TypeInfo derived from Type in every release of .NET except for .NET Portable which is essentially supplanted with .NET Core.

The original rationale for TypeInfo is explained here.

@GrabYourPitchforks
Copy link
Member

I agree in spirit with the idea of obsoleting or hiding TypeInfo, but I fear this will be much more complicated than it appears. We already expose it through public type hierarchies, including the *Builder types through ref emit.

Since TypeInfo also does enjoy widespread use throughout the ecosystem, I don't know how good an idea it would be to hide the GetTypeInfo extension method. It could lead to difficulty for callers who have a Type, need to pass it to an API that takes a TypeInfo, and don't see any immediately obvious solution as to how to convert between the two.

@buyaa-n buyaa-n removed the untriaged New issue has not been triaged by the area owner label Jul 7, 2021
@buyaa-n buyaa-n added this to the 7.0.0 milestone Jul 7, 2021
@buyaa-n
Copy link
Contributor

buyaa-n commented Jul 7, 2021

@ghost ghost added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Jul 7, 2021
@buyaa-n buyaa-n removed the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Jul 8, 2021
@jeffhandley
Copy link
Member

I appreciate the hesitation that @GrabYourPitchforks expressed. If the type is used in non-obsolete APIs, then we should not obsolete it. Therefore this proposal would also need to include identification of all such APIs in the .NET Libraries and assessing if it's feasible to add method overloads and replacement properties. Depending on the surface area affected by that, we'd either conclude it to be low enough impact to proceed, or too disruptive.

@ghost ghost added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Jul 23, 2021
@terrajobst
Copy link
Member

I suggest we start with a code fixer that replaces GetTypeInfo() with calls to GetType(), and occurrences of TypeInfo with Type. A heavy reflection code based that migrated to Windows 8/was written for the Windows 8 era, would have have widely used both. The key would be making it easier for folks to move and then pushing them. Only obsoleting it without a code fixer will likely result in folks just suppressing it.

@buyaa-n
Copy link
Contributor

buyaa-n commented Oct 19, 2021

The usage of TypeInfo in source.dot.net is huge, and many internal/public reflection types derived from it. Can we change to derive from Type instead? I guess that could be a breaking change

@buyaa-n buyaa-n removed the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Oct 19, 2021
@terrajobst
Copy link
Member

The usage of TypeInfo in source.dot.net is huge, and many internal/public reflection types derived from it. Can we change to derive from Type instead? I guess that could be a breaking change

Yeah, we can't do that. External folks don't inherit from Type or TypeInfo, so all our own usage where we extend TypeInfo would need to remain and be suppressed.

@buyaa-n
Copy link
Contributor

buyaa-n commented Nov 30, 2021

I suggest we start with a code fixer that replaces GetTypeInfo() with calls to GetType(), and occurrences of TypeInfo with Type

@terrajobst the analyzer proposal is ready for review #61122, we might want to mark this one ready for review too

@buyaa-n buyaa-n added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Jul 6, 2022
@buyaa-n buyaa-n modified the milestones: 7.0.0, Future Jul 6, 2022
@bartonjs
Copy link
Member

bartonjs commented Jul 20, 2023

Video

  • Marking the type as [Obsolete] feels like overkill, since it will force anything already taking one to add a suppression.
  • The things that produce a TypeInfo are the more likely candidate.
  • But at this point we think we're probably fine with just hiding the methods, instead of Obsoleting them.
  • And since it's the only method we see on IntrospectionExtensions, let's mark that type as EB-Never, too.
  • Someone should update the docs for TypeInfo to call out it's now an obsolete/unnecessary indirection.
namespace System.Reflection
{
+   [EditorBrowsable(Never)]
    public static class IntrospectionExtensions
    {
+       [EditorBrowsable(Never)]
        public static TypeInfo GetTypeInfo(this Type type);
    }
}

@bartonjs bartonjs added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Jul 20, 2023
@terrajobst
Copy link
Member

  • Marking the type as [Obsolete] feels like overkill, since it will force anything already taking one to add a suppression.

That's fair.

Couple of other questions:

  1. Have we considered hiding TypeInfo as well?
  2. What about all the other reflection additions we did for Win8, such as
    • System.Reflection.AssemblyExtensions
    • System.Reflection.CustomAttributeExtensions
    • System.Reflection.CustomAttributeExtensions
    • System.Reflection.EventInfoExtensions
    • System.Reflection.MemberInfoExtensions
    • System.Reflection.MethodInfoExtensions
    • System.Reflection.ModuleExtensions
    • System.Reflection.RuntimeReflectionExtensions
    • System.Reflection.TypeExtensions

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Jul 20, 2023

Don't obsolete CustomAttributeExtensions. It defines GetCustomAttribute<T> and GetCustomAttributes<T> extension methods that are useful and do not exist as instance methods.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 21, 2023
@steveharter steveharter modified the milestones: Future, 9.0.0 Jul 26, 2023
@steveharter
Copy link
Member

Moving to 9; should be simple but there are the questions stated above about expanding the scope here around other types and extension methods.

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 3, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Reflection breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

9 participants