Skip to content
Discussion options

You must be logged in to vote

A record is indeed mutable at runtime. This is intentional, is it means most serializer frameworks work without updating.

It is however possible to check if a property is init by checking:

bool IsInitOnly(PropertyInfo propertyInfo)
{
    return propertyInfo.SetMethod.ReturnParameter.GetRequiredCustomModifiers().Any(x => x.FullName == typeof(System.Runtime.CompilerServices.IsExternalInit).FullName);
}

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@MgSam
Comment options

Answer selected by moh-hassan
Comment options

You must be logged in to vote
1 reply
@YairHalberstadt
Comment options

Comment options

You must be logged in to vote
2 replies
@YairHalberstadt
Comment options

@333fred
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants