标签: code-conversion

如何为 boolean.class/Boolean::class.javaPrimitiveType 和 Boolean.class/Boolean.class.java 注册类型适配器

我正在尝试将此 Java 示例转换为 Kotlin:

Gson gson = new GsonBuilder()
        .registerTypeAdapter(Boolean.class, new JsonStrictBooleanDeserializer())
        .registerTypeAdapter(boolean.class, new JsonStrictBooleanDeserializer())
        .create();
Run Code Online (Sandbox Code Playgroud)
val gson = GsonBuilder()
        .registerTypeAdapter(Boolean::class.java, JsonStrictBooleanDeserializer())
        .registerTypeAdapter(Boolean::class.javaPrimitiveType, JsonStrictBooleanDeserializer())
        .create()
Run Code Online (Sandbox Code Playgroud)

但是,它们的行为似乎并不相同。我反编译了 Kotlin 示例,似乎只注册了一种类型的适配器:

(new GsonBuilder())
        .registerTypeAdapter((Type)Boolean.TYPE, new JsonStrictBooleanDeserializer())
        .registerTypeAdapter((Type)Boolean.TYPE, new JsonStrictBooleanDeserializer())
        .create();
Run Code Online (Sandbox Code Playgroud)

在 Kotlin 中为装箱和原始布尔值注册类型适配器的正确方法是什么?

code-conversion gson kotlin

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

需要一些帮助将VB.NET代码转换为C#

我有一个用VB.NET编写的CRC类.我需要它在C#中.我使用在线转换器让我开始,但我收到一些错误.

byte[] buffer = new byte[BUFFER_SIZE];
iLookup = (crc32Result & 0xff) ^ buffer(i);
Run Code Online (Sandbox Code Playgroud)

在那一行,编译器给了我这个错误:

编译器错误消息: CS0118:'buffer'是'变量'但是像'方法'一样使用

我有什么想法可以解决这个问题?

谢谢!

c# code-conversion

2
推荐指数
7
解决办法
198
查看次数

你如何在C#中返回'not uint'?

我有一些用VB编写的代码,内容如下:

Return (Not (crc32Result))
Run Code Online (Sandbox Code Playgroud)

我正在尝试将其转换为C#,这就是我所拥有的:

return (!(crc32Result));
Run Code Online (Sandbox Code Playgroud)

但是我收到编译器错误:

编译器错误消息: CS0023:运算符'!' 不能应用于'uint'类型的操作数

是否有一个不同的运营商我需要使用而不是这个?

谢谢!

c# operators code-conversion

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

如何用python解析*.py文件?

我想解析Python源代码,以尝试从Python到Go的基本源代码转换器.

  • 我应该使用什么模块?
  • 我应该继续吗?
  • 如果我要继续,怎么样?

python code-conversion go

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

string vs System.String,int vs System.Int32:另一个Alias vs Type Name问题

很多时候,我看到那里的语言的关键字与完整的类型名称进行替换源代码: System.String,System.Int32,System.GUID等.

此外,执行此操作的人在任何地方都写出完整的类型名称,使得源代码充满了这样的声明:

System.Collections.Generic.List<System.Reflection.PropertyInfo> list = System.Collections.Generic.List<System.Reflection.PropertyInfo>(newSystem.Reflection.PropertyInfo[] { ... });
Run Code Online (Sandbox Code Playgroud)

当我问他们为什么这样做时,我得到了广泛的答案:"这有助于我避免类型名称冲突","它看起来更专业","我的VS插件自动为我做"等.

据我所知,using如果在整个源代码文件中使用类型一次,有时编写完整类型名称可以帮助您避免编写不必要的内容.有时您需要明确声明一个类型,一个很好的例子是Threading Timer和WinForms Timer.

但是如果你完整的数据库调用来源而你仍然在编写System.Data.SqlClient.SqlCommand而不是'SqlCommand',那对我来说看起来有点奇怪.

你怎么看?我是对的还是我只是不明白的东西?

谢谢!

