php到C#转换器

SOF*_*ser 13 php c#

我需要将这个PHP代码转换为C#.是否有工具或网站可以实现这一目标?

public function call($method, array $params) {
    // Add the format parameter, only 'json' is supported at the moment
    if (!array_key_exists('format', $params)) {
        $params['format'] = 'json';
    }

    $url = "{$this->_url}/{$method}";
    $ch = $this->_getCurlHandle($url);

    if (!$ch) {
        throw new Fuze_Client_Exception("Unable to create a cURL handle");
    }

    // Set the request parameters
    $queryString = http_build_query($params);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString);

    // Fire!
    $result = $this->_executeCurl($ch);

    // All API response payloads should be valid json with 'code' and
    // 'message' members
    $json = json_decode($result);
    if ( !($json instanceof stdClass)
            || !isset($json->code)
            || !isset($json->message) ) {

        throw new Fuze_Client_ServerException(
            "Invalid JSON payload received", $result, $info['http_code']);
    }

    if ( $json->code >= 500 && $json->code < 600) {
        throw new Fuze_Client_FaultException($json);
    }

    return $json;
}
Run Code Online (Sandbox Code Playgroud)

RQD*_*QDQ 39

我不知道任何可以从PHP转换为C#的工具.如果有这样的事情,我不相信它能正确地进行转换.这样就可以选择:

  • 学习C#
  • 将它传递给可以转换它的人.

  • 可以将现有的PHP代码集成到.NET中,而不是转换,例如使用Phastnger,如http://stackoverflow.com/questions/5221669/php-to-c-sharp-converter/8007020#8007020所述.用过的 (4认同)
  • +1,借调.将源代码从一种语言转换为另一种语言是一项复杂的任务,我怀疑有一种工具可以实现,更不用说可靠性了. (3认同)

Bea*_*ker 18

也许你应该看看Phalanger.它不是转换器,但它允许你为.Net编译PHP代码 - 所以你应该能够从C#调用php方法.它是一个开源项目,源代码在这里托管.

  • Phalanger 已打折,请使用 https://www.peachpie.io 代替。 (3认同)

Jak*_*šek 7

不要转换(这会导致无法管理的意大利面条式代码),而是使用我们正在处理的 PHP 编译器使 PHP 项目成为常规的 .NET 项目(如 F# 或 C++/CLI):

https://github.com/iolevel/peachpie

这样,除此之外,您还可以保持 PHP 代码的可维护性,同时可以从 C# 无缝使用它。

一些资源: