Result of calling bound.repeat("hi ", 5) = ); document.write(); ) { document.write(); } else { document.write(); }
执行结果:
委托C#方法将绑定对象的方法作为参数传递给JavaScript方法。
myFunction(functionParam) { return functionParam(); } document.write( myFunction(bound.echoMyProperty));
echoMyProperty方法:public int EchoMyProperty() { return MyProperty;//初始化为42 }
返回C#对象BoundObject含有一个子对象 SubBoundObject。通过GetObject返回。
public SubBoundObject GetSubObject() { return SubObject; }
SubBoundObject:
public class SubBoundObject { public string SimpleProperty { get; set; } public SubBoundObject() { SimpleProperty = ; } public string GetMyType() { + GetType(); } public string EchoSimpleProperty() { return SimpleProperty; } }
View CodeJavaScript调用:
document.write();
执行结果:
获取bound对象的所有方法和属性
'bound的'所有方法: bound)
{
) continue;
document.write();
}
'bound的'所有属性: bound)
{
) continue;
document.write();
)
{
//展示子对象属性
bound[name])
{
;
document.write();
}
}
}
可以在C#对象中忽略掉属性和方法,这样就不会显示出来。
[JavascriptIgnore] public string IgnoredProperty { get; set; } [JavascriptIgnore] public string IgnoredMethod() { ; }
整个测试页面:
Binding Test Async Binding Test ); function writeAsyncResult(call, end) { ); ); ); ); document.createTextNode(call); document.createTextNode(end); p.appendChild(title); p.appendChild(br); p.appendChild(callText); p.appendChild(br2); p.appendChild(endText); asResult.appendChild(p); } function asyncError() { Date(); boundAsync.error(). (e) { ; writeAsyncResult(call, end); }); } function asyncDivOk() { Date(); boundAsync.div( (res) { ; writeAsyncResult(call, end); }); } function asyncDivFail() { Date(); boundAsync.div( (res) { ; writeAsyncResult(call, end); }, function (e) { ; writeAsyncResult(call, end); }); } function asyncHello() { Date(); boundAsync.hello( (res) { ; writeAsyncResult(call, end); }); } function asyncDoSomething() { Date(); boundAsync.doSomething().then(function (res) { ; writeAsyncResult(call, end); }); } asyncError(); asyncDivOk(); asyncDivFail(); asyncDoSomething(); Javscript Callback Test callback(s) { ); result.innerText Date(); } function testCallback() { bound.testCallback(callback); ); result.innerText ; } Test Callback Disposed Javscript Callback Test (navigates to before callback fires) disposedCallback(s) { ); ); result.innerText Date(); } function testDisposedCallback() { bound.testCallback(callback); ); result.innerText ; window.location.assign(); } Test Disposed Callback Result of calling bound.repeat("hi ", 5) = ); document.write(); ) { document.write(); } else { document.write(); } 委托c# 方法 myFunction(functionParam) { return functionParam(); } document.write( myFunction(bound.echoMyProperty)); Function returning complex type document.write( bound.getSubObject().simpleProperty); Stress Test ; ) { bound.repeat(); } document.write(); JSON Serializer Test bound.returnJsonEmployeeList(); JSON.parse(json); document.write(); ) { jsonObj.employees[i]; document.write(); } 'bound的'所有方法: bound) { ; document.write(); } 'bound的'所有属性: bound) { ; document.write(); ) { bound[name]) { ; document.write(); } } }
View CodeWebGL的渲染效果