DefaultValue and expandable object

  • Thread starter Thread starter Peb
  • Start date Start date
P

Peb

Hi All,

I have two properties of type PointXYZ width 2 differents default values
I would like that the default values of x, y and z properties inherite from
the default value of the object

public class PointXYZ
{
[DefaultValue(????)] //Not sure
public float X
{
get ...
set...
}

/May be
private bool ShouldSerializeX()
{
????
}
.....
}

[TypeConverter(typeof(PointXYZConverter))]
[DefaultValue(typeof(PointXYZ), "0; 0; 0")]
public PointXYZ Origin
{
get..
set..
}

[TypeConverter(typeof(PointXYZConverter))]
[DefaultValue(typeof(PointXYZ), "1; 1; 1")]
public PointXYZ End
{
get..
set..
}

All the best

Polo
 
hi Polo,
I have two properties of type PointXYZ width 2 differents default values
I would like that the default values of x, y and z properties inherite from
the default value of the object
I'm not sure, what you like to achieve.
[TypeConverter(typeof(PointXYZConverter))]
[DefaultValue(typeof(PointXYZ), "0; 0; 0")]
public PointXYZ Origin
{
get..
set..
}
Why not

private PointXYZ origin;
public PointXYZ Origin
{
get
{
if (this.origin == null)
{
this.origin = new PointXYZ() { X = 0, Y = 0, Z = 0};
}
return this.origin;
}
set
{
}
}


mfG
--> stefan <--
 
In fact, it's to show the properties inside the propertygrid with the
"regular font"

Stefan Hoffmann said:
hi Polo,
I have two properties of type PointXYZ width 2 differents default values
I would like that the default values of x, y and z properties inherite
from the default value of the object
I'm not sure, what you like to achieve.
[TypeConverter(typeof(PointXYZConverter))]
[DefaultValue(typeof(PointXYZ), "0; 0; 0")]
public PointXYZ Origin
{
get..
set..
}
Why not

private PointXYZ origin;
public PointXYZ Origin
{
get
{
if (this.origin == null)
{
this.origin = new PointXYZ() { X = 0, Y = 0, Z = 0};
}
return this.origin;
}
set
{
}
}


mfG
--> stefan <--
 
Hi All,

I have two properties of type PointXYZ  width 2 differents default values
I would like that the default values of x, y and z properties inherite from
the default value of the object

public class PointXYZ
{
    [DefaultValue(????)] //Not sure
    public float X
    {
        get ...
        set...
    }

    /May be
    private bool ShouldSerializeX()
    {
        ????
    }
    .....

}

[TypeConverter(typeof(PointXYZConverter))]
[DefaultValue(typeof(PointXYZ), "0; 0; 0")]
public PointXYZ Origin
{
get..
set..

}

[TypeConverter(typeof(PointXYZConverter))]
[DefaultValue(typeof(PointXYZ), "1; 1; 1")]
public PointXYZ End
{
get..
set..

}

Use "null" (or String.Empty, or other distinct marker value) as a
default value in DefaultValueAttribute, and change your
PointXYZConverter so that it specifically checks for that marker
value, and returns PointXYZ with fields initialized according to their
DefaultValue.
 
Back
Top