小编Yot*_*mon的帖子

(C#)在运行时编译类并从原始代码调用方法


我正在尝试在C#中运行时编译代码,然后从编译的代码中调用一个函数或初始化一个在原始代码中定义的类.
我目前的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;

namespace CTFGame
{
    class Program
    {
        static void Main(string[] args)
        {
            string code = @"

using System;

namespace CTFGame
{
    public class MyPlayer
    {
        public static void Main ()
        {
            Console.WriteLine(""Hello world"");
        }
        /*public void DoTurn ()
        {
            Program.SayHello();
        }*/
    }
}

";
            CSharpCodeProvider provider = new CSharpCodeProvider();
            CompilerParameters parameters = new CompilerParameters();
            parameters.GenerateInMemory = true;

            CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);
            if …
Run Code Online (Sandbox Code Playgroud)

c# runtime dynamic-compilation

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

以编程方式显示桌面

我正在编写Windows窗体应用程序,我需要以编程方式返回到桌面.

我尝试了这段代码,但它没有用:

using System;
using System.Windows.Forms;

private void ToggleDesktop() {

SendKeys.Send("^({ESC}D)"); //<-- Semantic error, Should simulate: WIN+D

}
Run Code Online (Sandbox Code Playgroud)

有可能这样做吗?

c# desktop sendkeys winforms

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

Find JavaScript handler connected to a button's click event

During some code investigating, I found a html submit button like this:

<button class="btn btn-primary">Create new aicraft</button>
Run Code Online (Sandbox Code Playgroud)

I know somewhere there is javascript code that handeles the button click event. How can I find that javascript code?

html javascript events

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

与http请求通信Java-Javascript

最近我一直试图在minecraft服务器(用Java运行)和scratch(用JavaScript运行)之间进行通信.我已经用java编写了代码:

package me.yotam180;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;


public class HttpProcessor {
     public MainClass plugin;
    public HttpProcessor (MainClass plug) throws IOException {
        plugin = plug;
        plugin.getLogger().info("CREATED HTTTP PROCESSOR");
        HttpServer server = HttpServer.create(new InetSocketAddress(9090), 0);
        server.createContext("/pollplayer", new PollPlayerHandler());
        server.createContext("/killplayer", new KillPlayerHandler());
        plugin.getLogger().info("STARTED HTTTP SERVER");
        server.setExecutor(null); // creates a default executor
        server.start();
    }

    static class PollPlayerHandler implements HttpHandler {

        @SuppressWarnings("deprecation")
        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
            // …
Run Code Online (Sandbox Code Playgroud)

javascript java minecraft mit-scratch bukkit

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

使用void类型(不是方法)定义类属性

我正在尝试构建一个名为GameObject的类(用于consoleApplication游戏),GameObject应该有一个函数"onFrame",每0.1秒调用一次.

但问题是,这个函数(void)应该对每个gameObject都是唯一的 - 假设我有GameObject:G1,G2.G1会在onFrame中将变量增加1,G2会在控制台上打印一些内容(只是示例).

有可能吗?

我试着用这种方式做到这一点:

class GameObject 
{
    public void onFrame;

    public GameObject (void of) //constructor
    {
        onFrame = of;
        Thread t = new Thread(runOnFrame);
        t.isBackgroundThread = true;
        t.Start();
    }

    protected void runOnFrame () 
    {
        while (true)
        {
            Thread.Sleep(100);
            if (onFrame != null) onFrame(); //EDIT: that (0) was typed by mistake
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

主要功能:

public static int i = 0;
static void Main (string[] args)
{
    GameObject G1 = new GameObject(new void (){
        i++;
    });
    GameObject G2 = …
Run Code Online (Sandbox Code Playgroud)

c# oop void

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