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

[Xamarin.Android.Build.Tasks] Fix Intellisense errors for switch statements #1731

Merged
merged 2 commits into from May 25, 2018

Conversation

Projects
None yet
3 participants
@dellis1972
Contributor

dellis1972 commented May 25, 2018

We got a report on slack that intellisense is showing errors on switch
statements for android resources. This might be because ALL of
the resource ids are 0 when using the managed parser.

This commit mimics the algorithm used by aapt as decribed at [1].
As a result most of the ids will be unique, which should fix
the intellisense errors.

[1] https://stackoverflow.com/questions/6517151/how-does-the-mapping-between-android-resources-and-resources-id-work

[Xamarin.Android.Build.Tasks] Fix Intellisense errors for switch stat…
…ements

We got a report that intellisense is showing errors on switch
statements for android resources. This might be because ALL of
the resource ids are 0 when using the managed parser.

This commit mimics the algorithm used by aapt as decribed at [1].
As a result most of the ids will be unique, which should fix
the intellisense errors.

[1] https://stackoverflow.com/questions/6517151/how-does-the-mapping-between-android-resources-and-resources-id-work

@dellis1972 dellis1972 requested review from kzu and jonathanpeppers May 25, 2018

@dellis1972 dellis1972 changed the title from [Xamarin.Android.Build.Tasks] Fix Intellisense errors for switch stat… to [Xamarin.Android.Build.Tasks] Fix Intellisense errors for switch statements May 25, 2018

// aapt resource value: 0
public const int slide_in_bottom = 0;
// aapt resource value: 0x7F030002
public const int slide_in_bottom = 2130903042;

This comment has been minimized.

@jonathanpeppers

jonathanpeppers May 25, 2018

Contributor

This might be from ancient history, but I was wondering why we don't just use the hex value in C#:

public const int some_resource = 0x7F030002;

Then we wouldn't need the comment?

It seems to compile fine: https://dotnetfiddle.net/3JPGU3

It's probably not worth changing this, I was mainly just wondering about it.

This comment has been minimized.

@dellis1972

dellis1972 May 25, 2018

Contributor

@jonathanpeppers its probably because this is what the CodeDom outputs.

This comment has been minimized.

@jonpryor

jonpryor May 25, 2018

Contributor

CodeDom is exactly why the values aren't in hex.

@jonpryor jonpryor merged commit 1822078 into xamarin:master May 25, 2018

3 checks passed

Ubuntu PR Build Build finished. No test results found.
Details
license/cla All CLA requirements met.
Details
macOS PR Build Build finished. 37261 tests run, 895 skipped, 0 failed.
Details

jonpryor added a commit that referenced this pull request May 29, 2018

[Xamarin.Android.Build.Tasks] Fix Intellisense errors for switch stat…
…ements (#1731)

We got a report that IntelliSense is showing errors on `switch`
statements for Android resources.  This might be because ALL of
the resource ids are 0 when using the managed parser:

        switch (value) {
        case Resource.Id.foo:
          // ...
          break;
        // IntelliSense doesn't like `.bar`, as it has the same value as `.foo`
        case Resource.Id.bar:
          // ...
          break;
        }

This commit mimics [the algorithm used by `aapt`][1].  As a result
most of the ids will now be unique, which should fix the
IntelliSense errors.

[1]: https://stackoverflow.com/questions/6517151/how-does-the-mapping-between-android-resources-and-resources-id-work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment