Can you use a name when hidden in a member of a sphere?

Consider the following legacy code:

public class Foo
{
    public void Blah(string frob)
    {
        if (frob == null)
            throw new ArgumentException("frob");
    }

    public string nameof()
    {
        //boring code
    }
}

Now imagine that part of this code is being reorganized, and we want to reorganize Blahas follows:

public void Blah(string frob)
{
    if (frob == null)
        throw new ArgumentException(nameof(frob)); //nameof contextual keyword
}

This analyzer will not select a contextual keyword nameofand will allow a private method nameofgiving a compile-time error (without existing overload). What for? I would understand it if there was a method nameof(object o).

Is there any way to enable the compiler inline nameof? Do I need to reorganize code that renames a method?

The example above is a very simplified scenario, in truth, the method is nameofwidely used in reflection, and it will take time and effort to make sure that the renaming has been done correctly everywhere.

+4
3

nameof private , ( ). ?

"" ; , " ?"

, , , . , var # 3, ,

class var { public implicit operator var(int x) { ... } }
...
var y = 3;

var y, int. , , .

, yield return yield return, yield, * yield return. yield(123);

await async, from select .. .

, nameof nameof, , . , # . ", , , , ..." , , . nameof , pre-# 6. 99,9% , nameof .

# - " - , , ". , , . # - , , .

+8

, nameof -, - ...

, , nameof, , nameof.

, .

, nameof , , , nameof nameof ( , ), , nameof. , nameof.

.NET, , , - .

, , , , .

0

, nameof , . name.

-1
source

Source: https://habr.com/ru/post/1668555/


All Articles