我有一个看起来像这样的xml文件:
<xml>
<A>value</A>
<B>value</B>
<listitems>
<item>
<C>value</C>
<D>value</D>
</item>
</listitems>
</xml>
Run Code Online (Sandbox Code Playgroud)
我有两个代表这个xml的对象:
class XmlObject
{
public string A { get; set; }
public string B { get; set; }
List<Item> listitems { get; set; }
}
class Item : IXmlSerializable
{
public string C { get; set; }
public string D { get; set; }
//Implemented IXmlSerializeable read/write
public void ReadXml(System.Xml.XmlReader reader)
{
this.C = reader.ReadElementString();
this.D = reader.ReadElementString();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("C", this.C);
writer.WriteElementString("D", this.D);
} …Run Code Online (Sandbox Code Playgroud) 我需要将字符串拆分为"thisIs12MyString"类似的数组[ "this", "Is", "12", "My", "String" ]
我已经到目前为止,"thisIs12MyString".split(/(?=[A-Z0-9])/)但它在每个数字上分裂并给出数组[ "this", "Is", "1", "2", "My", "String" ]
所以在单词中我需要将字符串拆分为大写字母和数字,而前面没有另一个数字.
有没有办法序列化以下类的对象,并以某种方式忽略抛出的异常?
public class HardToSerialize
{
public string IAmNotTheProblem { get; set; }
public string ButIAm { get { throw new NotImplementedException(); } }
}
Run Code Online (Sandbox Code Playgroud)
并不奇怪的是,当Newtonsoft尝试序列化该ButIAm属性的值时会抛出错误.
我无法访问该类,因此我无法使用任何属性来装饰它.
澄清:我希望这适用于任何具有抛出NotImplementedException属性的对象.这个HardToSerialize课只是一个例子.
我发现以下代码用于在将密码存储在MSSQL数据库(该列为NVARCHAR类型)之前对其进行哈希处理.
string HashPassword(string password)
{
var encoding = Encoding.UTF8,
var plainBytes = encoding.GetBytes(password);
var hashedBytes = MD5.Create().ComputeHash(plainBytes);
return encoding.GetString(hashedBytes); //<-- Bad practice?
}
Run Code Online (Sandbox Code Playgroud)
起初我认为尝试将随机字节存储为UTF8字符串并且我应该将其更改为Base64编码真的很奇怪.但除了糟糕的做法之外,这样做有什么实际意义吗?
并且; 如果有人会得到数据库的保留,这是不是意味着不可能使用彩虹表或类似的尝试和暴力反转哈希,因为原始字节丢失?