D
Dan Holmes
I have code that generates a class.
[Serializable()]
public sealed partial class ProductInfo {
private string _ProductID;
....
public virtual string ProductID {
get {
return _ProductID;
}
set {
_ProductID = value;
}
}
....
}
i can't figure out how to get the virtual off the properties. It reads
table definitions from the DB and creates the class that looks like it.
Here is the code.
CodeTypeDeclaration c = new CodeTypeDeclaration(t.Name + "Info");
c.CustomAttributes.Add(new CodeAttributeDeclaration("Serializable"));
c.IsClass = true;
c.IsPartial = true;
c.TypeAttributes = TypeAttributes.Serializable | TypeAttributes.Sealed |
TypeAttributes.Public;
foreach (Column cn in t.Columns)
{
Type ct = null;
if (cn.DataType.SqlDataType.ToString().Contains("Char") ||
cn.DataType.ToString().Contains("Text"))
ct = typeof(string);
else
ct = Type.GetType("System." + cn.DataType.SqlDataType.ToString());
CodeMemberField f = new CodeMemberField(ct, "_" + cn.Name);
f.Attributes = MemberAttributes.Private ;
c.Members.Add(f);
CodeMemberProperty p = new CodeMemberProperty();
p.Attributes = MemberAttributes.Public;
p.Name = cn.Name;
p.Type = new CodeTypeReference(ct);
p.HasGet = true;
p.GetStatements.Add(new CodeSnippetExpression("return _" + cn.Name));
p.HasSet = true;
p.SetStatements.Add(new CodeSnippetExpression("_" + cn.Name + " =
value"));
c.Members.Add(p);
}
What am i doing wrong?
dan
[Serializable()]
public sealed partial class ProductInfo {
private string _ProductID;
....
public virtual string ProductID {
get {
return _ProductID;
}
set {
_ProductID = value;
}
}
....
}
i can't figure out how to get the virtual off the properties. It reads
table definitions from the DB and creates the class that looks like it.
Here is the code.
CodeTypeDeclaration c = new CodeTypeDeclaration(t.Name + "Info");
c.CustomAttributes.Add(new CodeAttributeDeclaration("Serializable"));
c.IsClass = true;
c.IsPartial = true;
c.TypeAttributes = TypeAttributes.Serializable | TypeAttributes.Sealed |
TypeAttributes.Public;
foreach (Column cn in t.Columns)
{
Type ct = null;
if (cn.DataType.SqlDataType.ToString().Contains("Char") ||
cn.DataType.ToString().Contains("Text"))
ct = typeof(string);
else
ct = Type.GetType("System." + cn.DataType.SqlDataType.ToString());
CodeMemberField f = new CodeMemberField(ct, "_" + cn.Name);
f.Attributes = MemberAttributes.Private ;
c.Members.Add(f);
CodeMemberProperty p = new CodeMemberProperty();
p.Attributes = MemberAttributes.Public;
p.Name = cn.Name;
p.Type = new CodeTypeReference(ct);
p.HasGet = true;
p.GetStatements.Add(new CodeSnippetExpression("return _" + cn.Name));
p.HasSet = true;
p.SetStatements.Add(new CodeSnippetExpression("_" + cn.Name + " =
value"));
c.Members.Add(p);
}
What am i doing wrong?
dan