private static void serializeToFile(TestProfile TestProfile, string filePath)
        {
            FileStream writer = null;

            try
            {
                System.Runtime.Serialization.DataContractSerializer serializer =
                    new System.Runtime.Serialization.DataContractSerializer(typeof(TestProfile));

                // Create a FileStream to write with.
                writer = new FileStream(filePath, FileMode.Create);

                // Write object out.
                serializer.WriteObject(writer, TestProfile);

                writer.Close();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (writer != null)
                {
                    // Close file.
                    writer.Close();
                }
            }
        }
        private static TestProfile deserializeFromFile(string filePath)
        {
            FileStream  reader      = null;
            TestProfile TestProfile = null;

            try
            {
                // Create DataContractSerializer.
                System.Runtime.Serialization.DataContractSerializer serializer =
                    new System.Runtime.Serialization.DataContractSerializer(typeof(TestProfile));

                // Create a file stream to read into.
                reader = new FileStream(filePath, FileMode.Open, FileAccess.Read);

                // Read into object.
                TestProfile = serializer.ReadObject(reader) as TestProfile;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (reader != null)
                {
                    // Close file.
                    reader.Close();
                }
            }

            return(TestProfile);
        }
 public static void WritetoFile(TestProfile TestProfile, string filePath)
 {
     serializeToFile(TestProfile, filePath);
 }