PS而另一种现象是写作if (0 != variable而不是if (variable != 0).

.net c# code-conversion

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

如何将RETRIEVAL_POINTERS_BUFFER结构转换为Delphi?

我正在使用Windows API,并且必须在Delphi中重新创建一个结构record.我想我已经把它弄下来,但这个有点令人困惑,我需要确保我做对了.

这是原始的C++结构:

typedef struct RETRIEVAL_POINTERS_BUFFER {
  DWORD         ExtentCount;
  LARGE_INTEGER StartingVcn;
  struct {
    LARGE_INTEGER NextVcn;
    LARGE_INTEGER Lcn;
  } Extents[1];
} RETRIEVAL_POINTERS_BUFFER, *PRETRIEVAL_POINTERS_BUFFER;
Run Code Online (Sandbox Code Playgroud)

请注意,此结构中有一个数组结构.这是我迷路的地方.如果我没弄错的话,Delphi版应该是这样的:

  TExtent = record
    NextVcn: Integer;
    Lcn: Integer;
  end;

  TExtents = array of TExtent;

  PRETRIEVAL_POINTERS_BUFFER = ^TRETRIEVAL_POINTERS_BUFFER;
  TRETRIEVAL_POINTERS_BUFFER = record
    ExtentCount: DWORD;
    StartingVcn: Integer;
    Extents: TExtents;
  end;
Run Code Online (Sandbox Code Playgroud)

当我在Windows API中使用此结构时,它似乎确实有效.但是,由于结构内部的这个结构数组,我有点犹豫,我正确地做到了这一点.这看起来不错吗?

delphi winapi struct code-conversion delphi-xe2

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

在C#中,这段Java代码的等价物是什么?

我偶然发现了这个网站,我正在尝试测试这个想法,我不知道Java,所以我尝试将其转换为C#.一切似乎微不足道但我在执行样本时遇到了一些异常.

我想我必须在这里做错事.生成该异常的方法如下:

 static void setSolution(String newSolution)
 {
        solution = new byte[newSolution.length()];
        // Loop through each character of our string and save it in our byte
        // array
        for (int i = 0; i < newSolution.length(); i++){
            String character = newSolution.substring(i, i + 1);
            if (character.contains("0") || character.contains("1")){
                solution[i] = Byte.parseByte(character);
            } else {
                solution[i] = 0;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我基于C#的方法:

public static void SetSolution(string newSolution)
{
    solution = new byte[newSolution.Length];
    // Loop through each character of our string …
Run Code Online (Sandbox Code Playgroud)

c# java code-conversion

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

将类转换为struct

我有一个作业,我必须将类似c ++的程序转换为ac程序。

如果我有类似的东西

class B {
    int var;
    int somefunction(){
        some code here
    }
}
Run Code Online (Sandbox Code Playgroud)

它会变成

struct B{
    int var;
}

int somefunction(){
    some code here
}
Run Code Online (Sandbox Code Playgroud)

基本上,我不得不改变class,以struct每次看到它的时候,如果有一个功能,我现在把它移到了外面结构。

做这样的事情的最佳方法是什么?我得到了背后的理论,但不确定如何去实现它。

c++ parsing code-conversion

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

将if((loc = [player locateCardValue:8])> - 1)转换为Swift 3

你会如何转换这个Objective-C

if ((loc = [player locateCardValue:8]) > -1) {
Run Code Online (Sandbox Code Playgroud)

到Swift 3?

[player locateCardValue]返回'8'找到卡片的位置的整数.返回-1意味着它没有找到卡'8'.

我可以用......

let loc = player.locateCard(withValue: 8)
if loc > -1 {
Run Code Online (Sandbox Code Playgroud)

但我有多个IF的嵌套,它会变得非常混乱.

objective-c code-conversion swift

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

将 R 代码转换为 Python 的问题

from pyensae.languages import r2python

print(r2python(rscript, pep8=True))
Run Code Online (Sandbox Code Playgroud)

filename.R我在转换时遇到问题pythonfilename.py,因为这些库对于转换没有用,因为它会生成错误“找不到模块”,即使我使用以下方式安装了该模块:

pip install pyensae

python r pip code-conversion

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

标签 统计

code-conversion ×10

c# ×4

python ×2

.net ×1

c++ ×1

delphi ×1

delphi-xe2 ×1

go ×1

gson ×1

java ×1

kotlin ×1

objective-c ×1

operators ×1

parsing ×1

pip ×1

r ×1

struct ×1

swift ×1

winapi ×1