Click here to Skip to main content
15,664,272 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All ,

I need to convert a List of data contracts to an integer array[]
from C# to an Integer array[] in C++/CLI and then to C++.

Could you please let me know how can I achive this.

Appreciate your help on this.

//topicDetails is a data-contract

//Here TopicDetails is a class (data contract) as follows.

public class TopicDetails
        protected object baseObjectType;  //string
        protected object topic;            //string

        public TopicDetails();

        public object BaseObjectType { get; set; }
        public object TopicID { get; set; }

        public static TopicDetails CreateTopic<T, mT>(IComparable<T> objectType, IComparable<mT> objectID);
Updated 26-Aug-15 22:02pm
Maciej Los 27-Aug-15 4:26am    
What have you tried? Where are you stuck?
Member 3975629 27-Aug-15 4:44am    
Basically I am not getting any idea on how to proceed. could you please suggest any ideas/suggestions on how to approach this.

Member 3975629 27-Aug-15 5:29am    
As you asked ,

I need to convert from C# , List of datacontract to C++ const integer vector &topicList via C++/CLI wrapper.

I need to pass List of data contract to C++/CLI and then to C++
I need to convert List of data contracts from C# to an integer array in C++ thru a wrapper classes. Please see the details in the below link. And please provide your suggestions on how to achieve this. Thanks..

1 solution

Hi All,

The following code is working to satisfy the requirement.
Please take a look at it.
To convert List of Datacontracts to an integer array.

 int[] data;

var obj = topicDetails;// topicDetails= new List<TopicDetails> { };// List of DataContracts{ BaseObjectType = ":EQUIPMENT", TopicID = "42" };
           var serializer = new System.Runtime.Serialization.DataContractSerializer(typeof(List<TopicDetails>));

           using (var stream = new System.IO.MemoryStream())
               serializer.WriteObject(stream, obj);

               data = new int[stream.Length];
               stream.Position = 0;

               for (int i = 0; i < data.Length; i++)
                   data[i] = stream.ReadByte();
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900