If I declare a struct like this:
public record struct MyStruct(bool MyValue);
and then look at the decompiled source, it looks like this:
public struct MyStruct : IEquatable<MyStruct>
{
[CompilerGenerated]
private bool <MyValue>k__BackingField;
public bool MyValue
{
[IsReadOnly]
[CompilerGenerated]
get
{
return <MyValue>k__BackingField;
}
[CompilerGenerated]
set
{
<MyValue>k__BackingField = value;
}
}
public MyStruct(bool MyValue)
{
<MyValue>k__BackingField = myValue;
}
<etc>
How do I prevent the compiler from adding the set to MyValue property?
I would expect that changing it to:
public record struct MyStruct(in bool myValue);
would indicate that I want it to be readonly but this doesn't seem to make a difference
readonly record struct.