c# - 在 Python 中使用 System.Collections.Generic.List`1[System.Byte]

标签 c# python .net ironpython python.net

我有一个 Python 脚本,它从 .NET 应用程序接收数据。如何在我的脚本中使用“System.Collections.Generic.List`1[System.Byte]”类型的传入缓冲区?

脚本的功能是查找和替换字符串标记,将缓冲区重新组装回 System.Collections.Generic.List`1[System.Byte],然后将缓冲区返回给 .NET 服务器。

非常是 Python 的新手。这是我目前所拥有的:

import array
import clr
from System.Collections.Generic import *

def SetRecvBuffer(buffer):
    li = List[byte](buffer)
    hookme.Debug(li)    
    for x in li:
        hookme.Debug(x) 

如有任何帮助,我们将不胜感激。谢谢!

最佳答案

问题是 Python 端的 C# List 初始化忽略了括号中给出的项目,这看起来像一个错误,现在改为使用 List.Add():

import clr
clr.AddReference("System.Collections")
from System.Collections.Generic import List
from System import Int32

li = List[Int32](range(3))
list(li) #returns []
li.Add(5) 
list(li) #returns [5]

关于c# - 在 Python 中使用 System.Collections.Generic.List`1[System.Byte],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30586954/

相关文章:

Python 错误 : PermissionError: [WinError 5] Access is denied

.net - 如何在TopShelf中指定服务的命令行选项

c# - 使用c#删除书签的内容而不删除ms word中的书签

c# - 使用 Jet 读取 CSV 文件 - 制表符分隔不起作用!

c# - Razor View IsAuthenticated 未按预期工作

c# - 使用 ADO.NET 重命名列名称和更改表中列的数据类型

python - 在字典中查找并集和交集

python:从二维网格中无替换地采样

c# - Resharper 和 C# Catch 子句

c# - 在 WinPhone 中使用 PCL 中的 System.ComponentModel.DataAnnotations 就像 "microsoft bcl portability pack"一样?