0

Is there in language anything like curclass to reference current class name without hardtyping it any time again and again?
As example something like typeof(curclass).GetMethod(nameof(curclass.MyMethod)) instead of typeof(MyPrettyClass).GetMethod(nameof(MyPrettyClass.MyMethod)).

Update: it's not just about name, but about alias.

Troll the Legacy
  • 675
  • 2
  • 7
  • 22

1 Answers1

0

There is no alias for current type or typedef equivalent in C#. I would suggest two possible solutions though:

1- Use using statement at top of the file:

using MyNamespace.MyPrettyClass = curclass;

You need to repeat this for every class though as this works only at the scope of current file.

2- Define a variable of type Type like this and use it:

private static Type curclass = typeof(MyPrettyClass);

The variable doesn't have to be static though but static allows to use in contexts when there is no specific instance. Also you have to repeat this construct for every class.

Mohammad
  • 1,930
  • 1
  • 21
  • 31