mardi 5 décembre 2017

Why do reflection of struct's properties, the reflected property's CanWrite is always false even I have set method?

Why do reflection of struct's properties, the reflected property's CanWrite is always false even I have set method?

The struct is like below:

public struct Point
{
    public int X { get; set; }

    public int Y { get; set; }
}

The reflection code is like below: var propsAll = typeof(Point).GetProperties(BindingFlags.Instance | BindingFlags.Public);

var props = new List<PropertyInfo>();
foreach (var prop in propsAll)
{
    if (prop.CanWrite)   // always false
    {
        props.Add(prop);
    }
}





Aucun commentaire:

Enregistrer un commentaire