标签: invocation

以类似拳击的方式召集代表

我经常看到代理调用的代码示例如下所示:

`

    public delegate void DelegateThreadActivity<T, U> (T sender, U e);

    public event DelegateThreadActivity<Thread, System.EventArgs> OnStart = null;
    public event DelegateThreadActivity<Thread, System.EventArgs> OnStop = null;

    // Helper method for invocation.
    public void RaiseOnStart ()
    {
        DelegateThreadActivity<Thread, System.EventArgs> instance = null;

        try
        {
            instance = this.OnStart;
            // OR
            instance = (DelegateThreadActivity) (object) this.OnStart;

            if (instance != null)
            {
                instance(this, System.EventArgs.Empty);
            }
        }
        catch
        {
        }
    }
Run Code Online (Sandbox Code Playgroud)

`

为什么要使用这个[instance]对象?起初我认为这是公司惯例,但看到经验丰富的开发人员也这样做.有什么好处?

.net c# convention delegates invocation

3
推荐指数
1
解决办法
246
查看次数

克罗克福德的"新"方法

希望有人可以帮我打破Crockford JS Good Parts的一小段代码:

Function.method('new', function ( ) {
  // Create a new object that inherits from the
  // constructor's prototype.
  var that = Object.create(this.prototype);
  // Invoke the constructor, binding –this- to
  // the new object.
  var other = this.apply(that, arguments);
  // If its return value isn't an object,
  // substitute the new object.
  return (typeof other === 'object' && other) || that;
});
Run Code Online (Sandbox Code Playgroud)

我不理解的部分是他使用apply调用模式创建一个对象:

var other = this.apply(that, arguments);
Run Code Online (Sandbox Code Playgroud)

如何执行函数将创建新对象?

如果该功能将是:

var f = function (name) { …
Run Code Online (Sandbox Code Playgroud)

javascript invocation apply

3
推荐指数
1
解决办法
189
查看次数

如何在.NET 3.5中进行动态对象创建和方法调用

代码看起来如何创建类的对象:

string myClass = "MyClass";
Run Code Online (Sandbox Code Playgroud)

以上类型,然后调用

string myMethod = "MyMethod";
Run Code Online (Sandbox Code Playgroud)

那个对象?

.net c# clr dynamic invocation

2
推荐指数
1
解决办法
1万
查看次数

以下代码如何工作?

目前我正试图像这样调用它:

class Test {
    public static void test() {
        System.out.println("hi");
    }
    public static void main(String[] args) {
        Test t = null;
        t.test();
    }
}
Run Code Online (Sandbox Code Playgroud)

代码的输出是hi

java methods static invocation

2
推荐指数
2
解决办法
242
查看次数

iPhone:使用dispatch_after来模仿NSTimer

不知道很多关于积木的事情.你会如何去模仿重复NSTimer使用dispatch_after()?我的问题是我想在应用程序移动到后台时"暂停"一个计时器,但是子类NSTimer似乎不起作用.

我尝试过似乎有用的东西.我无法判断其性能影响或是否可以大大优化.欢迎任何输入.

#import "TimerWithPause.h"


@implementation TimerWithPause

@synthesize timeInterval;
@synthesize userInfo;
@synthesize invalid;
@synthesize invocation;

+ (TimerWithPause *)scheduledTimerWithTimeInterval:(NSTimeInterval)aTimeInterval target:(id)aTarget selector:(SEL)aSelector userInfo:(id)aUserInfo repeats:(BOOL)aTimerRepeats {

    TimerWithPause *timer = [[[TimerWithPause alloc] init] autorelease];

    timer.timeInterval  = aTimeInterval;

    NSMethodSignature *signature = [[aTarget class] instanceMethodSignatureForSelector:aSelector];
    NSInvocation *aInvocation = [NSInvocation invocationWithMethodSignature:signature];
    [aInvocation setSelector:aSelector];
    [aInvocation setTarget:aTarget];
    [aInvocation setArgument:&timer atIndex:2];
    timer.invocation = aInvocation;

    timer.userInfo      = aUserInfo;

    if (!aTimerRepeats) {
        timer.invalid = YES;
    }

    [timer fireAfterDelay];

    return timer;
}

- (void)fireAfterDelay {

    dispatch_time_t delay = …
Run Code Online (Sandbox Code Playgroud)

objective-c invocation nstimer grand-central-dispatch objective-c-blocks

2
推荐指数
1
解决办法
9015
查看次数

Mockito.verify选择性方法调用

在我的应用程序中,我的代码看起来像 -

request.setParameter("a",false);//line1
request.setParameter("b",someObject);//line2
request.setParameter("c",someObject);//line3
request.setParameter("d",someObject);//line4
Run Code Online (Sandbox Code Playgroud)

我已经模拟了请求对象,现在我想验证是否调用了line3.在我试过的测试类中,我不关心其他行 Mockito.verify(request).setParameter("c",someObject) ,但是我得到了错误 -

Argument(s) are different! Wanted:
request.setParameter("c",com.test.MyObject@fec107);
-> at XXX

Actual invocation has different arguments:
request.setParameter("a", false);
Run Code Online (Sandbox Code Playgroud)

出于某种原因,Mockito比较了第一次调用和抛出错误

verify invocation mockito

2
推荐指数
1
解决办法
1431
查看次数

更改名称会破坏项目运行能力!Xcode中

我最近改变了我的项目名称,然后当我运行时,我得到了Apple Mach-O Linker错误.

ld: file not found: /Users/Ajay/Library/Developer/Xcode/DerivedData/TapAway-dzdhwbcfttcdcceccpophqtqgmvl/Build/Products/Debug-iphonesimulator/Speedy.app/Speedy
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会这样,任何人都可以帮助我,我真的很新.

感谢所有帮助过的人.请具体一点我不是那么好.

再次感谢 :)

linker file mach-o invocation

2
推荐指数
1
解决办法
547
查看次数

这是一个有效的Java方法调用?

我刚刚阅读了Marko Rodriguez 关于不同类型数据库的优秀博客文章.虽然阅读我发现了一些语法......

// put data
db.put('marko');
db.put(31);
db.put(true);
// get data
Iterator results = db.get();
Iterator filteredResults = db.get{it.startsWith('ma')};
Run Code Online (Sandbox Code Playgroud)

...我认为它是Java的片段,但我从来没有见过像这样使用花括号调用的方法 - db.get{it.startsWith('ma')}.

任何细节/想法将不胜感激!

java methods invocation

1
推荐指数
1
解决办法
230
查看次数

如何传递Null\Void而不是数组?

有一些invokeMethod接受(java.lang.String method_name, Object[] params, Class[] params_classes)你会如何调用签名的方法void MyMethod()

java parameters arguments invocation

1
推荐指数
1
解决办法
2750
查看次数

获取对arity-0 scala函数的引用

Scala允许在没有括号的情况下调用没有参数列表的函数:

scala> def theAnswer() = 42
theAnswer: ()Int

scala> theAnswer
res5: Int = 42
Run Code Online (Sandbox Code Playgroud)

我将如何构造一个scala表达式来计算函数theAnswer本身,而不是结果theAnswer?或者换句话说,我将如何修改表达式theAnswer,以便结果是类型() => Int,而不是类型Int

types scala invocation

1
推荐指数
1
解决办法
288
查看次数