php 到 C# 转换器 [已关闭]

2022-08-30 22:34:33

我需要将此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;
}

答案 1

我不知道有任何工具可以从PHP转换为C#。如果有这样的事情,我不会相信它能正确地进行转换。因此,您的选择将留给:

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

答案 2

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


推荐