I have beed using CodeDom to generate codes. I was generating property using CodeMemberProperty. Can anybody tell me how to generate property like this:
get;
instead of
get
{
}
I have beed using CodeDom to generate codes. I was generating property using CodeMemberProperty. Can anybody tell me how to generate property like this:
get;
instead of
get
{
}
nccsbim071,
Which version of .net framework are you using? If it is 3.0 or later; It is called Auto-Implemented Properties.
Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors.
public class Student
{
public int Roll { get; set; }
public int Mark1 { get; set; }
public int Mark2 { get; set; }
public int Total { get { return Mark1 + Mark2; } }
}
class MainApp{
static void Main() {
Student a = new Student();
a.Roll = 10;
a.Mark1 = 90;
a.Mark2 = 40;
Console.WriteLine(a.Total);
}
}
I have been using .net framework 2.0
nccsbim071,
Post #2 belongs to .net framework 3.5. With .net framework 2.0 - It is called unimplemented property. If this property is declared in a class then it must qualified with an abstract modifier and hence a class becomes an abstract.
The same declaration can appear with Interface.
Yes, i did that and i got the kind of accessor i wanted, but abstract keyword appeared on property.
I want to do the same but without the abstract keyword appear on the property name.
If this can only be done in .net framework 3.5 that's ok. I will use .net framework 3.5.
But how to do that in .net framework 3.5.
What attributes should i set for
CodeMemberProperty
object to get the auto-implemented accessor.
I am so sorry,
I already read that.
But i was not able to figure it out.
Thanks, anyway
nccsbim071 ,
You solve this problem? I now have such a need.(你解决这个问题了?我现在也有这个需要的。)
My mailbox is : <<Email Snipped>>
y_minhua,
I wrote this post long time ago. But even then i was not able to solve this problem.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.