Compiler indicates non existent enum that exists

3

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 occurred

  

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 missing System.Globalization 'using d   irective?   Compilation failed: 1 error (s), 0 warnings

What you're saying, type UnicodeCategory does not exist. However, if we visit the GitHub repository, we can see that the enum System.Globalization.UnicodeCategory (C # CLI) has been implemented. So why does not the compiler find: v?

    
asked by anonymous 12.12.2017 / 00:17

1 answer

3

You have problems with both.

The first is importing the type statically and used the type name to access the members, either doing one thing or doing another. If you want to use the type name does not matter statically. There are more problems in this part of the code.

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

If you want soda bottles, order a crate or bale of bottles. 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 do not know what we really want.

So:

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

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

See running on .NET Fiddle . And no Coding Ground . Also I placed GitHub for future reference .

    
12.12.2017 / 00:39