c# - How to know the type of deserialized class??(or objects) -


i have 2 classes

[serializable]     public class class1 {                     public list<string[]> items= new list<string[]>();         }  [serializable] public class class2 {     public list<string[]> items = new list<string[]>();                 } 

and serialize these classes , send data clients this

networkstream stream = client.getstream(); memorystream memory = new memorystream(); binaryformatter bf = new binaryformatter();  class1 data = new class1(); // or class2 data.items.add(new string[]{"1", "2", "3"});         bf.serialize(memory, data); memory.position = 0;  byte[] buffer = memory.toarray();                          stream.write(buffer, 0, buffer.length); stream.flush(); 

when client program receive data server, program handle data this

binaryformatter bf = new binaryformatter(); memorystream memory = new memorystream(); networkstream stream = client.getstream();  int buffersize = client.receivebuffersize; byte[] buffer = new byte[buffersize]; int bytes = stream.read(buffer, 0, buffer.length);  memory.write(buffer, 0, buffer.length); memory.position = 0; 

but in situation, don't know type of data...is class1??? or class2..

how know type of deserialized class??(or objects)

you should able deserialize object, use gettype()

gettype(new binaryformatter().deserialize(stream));


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -