Tom Rouse
Tom Rouse

Reputation: 61

C# Can you serialise a class from within that class

using somthing.Pakages;

namespace somthing.Entity
{
public class SomeClass
{

    // Data from new quote
    public string SomeData;

    public string SomeData;

    public string SomeData;

    public string SomeData;

    public int SomeData;

    public int SomeData;

    public int SomeData;

    public int SomeData;

    public bool SomeData;

    public string SomeData;

    public LifePolicy[] SomeData;

    public CiPolicy[] SomeData;

    public int SomeData;

    public SomeData()
    {

    }

    public void Save()
    {
        if(string.IsNullOrEmpty(ApplicantId)){
            GuidCreator guidCreator = new GuidCreator();
            ApplicantId = guidCreator.GetGuid();
        }
        string serialization = ""; // On this line i want this var as a serialisation of this class with its vales
        DataSaver dataSaver = new DataSaver("Applicant", ApplicantId, serialization);
    }

}

}

How would i set the string serialization = to a string/json of this class as i need to save that data as a file but im not sure how i get this class into a string so it can be used.

Any help would be amazing thanks!

Upvotes: 0

Views: 56

Answers (1)

lcryder
lcryder

Reputation: 496

Visit & download: https://www.newtonsoft.com/json

Then: myString = JsonConvert.SerializeObject(this)

Upvotes: 1

Related Questions