-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore members with default values #89
Comments
@eiriktsarpalis One of your test cases in the exhaustive set fail when I turn this setting on, because it sets a bunch of default values explicitly. And no public record RecordWithSpecialValueDefaultParams(double d1 = double.PositiveInfinity, double d2 = double.NegativeInfinity, double d3 = double.NaN, double? dn1 = double.PositiveInfinity, double? dn2 = double.NegativeInfinity, double? dn3 = double.NaN, float f1 = float.PositiveInfinity, float f2 = float.NegativeInfinity, float f3 = float.NaN, float? fn1 = float.PositiveInfinity, float? fn2 = float.NegativeInfinity, float? fn3 = float.NaN, string s = "\"\ud83d\ude00葛\ud83c\udc04\r\n\ud83e\udd2f\ud801\udc00\ud801\udc28\"", char c = '\'') : IShapeable<RecordWithSpecialValueDefaultParams> It looks like your source generated |
I'm not sure I entirely follow the requirement, but is it that you need getters exposed on the argument state type? What about comparing against |
That would be awesome. Except there is no such property. You link to IConstructorParameterShape, which does have that property. I hadn't noticed that and I can and should use that. But for the properties that are not on the constructor (and/or types with a default constructor and no [GenerateShape]
partial class A
{
public int Age { get; set; } = 18;
public int Field = 15;
} |
Now, default parameters are limited to values that C# can express as constants, whereas property and field initializers are allowed to be any runtime-constructible value. However, we know that these initializers are limited in that they cannot access A simpler scope for the fix would be to start with only supporting literal expressions in field and property initializers. But that's more limited even than 'any constant expression' that default parameters can specify... |
Although, I guess field and property initializers not being supported and instead asking users to apply a |
The second most voted feature request on MessagePack-CSharp requests for reducing serialized payloads by omitting properties with default values.
This most readily makes sense when serializing objects as maps, where the property name can be dropped along with the 0/nil value which itself is just one byte. When the object is serialized as an array of values, serialization payload savings are only feasible if they happen to all be at the end of the array such that the array can be truncated.
Default values could potentially be different than
default(TPropertyType)
, since the object constructor can initialize these fields to other values. Respecting[DefaultValueAttribute(value)]
seems like a no-brainer.Another option would be a property naming pattern where property X does not serialize if property
ShouldXSerialize
returnsfalse
, which gives ultimate runtime support for controlling what gets serialized.CC: @eiriktsarpalis
The text was updated successfully, but these errors were encountered: