简体   繁体   English

带后缀的C#数字序列化

[英]C# Serialization of numerics with suffixes

Is there some library for C#, or classes in .Net, that serializes numeric values with their corresponding suffixes to differentiate between eg signed and unsigned, int and long. 是否有一些C#库或.Net中的类,该库可将数值及其相应的后缀序列化以区分例如有符号和无符号,int和long。

For example, I want the following serializition behavior: 例如,我想要以下序列化行为:

ulong value = 123456789;
string valueStr = ToString(value);    

// valueStr == "123456789ul"

and a way to deserialize it, eg: 以及反序列化的方法,例如:

object parsedValue;
Type parsedType;
ParseNumeric(out parsedValue, out parsedType);    

// parsedValue == 123456789 (as an ulong)
// parsedType == typeof(ulong)

I need it to handle at least float, double, int, uint, long, ulong. 我需要它至少处理float,double,int,uint,long,ulong。

I've actually already wrote some naive code for this, but I'm wondering if there is anything out there already made for this? 我实际上已经为此写了一些幼稚的代码,但是我想知道是否已经为此做了什么?

如果使用DataContractSerializer并将typeof(object)传递为声明的类型,则应获得所需的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM