我需要一种方法来跨 .NET 框架/环境/执行一致地生成给定对象或对象属性子集的唯一 ID,同时最大限度地减少冲突。
例如,给定一个固定对象,例如
public class ExampleObject
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public int Prop3 { get; set; }
public decimal Prop4 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我正在考虑将所有值转换为字符串,连接它们,然后使用一些确定性算法来获得所需的结果
// Convert all values to strings and concat
string str1 = "a";
string str2 = "b";
int int1 = 1;
decimal dec1 = 1.2m;
string concatStr …Run Code Online (Sandbox Code Playgroud)