static-import

static imports in c#

﹥>﹥吖頭↗ 提交于 2019-11-27 17:04:58
问题 Does C# has feature like Java's static imports? so instead of writing code like FileHelper.ExtractSimpleFileName(file) I could write ExtractSimpleFileName(file) and compiler would know that I mean method from FileHelper. 回答1: Starting with C# 6.0, this is possible: using static FileHelper; // in a member ExtractSimpleFileName(file) However, previous versions of C# do not have static imports. You can get close with an alias for the type. using FH = namespace.FileHelper; // in a member FH

What is a good use case for static import of methods?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 10:16:36
Just got a review comment that my static import of the method was not a good idea. The static import was of a method from a DA class, which has mostly static methods. So in middle of the business logic I had a da activity that apparently seemed to belong to the current class: import static some.package.DA.*; class BusinessObject { void someMethod() { .... save(this); } } The reviewer was not keen that I change the code and I didn't but I do kind of agree with him. One reason given for not static-importing was it was confusing where the method was defined, it wasn't in the current class and not

What is a good use case for static import of methods?

谁都会走 提交于 2019-11-26 03:25:23
问题 Just got a review comment that my static import of the method was not a good idea. The static import was of a method from a DA class, which has mostly static methods. So in middle of the business logic I had a da activity that apparently seemed to belong to the current class: import static some.package.DA.*; class BusinessObject { void someMethod() { .... save(this); } } The reviewer was not keen that I change the code and I didn\'t but I do kind of agree with him. One reason given for not