第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

創(chuàng)建另一個(gè)類的后代

創(chuàng)建另一個(gè)類的后代

C#
手掌心 2021-06-02 13:37:04
我想根據(jù)以下內(nèi)容創(chuàng)建一個(gè)新類:    [Serializable()]    public class Class_A : ISerializable    {        public int DISP_SEGS { get; set; }        //Default constructor        public Class_A()        {            //        }        //Deserialization constructor    //If I add virtual to this I get an error        public Class_A(SerializationInfo info, StreamingContext ctxt)        {            foreach (PropertyInfo PI in this.GetType().GetProperties()) PI.SetValue(this, info.GetValue(PI.Name, PI.PropertyType));        }        //Serialization function        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)        {            foreach (PropertyInfo PI in this.GetType().GetProperties()) info.AddValue(PI.Name, PI.GetValue(this));        }    }我希望“Class_B”使用序列化和反序列化函數(shù)的功能。不想創(chuàng)建一個(gè)全新的類并復(fù)制所有代碼,這些代碼將在基礎(chǔ)中。我希望能夠創(chuàng)建一個(gè) Class_B 對(duì)象,然后調(diào)用:    Class_B cb = new Class_B();...    bformatter.Serialize(stream, cb);...    cb = (Class_B)bformatter.Deserialize(stream);
查看完整描述

3 回答

?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊

按照建議,我從 Binaryformatter 切換到 Protobuf。之后,一些問題,我已經(jīng)得到了它的工作。所以,我以一種新的格式回到我原來(lái)的問題。


我有一個(gè)基類,想從它創(chuàng)建幾個(gè)不同的類。我看到了,您應(yīng)該使用 Protobufs ProtoInclude 屬性。但是,好像落后了。它說(shuō),我的基類必須知道派生類型。


    [ProtoContract]

    [ProtoInclude(7, typeof(SomeDerivedType))]

    class SomeBaseType {...}


    [ProtoContract]

    class SomeDerivedType {...}

這是我派生的獨(dú)立課程。所以,它需要是通用的。


    [ProtoContract]

    public class grid

    {

    }

所以,我需要從中得出。


    [ProtoContract]

    public class Class_A : grid

    {

    }  


    [ProtoContract]

    public class Class_B : grid

    {

    }

我理解,將 ProtoInclude 放在 Class_A 和 Class_B 上沒有任何作用。不,如果它需要在網(wǎng)格類上。做到這一點(diǎn)的最佳方法是什么?因?yàn)?,我正在打字,我想知道是否需要制作一個(gè)了解 Class_A 和 Class_B 的存根類?


    [ProtoContract]

    [ProtoInclude(7, typeof(Class_A))]

    [ProtoInclude(8, typeof(Class_B))]

    public class ProtoStub : grid

    {

    }


    [ProtoContract]

    public class Class_A : ProtoStub

    {

    }


    [ProtoContract]

    public class Class_B : ProtoStub

    {

    }

如果那行得通,那好吧。:( 但是,那只是多余的不必要的代碼,這讓我很傷心。


查看完整回答
反對(duì) 回復(fù) 2021-06-05
?
大話西游666

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個(gè)贊

我正在轉(zhuǎn)換的內(nèi)容:


    //My base class

    [ProtoContract]

    public class grid

    {

        [ProtoMember(1), CategoryAttribute("Grid Settings"), DescriptionAttribute("Number of Horizontal GRID Segments.")]

        public int HorizontalCells { get; set; }


        //more properties

    }


    //Our Protostub ... Originally, just for Stackoverflow.  But, I'm liking the name.

    [ProtoContract]

    [ProtoInclude(7, typeof(SKA_Segments))]

    public class ProtoStub : grid

    {

    }


    SKA_Segments seg_map;


    [ProtoContract]

    public class SKA_Segments : ProtoStub

    {

        public SKA_Segments()

        {

        }


        public override void Draw(Graphics Graf, Pen pencil)

        {

            base.Draw(Graf, pencil);

        }

    }


    //Serialization stuff

    seg_map.HorizontalCells = 1000;  //test property comes from the grid class


    //Need to stream all three of these into the one file

    //Serializer.SerializeWithLengthPrefix(stream, map, PrefixStyle.Base128, 1);

    //Serializer.SerializeWithLengthPrefix(stream, col_map, PrefixStyle.Base128, 1);

    Serializer.SerializeWithLengthPrefix(stream, seg_map, PrefixStyle.Base128, 1);


    //De-Serialization stuff

    //map = Serializer.DeserializeWithLengthPrefix<SKA_MAP>(stream, PrefixStyle.Base128, 1);

    //col_map = Serializer.DeserializeWithLengthPrefix<SKA_Collision>(stream, PrefixStyle.Base128, 1);

    seg_map = Serializer.DeserializeWithLengthPrefix<SKA_Segments>(stream, PrefixStyle.Base128, 1);



查看完整回答
反對(duì) 回復(fù) 2021-06-05
  • 3 回答
  • 0 關(guān)注
  • 161 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)