private static MethodAttributes GetAttributesOfMostAccessibleMethod(PropertyDefinition property)
{
// There should always be at least one method from which to
// obtain the result, but the compiler doesn't know this so
// initialize the result with a default value
MethodAttributes result = (MethodAttributes)0;
// Method access is defined from inaccessible (lowest) to public (highest)
// in numeric order, so we can do an integer comparison of the masked attribute
int accessLevel = 0;
if (property.GetMethod != null)
{
int methodAccessLevel = (int)(property.GetMethod.Attributes & MethodAttributes.MemberAccessMask);
if (accessLevel < methodAccessLevel)
{
accessLevel = methodAccessLevel;
result = property.GetMethod.Attributes;
}
}
if (property.SetMethod != null)
{
int methodAccessLevel = (int)(property.SetMethod.Attributes & MethodAttributes.MemberAccessMask);
if (accessLevel < methodAccessLevel)
{
accessLevel = methodAccessLevel;
result = property.SetMethod.Attributes;
}
}
if (property.HasOtherMethods)
{
foreach (var m in property.OtherMethods)
{
int methodAccessLevel = (int)(m.Attributes & MethodAttributes.MemberAccessMask);
if (accessLevel < methodAccessLevel)
{
accessLevel = methodAccessLevel;
result = m.Attributes;
}
}
}
return result;
}