相关疑难解决方法(0)

如何通过比较两个c#对象来创建JsonPatchDocument?

鉴于我有两个相同类型的c#对象,我想比较它们来创建一个JsonPatchDocument.

我有一个像这样定义的StyleDetail类:

public class StyleDetail
    {
        public string Id { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }
        public decimal OriginalPrice { get; set; }
        public decimal Price { get; set; }
        public string Notes { get; set; }
        public string ImageUrl { get; set; }
        public bool Wishlist { get; set; }
        public List<string> Attributes { get; set; }
        public ColourList Colours { get; set; }
        public SizeList Sizes { …
Run Code Online (Sandbox Code Playgroud)

c# json-patch

17
推荐指数
1
解决办法
4821
查看次数

C#box枚举错误与泛型

我不明白这里发生了什么......

我有以下错误: 该类型'TestApp.TestVal'不能用作'T'泛型类型或方法中的类型参数'TestApp.SomeClass<T>'.没有来自装箱转换'TestApp.TestVal''System.IComparable<TestApp.TestVal>'.

以下代码发生此错误:

public enum TestVal
{
    First,
    Second,
    Third
}

public class SomeClass<T>
    where T : IComparable<T>
{
    public T Stored
    {
        get
        {
            return storedval;
        }
        set
        {
            storedval = value;
        }
    }
    private T storedval;
}

class Program
{
    static void Main(string[] args)
    {
        //Error is on the next line
        SomeClass<TestVal> t = new SomeClass<TestVal>(); 
    }
}
Run Code Online (Sandbox Code Playgroud)

由于枚举是int默认的并且int实现了IComparable<int>接口,所以看起来应该没有错误....

c# generics enums icomparablet

5
推荐指数
2
解决办法
4018
查看次数

标签 统计

c# ×2

enums ×1

generics ×1

icomparablet ×1

json-patch ×1