Skip to content

Instantly share code, notes, and snippets.

View jiripolasek's full-sized avatar
🧙
Making world a better place

Jiří "Wizard" Polášek jiripolasek

🧙
Making world a better place
View GitHub Profile
@jiripolasek
jiripolasek / ReflectionExtensions.cs
Last active November 23, 2020 04:45
Detect init-only property using reflection
public static class ReflectionExtensions
{
/// <summary>
/// Gets a value indicating whether property has init accessor declared.
/// </summary>
/// <param name="propertyInfo"></param>
/// <returns>Returns <c>true</c> if the property is declared as init-only; otherwise returns <c>false</c>.</returns>
public static bool IsInitOnly(this PropertyInfo propertyInfo)
{
if (propertyInfo == null)