Compiler indicates non-existent Enum that exists

Asked

Viewed 64 times

4

I’m using the Mono compiler. When I tried to compile this:

using static System.Globalization.CharUnicodeInfo;
using static System.Globalization.UnicodeCategory;

namespace AS3Kit.Lexical
{
    static class Validator
    {
        static bool TestCategory(UnicodeCategory cat, int cp)
            { return CharUnicodeInfo.GetUnicodeCategory(cp) == cat; }

        // ...
    }
}

Error

D: hydroper local work Cs As3kit>mcs -recurse:source/*. Cs -out:As3kit.exe source Lexical Validator.Cs(8,28): error CS0246: The type or namespace name Uni codeCategory' could not be found. Are you missingSystem.Globalization' using d irective? Compilation failed: 1 error(s), 0 warnings

What do you mean, the guy UnicodeCategory does not exist. However, if we visit the Github repository, we can see that Enum System.Globalization.UnicodeCategory (C#CLI) has been implemented. So why does the compiler not find :v ?

1 answer

5


He’s got problems in both.

The first is statistically importing the type and using the type name to access the members, or does one thing or do another. If you want to use the type name do not import statically. You have more problems with this part of the code.

The second is that you are statistically importing the enumeration, but you are not using any of its members. The static import is to access your members directly. If you will only use the type and not the members, which is the case, then import the type in the normal way, ie by namespace, because you want what’s inside it, the kind and not what’s inside it, don’t do it statically.

If you want soda bottles, order a crate or bottle bale. If you want the liquid in the bottle, ask for the bottle. When we conceptualize right everything works, the problem is that we think mechanically and often don’t know what we really want.

Thus:

using static System.Globalization.CharUnicodeInfo;
using System.Globalization;

static class Validator {
    static void Main() {}
    static bool TestCategory(UnicodeCategory cat, char cp) => GetUnicodeCategory(cp) == cat;
}

Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.

  • So I did a lot of things wrong : using static is a little different from import static java...

  • 2

    @Hogenesis They have the same purpose. The two serve to access the static members directly, without writing their class name before.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.