Reputation: 2203
string myClass =" public class AcademicTestQuestion { public int Id { get; set; } public string Content { get; set; } public int ContentType { get; set; } public string Descrtionption { get; set; } public bool IsMandatory { get; set; } public bool IsMultiChoice { get; set; } public DateTime InsertDate { get; set; } public DateTime? UpdateDate { get; set; } public bool IsActive { get; set; } public int AcademicTestPageId { get; set; } } ";
for readability formatted below
string myClass ="
public class AcademicTestQuestion
{
public int Id { get; set; }
public string Content { get; set; }
public int ContentType { get; set; }
public string Descrtionption { get; set; }
public bool IsMandatory { get; set; }
public bool IsMultiChoice { get; set; }
public DateTime InsertDate { get; set; }
public DateTime? UpdateDate { get; set; }
public bool IsActive { get; set; }
public int AcademicTestPageId { get; set; }
}
";
How can i create a instance of above string representation of class at run time and use?
I'm trying to generating the table structure in to classes at run time.
Upvotes: 1
Views: 100
Reputation: 62129
You cannot do that at runtime unless you have the C# SDK installed.
Which is kind of tricky, because you, as a developer, will generally have the C# SDK installed, so to you it will appear to work, but if you deploy your application to users, the users will generally only have the DotNet runtime environment installed, but not the SDK, so it will not work for them.
If you insist on doing this, begin reading here:
MSDN - System.Runtime.CompilerServices Namespace
Upvotes: 2