0

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
{
}
3
Contributors
8
Replies
9
Views
8 Years
Discussion Span
Last Post by nccsbim071
0

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);
    }
}
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.

0

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.

0

I am so sorry,

I already read that.

But i was not able to figure it out.
Thanks, anyway

0

nccsbim071 ,
You solve this problem? I now have such a need.(你解决这个问题了?我现在也有这个需要的。)
My mailbox is : <<Email Snipped>>

Edited by __avd: Email Snipped.

0

y_minhua,

I wrote this post long time ago. But even then i was not able to solve this problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.