title: Getting datas from JSON file with Json.NET and create c-sharp file with using T4 Text Template
body: <p>I want to create <code>Subject.cs</code> file programmatically. For this, when I searched the Internet, I saw that I could use T4 Text Templates. Now, I want to get datas from a JSON file with Json.NET and set the <code>Root</code> values as a property, like this:</p>
  
  <pre><code>namespace Library
  {
      class Subject
      {
          public static int forensic_medicine { get; set; }
          public static int family_law { get; set; }
          public static int constitutional_law { get; set; }
          public static int obligations_law { get; set; }
      }
  }
  </code></pre>
  
  <p>Here is the JSON file content:</p>
  
  <pre><code>{
      "Subjects": [
          {
              "Root": "forensic_medicine",
              "Name": "Forensic Medicine",
              "StrID": "FMD",
              "RowID": 746
          },
          {
              "Root": "family_law",
              "Name": "Family Law",
              "StrID": "FML",
              "RowID": 1239
          },
          {
              "Root": "constitutional_law",
              "Name": "Constitutional Law",
              "StrID": "CNL",
              "RowID": 996
          },
          {
              "Root": "obligations_law",
              "Name": "Obligations Law",
              "StrID": "OBL",
              "RowID": 1672
          }
      ],
      "is_restart": 0,
      "book_path": "D:\\Colin\\_books\\",
      "thesis_path": "D:\\Colin\\_thesises\\",
      "full_screen": false
  }
  </code></pre>
  
  <p>I think, I must use <code>SubjectList</code> and <code>Subject</code> classes for reading and getting datas from JSON file. For this, I am using classes like this:</p>
  
  <pre><code>public class SubjectList
  {
      public List&lt;Subject&gt; Subjects { get; set; }
  }
  
  public class Subject
  {
      public string StrID { get; set; }
      public string Name { get; set; }
      public string Root { get; set; }
      public int RowID { get; set; }
  }
  </code></pre>
  
  <p>And finally, for getting datas, I am using code like this:</p>
  
  <pre><code>var json = JsonConvert.DeserializeObject&lt;SubjectList&gt;(File.ReadAllText("D:\\Colin\\_test\\inf.json"));
  </code></pre>
  
  <p>In the Text Template file (<code>Subjects.tt</code>), the codes are here:</p>
  
  <pre><code>&lt;#@ template debug="true" hostspecific="true" language="C#" #&gt;
  &lt;#@ assembly name="System.Core" #&gt;
  &lt;#@ assembly name="$(SolutionDir)Test\bin\Debug\Newtonsoft.Json.dll" #&gt;
  &lt;#@ import namespace="System.IO" #&gt;
  &lt;#@ import namespace="System.Linq" #&gt;
  &lt;#@ import namespace="System.Text" #&gt;
  &lt;#@ import namespace="System.Collections.Generic" #&gt;
  &lt;#@ output extension=".cs" #&gt;
  namespace Library
  {
      public class Subject
      {
          &lt;#
              var json = JsonConvert.DeserializeObject&lt;SubjectList&gt;(File.ReadAllText("D:\\Colin\\_test\\inf.json"));
          #&gt;
      }
  }
  </code></pre>
  
  <p>I'm getting the following errors without doing anything else.</p>
  
  <p><code>Compiling transformation: The name 'JsonConvert' does not exist in the current context</code></p>
  
  <p><code>Compiling transformation: The type or namespace name 'SubjectList' could not be found (are you missing a using directive or an assembly reference?)</code></p>
  
  <p>I think I have to use <code>SubjectList</code> and <code>Subject</code> classes in the <code>Subjects.tt</code> file, but I don't know how I do it. More importantly, how can I create <code>Subject.cs</code> file programmatically without getting any problem?</p>