Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ProtoBuf-迁移到新版本_C#_Protobuf Net - Fatal编程技术网

C# ProtoBuf-迁移到新版本

C# ProtoBuf-迁移到新版本,c#,protobuf-net,C#,Protobuf Net,我最近迁移到protobuf net的新版本,之后我开始收到此错误消息 重复数据列表、集合等具有内置行为,不能用作子类 调用堆栈跟踪 protobuf-net.dll!ProtoBuf.Meta.MetaType.AddSubType(int fieldNumber = 1, System.Type derivedType = {Name = "InfoColumn`1" FullName = "Om.Common.InfoSet.InfoColumn`1[[System.Double, msc

我最近迁移到protobuf net的新版本,之后我开始收到此错误消息

重复数据列表、集合等具有内置行为,不能用作子类

调用堆栈跟踪

protobuf-net.dll!ProtoBuf.Meta.MetaType.AddSubType(int fieldNumber = 1, System.Type derivedType = {Name = "InfoColumn`1" FullName = "Om.Common.InfoSet.InfoColumn`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}) Line 83    C#
protobuf-net.dll!ProtoBuf.Meta.MetaType.ApplyDefaultBehaviour() Line 431 + 0x32 bytes   C#
在此方面的任何帮助都将不胜感激。我计划将我的代码回滚到protobuf net的早期版本

下面是课程信息

[DataContract]
[ProtoInclude(1, typeof(InfoColumn<Double>))]
[ProtoInclude(2, typeof(InfoColumn<String>))]
[ProtoInclude(3, typeof(InfoColumn<DateTime>))]
[ProtoInclude(4, typeof(InfoColumn<Boolean>))]
public abstract class IInfoColumnBase 
{
    [DataMember(Order = 101)]
    public abstract bool IsSingleValue { get; set; }

    [DataMember(Order = 102)]
    public abstract string Name { get; set; }

    [DataMember(Order = 103)]
    public abstract InfoColumnDataType DataType { get; set; }
    public abstract long Insert();
    public abstract void Insert(long index);
    public abstract void SetValue(long index, object val);
    public abstract void CopyValues(long start, long end, IInfoColumnBase destCol, long index);
    public abstract long GetIndex(object val);
    public abstract void Remove(long index);
    public abstract object GetValue(long index);
    public abstract object GetInternalArrayValue(long index);
    public abstract void Clear();
    public abstract long Count { get; }
    public abstract long ArrayCount { get; }
}

public interface IInfoColumn<T>  : IEnumerable<T>
{
    T this[double index] { get; set; }
    InfoTable Table { get; set; }
    double Add(T item);
}


[DataContract(Name = "InfoColumn{0}")]
[KnownType(typeof(InfoColumn<double>))]
[KnownType(typeof(InfoColumn<String>))]
[KnownType(typeof(InfoColumn<bool>))]
[KnownType(typeof(InfoColumn<DateTime>))]
public class InfoColumn<T> : IInfoColumnBase, IInfoColumn<T> 
{
    long counter = 0;
    [DataMember(Order = 1)]
    public IList<T> Values { get; set; }

    //[DataMember(Order = 2)]
    bool isSingleVal = false;

    //[DataMember(Order=3)]
    public override string Name { get; set; }

    //[DataMember(Order=4)]
    public override InfoColumnDataType DataType { get; set; }

    public InfoTable Table { get; set; }


    public override long Count
    {
        get
        {
            return this.Table.Count;
        }
    }

    public override long ArrayCount
    {
        get { return this.Values.Count; } 
    }

    public InfoColumn()
    {
    }

    public InfoColumn(string name,InfoTable table)
    {
        this.Values = new List<T>();
        this.Name = name;
        this.Table = table;
    }

    public override void Clear()
    {
        this.Values = new List<T>();
    }

    public override void Remove(long index)
    {
        int newindex = (int)index;
        this.Values.RemoveAt(newindex);

    }



    public override void CopyValues(long start, long end, IInfoColumnBase destCol, long startIndex)
    {
        InfoColumn<T> typeCol = destCol as InfoColumn<T>;
        for (long ctr = start; ctr <= end; ctr++)
        {
            typeCol.SetValue(startIndex, this.Values[(int)ctr]);
            startIndex++;
        }
    }

    public override void Insert(long rows)
    {

        if (this.IsSingleValue == true) return;

        for (int ctr = 0; ctr < rows; ctr++)
        {
            this.Values.Add(default(T));
        }
    }

    public  T this[double a]
    {
        get
        {
            if (a >= this.Count) throw new IndexOutOfRangeException();
            long index = (long)a;
            if (this.Table.IsFreezed == false)
                index = this.Table.CheckData(a);


            if (this.isSingleVal == true)
                return this.Values[0];
            else 
                return this.Values[(int)index];
        }
        set
        {
            if (a >= this.Count) throw new IndexOutOfRangeException();

            long index = (long)a; 

            if (this.Table.IsFreezed == false)
                index = this.Table.CheckData(a);

            if (this.isSingleVal == true)
                this.Values[0] = value;
            else
                this.Values[(int)index] = value;

        }
    }

    public override long GetIndex(object val)
    {
        T item = (T)val;
        return this.Values.IndexOf(item);
    }

    public override void SetValue(long index, object val)
    {
        if (val is InfoSetLink)
            this.Values[(int)index] = (T)val;
        else
            this.Values[(int)index] = (T)Convert.ChangeType(val, typeof(T));
    }

    public override object GetValue(long index)
    {
        return this[index];
    }

    public override object GetInternalArrayValue(long index)
    {
        return this.Values[(int)index];
    }


    //[DataMember(Order=5)]
    public override bool IsSingleValue 
    {
        get { return isSingleVal; }
        set
        {
            if (isSingleVal == true)
            {
                this.Values = new List<T>(1);
            }
        }
    }

    public override long Insert()
    {
        if (this.IsSingleValue == true) return -1;
        this.Values.Add(default(T));
        return this.Values.Count - 1;
    }

    public double Add(T item)
    {
        this.Values.Add(item);
        return this.Values.Count - 1;
    }

    #region IEnumerable<T> Members

    public IEnumerator<T> GetEnumerator()
    {
        return new InfoColumnEnumerator<T>(this);
    }

    #endregion

    #region IEnumerable Members

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return new InfoColumnEnumerator<T>(this);
    }

    #endregion


}
InfoColumn有一个公共AddT,并通过IInfoColumn实现IEnumerable

v2中对类似列表的类型有更广泛的支持,这可能是因为它试图将上述内容解释为列表。的确,它看起来很像!我将试着看一看是否可以检测并避免这种一般情况,但这是一种边缘情况,因为它确实非常复杂

存在一个现有的IgnoreListBehavior开关,但是当为上面显示的模型验证此开关时,似乎对于此特定场景,您不能在禁用列表处理的代码之前触发该开关;我在源代码中对此进行了更改,这将包含在下一版本中。基本上,您可以通过添加以下内容来解决此问题:

[ProtoContract(IgnoreListHandling = true)]
到受影响的类型InfoColumn,以及下一个构建。很快,当我完成验证等之后。

InfoColumn有一个公共AddT,并通过IInfoColumn实现IEnumerable

v2中对类似列表的类型有更广泛的支持,这可能是因为它试图将上述内容解释为列表。的确,它看起来很像!我将试着看一看是否可以检测并避免这种一般情况,但这是一种边缘情况,因为它确实非常复杂

存在一个现有的IgnoreListBehavior开关,但是当为上面显示的模型验证此开关时,似乎对于此特定场景,您不能在禁用列表处理的代码之前触发该开关;我在源代码中对此进行了更改,这将包含在下一版本中。基本上,您可以通过添加以下内容来解决此问题:

[ProtoContract(IgnoreListHandling = true)]

到受影响的类型InfoColumn,以及下一个构建。很快,等我完成验证等之后。

我的心理调试器今天不工作;你能告诉我你的型号在这里是什么样子吗?例如,InfoColumn看起来像什么?它有什么基类型和派生类型?它实现了什么接口?它是否有一个Add方法,这可能很重要?我已经用原来的问题更新了类结构。谢谢你的回答;r480已经上传到nuget和google Code我的心理调试器今天不工作;你能告诉我你的型号在这里是什么样子吗?例如,InfoColumn看起来像什么?它有什么基类型和派生类型?它实现了什么接口?它是否有一个Add方法,这可能很重要?我已经用原来的问题更新了类结构。谢谢你的回答;r480已经上传到nuget和google Code,感谢Marc的快速回复。我启动了最新版本,在添加了上述属性后,它确实修复了我的代码。感谢Marc的快速回复。我启动了最新的构建,在添加了上述属性之后,它确实修复了我的代码。