diff --git a/PInvoke/SetupAPI/DevPropDef.cs b/PInvoke/SetupAPI/DevPropDef.cs index 5320e25d..6534578f 100644 --- a/PInvoke/SetupAPI/DevPropDef.cs +++ b/PInvoke/SetupAPI/DevPropDef.cs @@ -839,16 +839,32 @@ namespace Vanara.PInvoke /// Performs a lookup of this against defined values in this assembly to find a name. /// The name, if found, otherwise . - public string LookupName() + public string LookupName() => Lookup()?.Name; + + /// + public override string ToString() => LookupName() ?? $"{fmtid}:{pid}"; + + /// + /// Tries to determine if the property is read-only by performing a reverse lookup on known keys and, if found, reading its attributes. + /// + /// if set to , the property is known to be read-only. + /// If , the known key was found and the output is valid. + public bool TryGetReadOnly(out bool readOnly) + { + readOnly = false; + var fi = Lookup(); + if (fi is null) return false; + readOnly = !fi.GetCustomAttributes(typeof(CorrespondingTypeAttribute), false).Cast().Any(a => a.Action.IsFlagSet(CorrespondingAction.Set)); + return true; + } + + private System.Reflection.FieldInfo Lookup() { var dpkType = GetType(); var lthis = this; return dpkType.DeclaringType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static). - Where(fi => fi.FieldType == dpkType && lthis.Equals(fi.GetValue(null))).Select(fi => fi.Name).FirstOrDefault(); + Where(fi => fi.FieldType == dpkType && lthis.Equals(fi.GetValue(null))).FirstOrDefault(); } - - /// - public override string ToString() => LookupName() ?? $"{fmtid}:{pid}"; } } } \ No newline at end of file