/// <summary> /// Returns true if <paramref name="referenceExpression"/> points to the static field or property /// with at least internal access. /// </summary> private static bool IsValidReference(IReferenceExpression referenceExpression) { Contract.Requires(referenceExpression != null); var modifiersOwner = referenceExpression .With(x => x.Reference) .With(x => x.Resolve()) .With(x => x.DeclaredElement as IModifiersOwner); if (modifiersOwner == null) { return(false); } // Supported only fields or properties if (!(modifiersOwner is IField) && !(modifiersOwner is IProperty)) { return(false); } // Checking access rights and is this stuff is static var accessRights = modifiersOwner.GetAccessRights(); if (accessRights == AccessRights.PUBLIC || accessRights == AccessRights.INTERNAL || accessRights == AccessRights.PROTECTED_OR_INTERNAL) { if (modifiersOwner.IsStatic) { return(true); } } return(false); }