Skip to content
New issue

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

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

Already on GitHub? # to your account

Decompiler should be smarter around constants #25006

Closed
davkean opened this issue Feb 23, 2018 · 3 comments
Closed

Decompiler should be smarter around constants #25006

davkean opened this issue Feb 23, 2018 · 3 comments
Labels
Area-IDE Resolution-External The behavior lies outside the functionality covered by this repository

Comments

@davkean
Copy link
Member

davkean commented Feb 23, 2018

The following:

        internal int ActualMaxDegreeOfParallelism
        {
            get { return (_maxDegreeOfParallelism == Unbounded) ? int.MaxValue : _maxDegreeOfParallelism; }
        }

gets decompiled to:

		internal int ActualMaxDegreeOfParallelism
		{
			get
			{
				if (this.m_maxDegreeOfParallelism != -1)
				{
					return this.m_maxDegreeOfParallelism;
				}
				return 2147483647;
			}
		}

Similar to other decompilers, we should be smarter around replacing magic "literals" with their appropriate constants.

@HaloFour
Copy link

Would the decompiler look for any constants in scope that happen to match that literal? How would it disambiguate if there is more than one?

@CyrusNajmabadi
Copy link
Member

@HaloFour Roslyn already has some smarts here. Namely it looks in the Type for that value for any constants matching the value. If it finds any, it will use them. As such, it will replace constants with things like int.MaxValue, double.Infinity, etc. etc.

This is the behavior you would get previously with the normal 'metadata as source' feature.

@sharwell
Copy link
Member

sharwell commented Mar 7, 2018

➡️ Moved to icsharpcode/ILSpy#1084

@sharwell sharwell closed this as completed Mar 7, 2018
@sharwell sharwell added the Resolution-External The behavior lies outside the functionality covered by this repository label Mar 7, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Area-IDE Resolution-External The behavior lies outside the functionality covered by this repository
Projects
None yet
Development

No branches or pull requests

5 participants