本文整理汇总了C#中IFunction.apply方法的典型用法代码示例。如果您正苦于以下问题:C# IFunction.apply方法的具体用法?C# IFunction.apply怎么用?C# IFunction.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFunction
的用法示例。
在下文中一共展示了IFunction.apply方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefault page)
{
page.SetVariable.onclick +=
delegate
{
var f = new IFunction("value", "this.foo = value;");
f.apply(null, page.VariableText.value);
page.ShowVariable.style.fontWeight = "bold";
};
page.ShowVariable.onclick +=
delegate
{
page.ShowVariable.style.fontWeight = "";
var f = new IFunction("alert(this.foo);");
f.apply(null);
};
page.GetVariableWithComment.onclick +=
delegate
{
var f = new IFunction("return { Text: this.foo, Comment: 'from javascript' };");
var r = (AnanymousDataEntry)f.apply(null);
Native.window.alert(
new
{
r.Text,
r.Comment
}.ToString()
);
};
@"Hello world".ToDocumentTitle();
// Send data from JavaScript to the server tier
service.WebMethod2(
@"A string from JavaScript.",
value => value.ToDocumentTitle()
);
}
示例2: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IApp page)
{
Console.WriteLine("InitializeContent");
//, b2Fixture = Box2D.Dynamics.b2Fixture
//, b2MassData = Box2D.Collision.Shapes.b2MassData
;
var world = new Box2D.Dynamics.b2World(
new Box2D.Common.Math.b2Vec2(0, 10) //gravity
, true //allow sleep
);
var fixDef = new Box2D.Dynamics.b2FixtureDef();
fixDef.density = 1.0;
fixDef.friction = 0.5;
fixDef.restitution = 0.2;
var bodyDef = new Box2D.Dynamics.b2BodyDef();
//create ground
const int b2Body_b2_staticBody = 0;
bodyDef.type = b2Body_b2_staticBody;
bodyDef.position.x = 9;
bodyDef.position.y = 13;
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape();
((Box2D.Collision.Shapes.b2PolygonShape)fixDef.shape).SetAsBox(10, 0.5);
world.CreateBody(bodyDef).CreateFixture(fixDef);
//var x = world.CreateBody(bodyDef);
//new IFunction("x", "alert(typeof x);").apply(null, x);
var __random = new IFunction("return Math.random();");
Func<double> Math_random = () => (double)__random.apply(null);
//create some objects
const int b2Body_b2_dynamicBody = 2;
bodyDef.type = b2Body_b2_dynamicBody;
for (var i = 0; i < 10; i++)
{
if (Math_random() > 0.5)
{
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape();
((Box2D.Collision.Shapes.b2PolygonShape)fixDef.shape).SetAsBox(
Math_random() + 0.1 //half width
, Math_random() + 0.1 //half height
);
}
else
{
fixDef.shape = new Box2D.Collision.Shapes.b2CircleShape(
Math_random() + 0.1 //radius
);
}
bodyDef.position.x = Math_random() * 10;
bodyDef.position.y = Math_random() * 10;
world.CreateBody(bodyDef).CreateFixture(fixDef);
}
//setup debug draw
var debugDraw = new Box2D.Dynamics.b2DebugDraw();
var context = page.canvas1.getContext("2d");
debugDraw.SetSprite(context);
debugDraw.SetDrawScale(30.0);
debugDraw.SetFillAlpha(0.3);
debugDraw.SetLineThickness(1.0);
const int b2DebugDraw_e_shapeBit = 0x1;
const int b2DebugDraw_e_jointBit = 0x2;
debugDraw.SetFlags(b2DebugDraw_e_shapeBit | b2DebugDraw_e_jointBit);
world.SetDebugDraw(debugDraw);
var c = 0;
Native.window.onframe += delegate
{
c++;
Native.document.title = "" + c;
world.Step(
1.0 / 60 //frame-rate
, 10 //velocity iterations
, 10 //position iterations
);
world.DrawDebugData();
world.ClearForces();
};
Console.WriteLine("InitializeContent done");
//new IFunction("alert(Box2D);").apply(null);
//Native.Window.alert("bodyDef=" + bodyDef);
}
示例3: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IApp page)
{
var toolbar = new
{
createItem = new IFunction("y", "return opera.contexts.toolbar.createItem(y);"),
addItem = new IFunction("y", "opera.contexts.toolbar.addItem(y);")
};
var windows = new
{
// http://dev.opera.com/articles/view/extensions-api-windows-create/
create = new IFunction("", "return opera.extension.windows.create();"),
// http://dev.opera.com/articles/view/extensions-api-window-update/
update = new IFunction("y", "this.update(y);"),
};
try
{
// can only create one button?
toolbar.createItem.apply(null,
new Opera_UIItemProperties
{
title = "OperaExtensionExperiment",
popup = new OperaToolbarPopupArguments { href = "index.html" }
}
).With(
theButton =>
{
toolbar.addItem.apply(null, theButton);
}
);
}
catch
{
// not running as extension?
}
// will only work on toolbar
//page.NewBrowser.style.color = JSColor.Green;
//page.NewBrowser.onclick +=
// delegate
// {
// var w = windows.create.apply(null);
// windows.update.apply(w,
// new Opera_BrowserWindowProperties
// {
// width = 400
// }
// );
// };
page.IAmAPopup.style.color = JSColor.Green;
page.IAmAPopup.onclick +=
delegate
{
page.IAmAPopup.style.color = JSColor.Red;
var getScreenshot = new IFunction("y", "opera.extension.getScreenshot(y);");
Action<ImageData> applyScreenshot =
imageData =>
{
// Create a blank canvas
var canvas = new IHTMLCanvas();
canvas.width = (int)imageData.width;
canvas.height = (int)imageData.height;
// Write the screenshot image data to the canvas context
var ctx = (CanvasRenderingContext2D)canvas.getContext("2d");
ctx.putImageData(imageData, 0, 0, 0, 0, imageData.width, imageData.height);
canvas.style.border = "1px solid blue";
canvas.AttachToDocument();
page.IAmAPopup.style.color = JSColor.Blue;
};
// http://dev.opera.com/articles/view/extensions-api-screenshot/
getScreenshot.apply(null, IFunction.OfDelegate(applyScreenshot));
};
page.foooex.ondragstart +=
e =>
{
// http://ajaxian.com/archives/how-to-drag-out-files-like-gmail
e.dataTransfer.setData("DownloadURL",
"application/octet-stream:foo.oex:" + page.foooex.href);
//.........这里部分代码省略.........
示例4: Application
//.........这里部分代码省略.........
foreach (var id in Expando.InternalGetMemberNames((object)window.manager.tracks))
{
Console.WriteLine(new { id });
//window.manager.tracs[item].setAmplitude(0);
// https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPanner
PannerNode panner = window.audio.panners[id];
// Failed to set the 'buffer' property on 'AudioBufferSourceNode': The provided value is not of type 'AudioBuffer'.
panner.disconnect();
THREE.Object3D t = window.video.trackObjects[id];
t.parent.remove(t);
}
window.manager.trackCount = 0;
//window.manager.tracks = new { };
window.manager.tracks = new object();
// vsync
await Native.window.async.onframe;
var MovingTrack = new IFunction("url", "return new MovingTrack({ src: url, color: 0x19414B});");
dynamic track = MovingTrack.apply(null, a.src);
Console.WriteLine("addTrack");
window.manager.addTrack(track);
Console.WriteLine("loadTrack_");
window.audio.loadTrack_(track.id);
Func<bool> isready = () => window.audio.ready[track.id];
var ready = new TaskCompletionSource<object> { };
new { }.With(
async delegate
{
while (!ready.Task.IsCompleted)
{
await Task.Delay(300);
bool xready = isready();
Console.WriteLine(new { track.id, xready });
if (xready)
ready.SetResult(null);
}
}
);
示例5: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IApp page)
{
Console.WriteLine("Application ctor");
if (page != null)
if (page.Content != null)
if (page.Content.childNodes.Length == 0)
{
var f = new IFunction("");
f.apply(null);
ApplicationWebService service = new ApplicationWebService();
ApplicationSprite sprite = new ApplicationSprite();
sprite.AutoSizeSpriteTo(page.ContentSize);
sprite.AttachSpriteTo(page.Content);
//Console.WriteLine("init... WhenReady?");
// a.__out_MethodInterface.MgAABkE_bRDa_ancxRw7JDdQ(PQAABosGVzucrRDVfJkoTA(a, b));
//sprite.WhenReady(
// delegate
// {
// Console.WriteLine("init... Ready!");
// }
//);
return;
}
Console.WriteLine("looking for myself...");
//Native.Window.alert("now what?");
//Action yield = delegate
//{
// Console.WriteLine("looking for myself... done!");
//};
Native.window.requestAnimationFrame +=
delegate
{
Native.Document.getElementsByTagName("embed").WithEach(
e =>
{
var embed = (IHTMLEmbedFlash)e;
try
{
// this is a hack
//var sprite = new ApplicationSprite();
//object sprite_object = sprite;
//dynamic a = sprite_object;
//a.__InternalElement = embed;
//var sprite = (ApplicationSprite)(object)embed;
Console.WriteLine("looking for myself... WhenReady?");
Initialize(
args =>
{
embed.CallFunction("WhenReady", new[] { args });
}
);
//sprite.WhenReady(yield);
}
catch
{ }
}
);
};
}