public static bool IsVariable(this MemberInfo memberInfo, VariableInfoDescriptor variableInfoDescriptor) { if (!MemberInfoTools.IsVariable(memberInfo)) { return(false); } var isIncludedByAttributeTypes = variableInfoDescriptor.IncludeByAttributeTypes == null || variableInfoDescriptor.IncludeByAttributeTypes.All(attrType => memberInfo.IsDefined(attrType, variableInfoDescriptor.IncludeByAttributeTypesInherit)); var notExcludedByAttributeTypes = !(variableInfoDescriptor.ExcludeByAttributeTypes != null && variableInfoDescriptor.ExcludeByAttributeTypes.Any(attrType => memberInfo.IsDefined(attrType, variableInfoDescriptor.ExcludeByAttributeTypesInherit))); if (memberInfo is FieldInfo fieldInfo) { return(isIncludedByAttributeTypes && notExcludedByAttributeTypes); } else if (memberInfo is PropertyInfo propertyInfo) { return((!variableInfoDescriptor.IncludeIfReadable || propertyInfo.CanRead) && (!variableInfoDescriptor.IncludeIfWritable || propertyInfo.CanWrite) && isIncludedByAttributeTypes && !(variableInfoDescriptor.ExcludeIfReadable && propertyInfo.CanRead) && !(variableInfoDescriptor.ExcludeIfWritable && propertyInfo.CanWrite) && notExcludedByAttributeTypes); } return(false); }
/// <param name="memberInfo">Pass <see cref="PropertyInfo"/> or <see cref="FieldInfo"/>.</param> public static bool TryGetAttributeVariableMember(this MemberInfo memberInfo, Type attributeType, [MaybeNull] out AttributeMemberInfo attrVarInfo, bool?getCustomAttributesInherit = null) { bool _getCustomAttributesInherit = getCustomAttributesInherit ?? true; // Library.DefaultCustomAttributesInherit if (!MemberInfoTools.IsVariable(memberInfo, attributeType, _getCustomAttributesInherit)) { attrVarInfo = null; return(false); } attrVarInfo = GetAttributeVariableMember(memberInfo, attributeType, getCustomAttributesInherit); return(true); }
/// <param name="memberInfo">Pass <see cref="PropertyInfo"/> or <see cref="FieldInfo"/>.</param> public static bool TryGetAttributeVariableMember <T>(this MemberInfo memberInfo, [MaybeNull] out AttributeMemberInfo <T> attrVarInfo, bool?getCustomAttributesInherit = null) where T : Attribute { bool _getCustomAttributesInherit = getCustomAttributesInherit ?? true; // Library.DefaultCustomAttributesInherit if (!MemberInfoTools.IsVariable(memberInfo, typeof(T), _getCustomAttributesInherit)) { attrVarInfo = null; return(false); } attrVarInfo = GetAttributeVariableMember <T>(memberInfo, getCustomAttributesInherit); return(true); }
/// <param name="memberInfo">Pass <see cref="PropertyInfo"/> or <see cref="FieldInfo"/>.</param> public static AttributeMemberInfo GetAttributeVariableMember(this MemberInfo memberInfo, Type attributeType, bool?getCustomAttributesInherit = null) { MemberInfoTools.CheckedAttributeVariable(memberInfo, attributeType); return(new AttributeMemberInfo(memberInfo, attributeType, getCustomAttributesInherit)); }
/// <param name="memberInfo">Pass <see cref="PropertyInfo"/> or <see cref="FieldInfo"/>.</param> public static AttributeMemberInfo <T> GetAttributeVariableMember <T>(this MemberInfo memberInfo, bool?getCustomAttributesInherit = null) where T : Attribute { MemberInfoTools.CheckedAttributeVariable(memberInfo, typeof(T)); return(new AttributeMemberInfo <T>(memberInfo, getCustomAttributesInherit)); }
public static object?GetValue(this MemberInfo memberInfo, object owner) => MemberInfoTools.GetValue(memberInfo, owner);
public static bool IsVariable(this MemberInfo memberInfo, Type attributeType, bool getCustomAttributesInherit) => MemberInfoTools.IsVariable(memberInfo, attributeType, getCustomAttributesInherit);
public static bool IsVariable(this MemberInfo memberInfo) => MemberInfoTools.IsVariable(memberInfo);
public static Type GetVariableType(this MemberInfo memberInfo) => MemberInfoTools.GetVariableType(memberInfo);
public static bool IsFieldOrProperty(this MemberInfo memberInfo) => MemberInfoTools.IsFieldOrProperty(memberInfo);
public static void SetValue(this MemberInfo memberInfo, object owner, object?value) => MemberInfoTools.SetValue(memberInfo, owner, value);