static-methods

Is there a way to force a C# class to implement certain static functions?

大兔子大兔子 提交于 2019-11-27 04:45:10
I am developing a set of classes that implement a common interface . A consumer of my library shall expect each of these classes to implement a certain set of static functions. Is there anyway that I can decorate these class so that the compiler will catch the case where one of the functions is not implemented. I know it will eventually be caught when building the consuming code. And I also know how to get around this problem using a kind of factory class. Just curious to know if there is any syntax/attributes out there for requiring static functions on a class. Ed Removed the word 'interface'

Can a static method be overridden in C#?

女生的网名这么多〃 提交于 2019-11-27 04:28:42
I was told that static methods are implicitly final and therefore can't be overridden. Is that true? Can someone give a better example of overriding a static method? If static methods are just class methods, what is the real use of having them? (1) Static methods cannot be overridden, they can however be hidden using the 'new' keyword. Mostly overriding methods means you reference a base type and want to call a derived method. Since static's are part of the type and aren't subject to vtable lookups that doesn't make sense. E.g. statics cannot do: public class Foo { public virtual void Bar() {

How to mock with static methods?

感情迁移 提交于 2019-11-27 04:20:09
问题 I'm new to mock objects, but I understand that I need to have my classes implement interfaces in order to mock them. The problem I'm having is that in my data access layer, I want to have static methods, but I can't put a static method in an interface. What's the best way around this? Should I just use instance methods (which seems wrong) or is there another solution? 回答1: I would use a method object pattern. Have a static instance of this, and call it in the static method. It should be

c++ automatic factory registration of derived types

北慕城南 提交于 2019-11-27 04:06:20
Like many before me, I'm trying so get my derived types to automatically register with my factory. I read through many question and tried to focus on what I didn't find there. I've got everything running nicely except the automatic registration. My Goals: automatically register any derived class of my base class Base only classes I mark as registrable not only direct sub-classes of Base ex: Base -> Device -> Camera -> Webcam this would make using the CRTP like described in this question dificult minimal changes to the classes I want registered - dummies proof would prefer using a registrator

Ruby on rails - Static method

余生长醉 提交于 2019-11-27 02:01:50
问题 I want a method to be executed every 5 minutes, I implemented whenever for ruby (cron). But it does not work. I think my method is not accessible. The method I want to execute is located in a class. I think I have to make that method static so I can access it with MyClass.MyMethod . But I can not find the right syntax or maybe I am looking in the wrong place. Schedule.rb every 5.minutes do runner "Ping.checkPings" end Ping.rb def checkPings gate = Net::Ping::External.new("10.10.1.1") @monitor

Excel vba to create every possible combination of a Range

佐手、 提交于 2019-11-27 01:04:47
I have a problem that I haven't been able to find anywhere on the web (it may be there, but I can't find it, heh). I have a spreadsheet with 13 columns of data. Each of the column contains variations of a parameter that needs to go into an overall test case. All of them differ, like E: 101% 105% 110% 120% J: Upper S Upside L Downside B Premium V I have seen several solutions to the combination issue which uses nested loops. I'd like to steer clear of 13 nested loops (but this is my best bet at the moment). I'm kind of at a loss on how to generate every unique combination in in each column. I'm

super() and @staticmethod interaction

我只是一个虾纸丫 提交于 2019-11-27 01:00:53
问题 Is super() not meant to be used with staticmethods? When I try something like class First(object): @staticmethod def getlist(): return ['first'] class Second(First): @staticmethod def getlist(): l = super(Second).getlist() l.append('second') return l a = Second.getlist() print a I get the following error Traceback (most recent call last): File "asdf.py", line 13, in <module> a = Second.getlist() File "asdf.py", line 9, in getlist l = super(Second).getlist() AttributeError: 'super' object has

ReSharper complains when method can be static, but isn't

蹲街弑〆低调 提交于 2019-11-27 00:59:50
Why does ReSharper complain when a method can become static, but is not? Is it because only one instance of a static method is created (on the type) and thus save on performance? I find that comment very useful as it points out two important things: It makes me ask myself if the method in question should actually be part of the type or not. Since it doesn't use any instance data, you should at least consider if it could be moved to its own type. Is it an integral part of the type, or is it really a general purpose utility method? If it does make sense to keep the method on the specific type,

How to verify static void method has been called with power mockito

淺唱寂寞╮ 提交于 2019-11-27 00:41:44
问题 I am using the following. Powermock-mockito 1.5.12 Mockito 1.95 junit 4.11 Here is my utils class public void InternalUtils { public static void sendEmail(String from, String[] to, String msg, String body) { } } here is gist of the class under test: public class InternalService { public void processOrder(Order order) { if (order.isSuccessful()) { InternalUtils.sendEmail(...); } } } And here is the test: @PrepareForTest({InternalUtils.class}) @RunWith(PowerMockRunner.class) public class

Static properties in Swift

為{幸葍}努か 提交于 2019-11-27 00:14:14
I'm trying to convert the following Objective-C code to Swift. In my Objective-C code, there's a static variable and its accessed from a class method. @implementation SomeClass static NSMutableArray *_items; + (void)someMethod { [_items removeAll]; } @end Since you can't access types declared like this private var items = [AnyObject]() from class functions in Swift, I created a stored property for it like this. class var items: [AnyObject] { return [AnyObject]() } And I'm trying to call a method on it from a class function like so. class func someFunction() { items.removeAll(keepCapacity: