Entries

笔记:从Hex向Byte[]转换 / Converting Hex String To Byte Array


using XS = System.Xml.Serialization;

public static class Utils
{
private class dummyReader : XS.XmlSerializationReader
{
protected override void InitCallbacks()
{
}

protected override void InitIDs()
{
}

public static byte[] HexToBytes(string hex)
{
return ToByteArrayHex(hex);
}
}
private class dummyWriter : XS.XmlSerializationWriter
{
protected override void InitCallbacks()
{
}

public static string BytesToHex(byte[] bin)
{
return FromByteArrayHex(bin);
}
}

public static string BytesToHex(byte[] bin)
{
return dummyWriter.BytesToHex(bin);
}

public static byte[] HexToBytes(string hex)
{
return dummyReader.HexToBytes(hex);
}
}


虽然查阅.NET FX源码之后发现这个种实现要经过至少三层的静态方法调用,但这也是目前我能像出来的最偷懒的办法了。
Although it makes more than 3 layers of static method calling inside the Frameworks' implement, it's the easiest way I've found.
引用此文章(FC2博客用户)
http://shinron4.blog126.fc2blog.us/tb.php/36-72afee5e

引用

留言

发表留言

发表留言
只对管理员显示

Appendix

自我介绍

优雅的神棍 / Elegant Tales

Author:优雅的神棍 / Elegant Tales
神棍你好,神棍再见。

最新引用

QR

QR

羔羊们啊

加为好友

和此人成爲好友

搜寻栏