Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java的c#封送结构等价物_Java_C#_Marshalling_Equivalent_Commarea - Fatal编程技术网

java的c#封送结构等价物

java的c#封送结构等价物,java,c#,marshalling,equivalent,commarea,Java,C#,Marshalling,Equivalent,Commarea,我想为java创建同样的对象。有可能创建它吗 工作原理: 使用系统; 使用System.Runtime.InteropServices; 使用System.Text.RegularExpressions; 使用通用模型; 使用系统文本; 命名空间Common.Utilities.Helpers { 公共部分类CommareaHelper { 公共静态T StringToObject(字符串缓冲区) { IntPtr pBuf=IntPtr.0; 尝试 { pBuf=Marshal.String

我想为java创建同样的对象。有可能创建它吗

工作原理:

使用系统;
使用System.Runtime.InteropServices;
使用System.Text.RegularExpressions;
使用通用模型;
使用系统文本;
命名空间Common.Utilities.Helpers
{
公共部分类CommareaHelper
{
公共静态T StringToObject(字符串缓冲区)
{
IntPtr pBuf=IntPtr.0;
尝试
{
pBuf=Marshal.StringToBSTR(缓冲区);
return(T)Marshal.PtrToStructure(pBuf,typeof(T));
}
接住
{
投
}
最后
{
pBuf=整数零;
}
}
公共静态字符串ObjectToString(对象转换对象)
{
int size=0;
IntPtr pBuf=IntPtr.0;
尝试
{
size=Marshal.SizeOf(conversionObject);
pBuf=封送处理。AllocHGlobal(大小);
StructureToPtr(conversionObject,pBuf,false);
返回Marshal.PtrToStringAuto(pBuf,size).Substring(0,size/2);
}
接住
{
投
}
最后
{
弗里赫全球元帅(pBuf);
}
}
}
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
公共类通信区
{
[Marshallas(UnmanagedType.ByValTStr,SizeConst=1)]
私有字符串状态;
公共字符串状态
{
收到
{
返回新字符串(status).Trim();
}
设置
{
status=value.ToFixedCharArray(1,true);
}
}
[Marshallas(UnmanagedType.ByValTStr,SizeConst=5)]
私有字符串操作名;
公共字符串操作名
{
收到
{
返回新字符串(operationName).Trim();
}
设置
{
operationName=value.ToFixedCharArray(5,true);
}
}
}
我可以使用一行字符串填充任何对象,并与该操作相反

string commareaStr = "0TR231";
Commarea commarea = CommareaHelper.StringToObject<Commarea>(commareaStr);
字符串commarestr=“0TR231”;
Commarea Commarea=CommareaHelper.StringToObject(commareaStr);

看看JNI,没有办法定义自己的二进制序列化声明。
string commareaStr = "0TR231";
Commarea commarea = CommareaHelper.StringToObject<Commarea>(commareaStr);