all groups > dotnet windows forms designtime > april 2004 >
You're in the

dotnet windows forms designtime

group:

Code generation question


Code generation question Victor Irzak
4/20/2004 12:18:19 PM
dotnet windows forms designtime:
Hello,

I have a class that contains a member which is accessed by get property
only.

public class B {

public int I {set; get;}
public string S {set; get;}
}

public class A {
B m_b = new b();

public B B {
get {return m_b;}
}

}

I'd like to generate code for class A without instantiating a new B object.
It should look something like this:

A a = new A();
a.B.I = 3;
a.B.S = "hehe";

I don't want the code generation to look like this:
A a = new A();
B b = new B();
b.I = 3;
b.S = "hehe";
a.B = b;


How can I do this?


TIA,


Victor


Re: Code generation question Jeremy Todd
4/20/2004 4:18:43 PM
[quoted text, click to view]


What you want to do is use the DesignerSerializationVisibility
attribute, in the System.ComponentModel namespace:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public B B {
get {return m_b;}
}

That will tell the designer to generate code persisting the contents of
the property, not assigning the entire property itself.

Jeremy
AddThis Social Bookmark Button