internal PropertySymbol GetLeastOverriddenProperty(NamedTypeSymbol accessingTypeOpt) { var accessingType = ((object)accessingTypeOpt == null ? this.ContainingType : accessingTypeOpt).OriginalDefinition; PropertySymbol p = this; while (p.IsOverride && !p.HidesBasePropertiesByName) { // We might not be able to access the overridden method. For example, // // .assembly A // { // InternalsVisibleTo("B") // public class A { internal virtual int P { get; } } // } // // .assembly B // { // InternalsVisibleTo("C") // public class B : A { internal override int P { get; } } // } // // .assembly C // { // public class C : B { ... new B().P ... } // A.P is not accessible from here // } // // See InternalsVisibleToAndStrongNameTests: IvtVirtualCall1, IvtVirtualCall2, IvtVirtual_ParamsAndDynamic. PropertySymbol overridden = p.OverriddenProperty; HashSet <DiagnosticInfo> useSiteDiagnostics = null; if ((object)overridden == null || !AccessCheck.IsSymbolAccessible(overridden, accessingType, ref useSiteDiagnostics)) { break; } p = overridden; } return(p); }
/// <summary> /// Returns the original virtual or abstract method which a given method symbol overrides, /// ignoring any other overriding methods in base classes. /// </summary> /// <param name="accessingTypeOpt">The search must respect accessibility from this type.</param> internal MethodSymbol GetLeastOverriddenMethod(NamedTypeSymbol accessingTypeOpt) { var accessingType = ((object)accessingTypeOpt == null ? this.ContainingType : accessingTypeOpt).OriginalDefinition; MethodSymbol m = this; while (m.IsOverride && !m.HidesBaseMethodsByName) { // We might not be able to access the overridden method. For example, // // .assembly A // { // InternalsVisibleTo("B") // public class A { internal virtual void M() { } } // } // // .assembly B // { // InternalsVisibleTo("C") // public class B : A { internal override void M() { } } // } // // .assembly C // { // public class C : B { ... new B().M ... } // A.M is not accessible from here // } // // See InternalsVisibleToAndStrongNameTests: IvtVirtualCall1, IvtVirtualCall2, IvtVirtual_ParamsAndDynamic. MethodSymbol overridden = m.OverriddenMethod; HashSet <DiagnosticInfo> useSiteDiagnostics = null; if ((object)overridden == null || !AccessCheck.IsSymbolAccessible(overridden, accessingType, ref useSiteDiagnostics)) { break; } m = overridden; } return(m); }
internal EventSymbol GetLeastOverriddenEvent(NamedTypeSymbol accessingTypeOpt) { var accessingType = ((object)accessingTypeOpt == null ? this.ContainingType : accessingTypeOpt).OriginalDefinition; EventSymbol e = this; while (e.IsOverride && !e.HidesBaseEventsByName) { // NOTE: We might not be able to access the overridden event. For example, // // .assembly A // { // InternalsVisibleTo("B") // public class A { internal virtual event Action E { add; remove; } } // } // // .assembly B // { // InternalsVisibleTo("C") // public class B : A { internal override event Action E { add; remove; } } // } // // .assembly C // { // public class C : B { ... new B().E += null ... } // A.E is not accessible from here // } // // See InternalsVisibleToAndStrongNameTests: IvtVirtualCall1, IvtVirtualCall2, IvtVirtual_ParamsAndDynamic. EventSymbol overridden = e.OverriddenEvent; HashSet <DiagnosticInfo> useSiteDiagnostics = null; if ((object)overridden == null || !AccessCheck.IsSymbolAccessible(overridden, accessingType, ref useSiteDiagnostics)) { break; } e = overridden; } return(e); }
private void CheckModifiers(Location location, bool hasBody, bool isAutoPropertyOrExpressionBodied, DiagnosticBag diagnostics) { // Check accessibility against the accessibility declared on the accessor not the property. var localAccessibility = this.LocalAccessibility; if (IsAbstract && !ContainingType.IsAbstract && (ContainingType.TypeKind == TypeKind.Class || ContainingType.TypeKind == TypeKind.Submission)) { // '{0}' is abstract but it is contained in non-abstract class '{1}' diagnostics.Add(ErrorCode.ERR_AbstractInConcreteClass, location, this, ContainingType); } else if (IsVirtual && ContainingType.IsSealed && ContainingType.TypeKind != TypeKind.Struct) // error CS0106 on struct already { // '{0}' is a new virtual member in sealed class '{1}' diagnostics.Add(ErrorCode.ERR_NewVirtualInSealed, location, this, ContainingType); } else if (!hasBody && !IsExtern && !IsAbstract && !isAutoPropertyOrExpressionBodied) { diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } else if (ContainingType.IsSealed && localAccessibility.HasProtected() && !this.IsOverride) { diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this); } else if (LocalDeclaredReadOnly && _property.HasReadOnlyModifier) { // Cannot specify 'readonly' modifiers on both property or indexer '{0}' and its accessors. diagnostics.Add(ErrorCode.ERR_InvalidPropertyReadOnlyMods, location, _property); } else if (LocalDeclaredReadOnly && IsStatic) { // Static member '{0}' cannot be marked 'readonly'. diagnostics.Add(ErrorCode.ERR_StaticMemberCantBeReadOnly, location, this); } else if (LocalDeclaredReadOnly && _isAutoPropertyAccessor && MethodKind == MethodKind.PropertySet) { // Auto-implemented accessor '{0}' cannot be marked 'readonly'. diagnostics.Add(ErrorCode.ERR_AutoSetterCantBeReadOnly, location, this); } }
public void AccessPaths() { AccessCheck ac = new AccessCheck(); List <string> ids = new List <string>() { "fw.de.he.da.mkk.mtl", "fw.de.he.da.mkk.nid" }; List <EmergenyObjectAccessContainer> acl = new List <EmergenyObjectAccessContainer>(); var oa = new EmergenyObjectAccessContainer("fw.de.he.da.mkk"); oa.AddAccessRight("stamm", AccessLevelEnum.Read); oa.AddAccessRight("status", AccessLevelEnum.Read); oa.AddAccessRight("*", AccessLevelEnum.Read); acl.Add(oa); var res = ac.GetPathsByAccessLevel(AccessLevelEnum.Read, ids, acl); Assert.Contains <string>("*", res); }
protected void ReportModifiersDiagnostics(DiagnosticBag diagnostics) { if (ContainingType.IsSealed && this.DeclaredAccessibility.HasProtected()) { diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(containingType), ErrorLocation, this); } else if (IsVolatile && IsReadOnly) { diagnostics.Add(ErrorCode.ERR_VolatileAndReadonly, ErrorLocation, this); } else if (containingType.IsStatic && !IsStatic) { diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, ErrorLocation, this); } else if (!IsStatic && !IsReadOnly && containingType.IsReadOnly) { diagnostics.Add(ErrorCode.ERR_FieldsInRoStruct, ErrorLocation); } // TODO: Consider checking presence of core type System.Runtime.CompilerServices.IsVolatile // if there is a volatile modifier. Perhaps an appropriate error should be reported if the // type isn't available. }
/// <summary> /// Checks if 'symbol' is accessible from within named type 'within'. If 'symbol' is accessed off /// of an expression then 'throughTypeOpt' is the type of that expression. This is needed to /// properly do protected access checks. /// </summary> public static bool IsSymbolAccessible( Symbol symbol, NamedTypeSymbol within, NamedTypeSymbol throughTypeOpt = null) { if ((object)symbol == null) { throw new ArgumentNullException(nameof(symbol)); } if ((object)within == null) { throw new ArgumentNullException(nameof(within)); } HashSet <DiagnosticInfo> useSiteDiagnostics = null; return(AccessCheck.IsSymbolAccessible( symbol, within, ref useSiteDiagnostics, throughTypeOpt)); }
private void CheckModifiers(Location location, bool hasBody, bool isAutoPropertyOrExpressionBodied, DiagnosticBag diagnostics) { // Check accessibility against the accessibility declared on the accessor not the property. var localAccessibility = this.LocalAccessibility; if (IsAbstract && !ContainingType.IsAbstract && (ContainingType.TypeKind == TypeKind.Class || ContainingType.TypeKind == TypeKind.Submission)) { // '{0}' is abstract but it is contained in non-abstract class '{1}' diagnostics.Add(ErrorCode.ERR_AbstractInConcreteClass, location, this, ContainingType); } else if (IsVirtual && ContainingType.IsSealed && ContainingType.TypeKind != TypeKind.Struct) // error CS0106 on struct already { // '{0}' is a new virtual member in sealed class '{1}' diagnostics.Add(ErrorCode.ERR_NewVirtualInSealed, location, this, ContainingType); } else if (!hasBody && !IsExtern && !IsAbstract && !isAutoPropertyOrExpressionBodied) { diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } else if (ContainingType.IsSealed && localAccessibility.HasProtected() && !this.IsOverride) { diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this); } }
protected void CheckModifiersAndType(DiagnosticBag diagnostics) { Location location = this.Locations[0]; HashSet <DiagnosticInfo> useSiteDiagnostics = null; if (this.DeclaredAccessibility == Accessibility.Private && (IsVirtual || IsAbstract || IsOverride)) { diagnostics.Add(ErrorCode.ERR_VirtualPrivate, location, this); } else if (IsStatic && (IsOverride || IsVirtual || IsAbstract)) { // A static member '{0}' cannot be marked as override, virtual, or abstract diagnostics.Add(ErrorCode.ERR_StaticNotVirtual, location, this); } else if (IsOverride && (IsNew || IsVirtual)) { // A member '{0}' marked as override cannot be marked as new or virtual diagnostics.Add(ErrorCode.ERR_OverrideNotNew, location, this); } else if (IsSealed && !IsOverride) { // '{0}' cannot be sealed because it is not an override diagnostics.Add(ErrorCode.ERR_SealedNonOverride, location, this); } else if (IsAbstract && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.AbstractKeyword)); } else if (IsVirtual && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.VirtualKeyword)); } else if (IsAbstract && IsExtern) { diagnostics.Add(ErrorCode.ERR_AbstractAndExtern, location, this); } else if (IsAbstract && IsSealed) { diagnostics.Add(ErrorCode.ERR_AbstractAndSealed, location, this); } else if (IsAbstract && IsVirtual) { diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this.Kind.Localize(), this); } else if (ContainingType.IsSealed && this.DeclaredAccessibility.HasProtected() && !this.IsOverride) { diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this); } else if (ContainingType.IsStatic && !IsStatic) { diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, location, Name); } else if (this.Type.SpecialType == SpecialType.System_Void) { // Diagnostic reported by parser. } else if (!this.IsNoMoreVisibleThan(this.Type, ref useSiteDiagnostics)) { // Dev10 reports different errors for field-like events (ERR_BadVisFieldType) and custom events (ERR_BadVisPropertyType). // Both seem odd, so add a new one. diagnostics.Add(ErrorCode.ERR_BadVisEventType, location, this, this.Type); } else if (!this.Type.IsDelegateType() && !this.Type.IsErrorType()) { // Suppressed for error types. diagnostics.Add(ErrorCode.ERR_EventNotDelegate, location, this); } else if (IsAbstract && !ContainingType.IsAbstract && (ContainingType.TypeKind == TypeKind.Class || ContainingType.TypeKind == TypeKind.Submission)) { // '{0}' is abstract but it is contained in non-abstract class '{1}' diagnostics.Add(ErrorCode.ERR_AbstractInConcreteClass, location, this, ContainingType); } else if (IsVirtual && ContainingType.IsSealed) { // '{0}' is a new virtual member in sealed class '{1}' diagnostics.Add(ErrorCode.ERR_NewVirtualInSealed, location, this, ContainingType); } diagnostics.Add(location, useSiteDiagnostics); }
/// <summary> /// Performs an iterative lookup of the given path starting from the root and obeying to the specified flags. /// </summary> /// <param name="path">The path to lookup. This can be a relative or absolute path. Path.DirectorySeparatorChar or Path.AltDirectorySeparatorChar are valid delimiters.</param> /// <param name="flags">The lookup flags, which control the lookup process.</param> /// <returns>The directory entry of the resolved path.</returns> /// <exception cref="System.Security.SecurityException">The caller does not have access to the path or a component. For example the caller does not have the right to traverse the path.</exception> /// <exception cref="System.IO.PathTooLongException">The path is too long to traverse. This can be the result of circular symbolic links in the path.</exception> /// <exception cref="System.IO.FileNotFoundException">The path or a component was not found. This exception can be prevented by specifying PathResolutionFlags.DoNotThrowNotFoundException.</exception> /// <exception cref="System.IO.DirectoryNotFoundException">A path component was not found. This exception can be prevented by specifying PathResolutionFlags.DoNotThrowNotFoundException.</exception> /// <remarks> /// This call may result in other exceptions not specified in the above list. Other exceptions can be thrown by IVfsNode implementations, which are visited during the traversal /// process. For example a network file system node may throw an exception, if the server is unreachable. /// </remarks> private DirectoryEntry Resolve(ref string path, PathResolutionFlags flags) { // DirectoryNode entry found by stepping through the path DirectoryEntry entry = null; // Split the given path to its components PathSplitter dirs = new PathSplitter(path); // Determine the number of path components int max = dirs.Length; // Current path component string item; // Loop index int index = 0; // Perform an access check on the root directory AccessCheck.Perform(currentDirectory, AccessMode.Traverse, AccessCheckFlags.None); // Do not resolve the last name, if we want the parent directory. if (PathResolutionFlags.RetrieveParent == (flags & PathResolutionFlags.RetrieveParent)) { path = dirs[dirs.Length - 1]; max--; } // Check if this is an absolute path? if (dirs[0].Length == 0) { // Yes, replace the current directory currentDirectory = rootDirectory; index++; } // Iterate over the remaining path components while ((currentDirectory != null) && (index < max)) { item = dirs[index]; entry = null; if (currentDirectory.Node.NodeType == VfsNodeType.SymbolicLink) { SymbolicLinkNode link = (SymbolicLinkNode)currentDirectory.Node; if (0 != depth--) { // The symlink stores a relative path, use it for a current relative lookup. string target = link.Target; // Build a new flags set for symlink lookups, as we do not want all of them. PathResolutionFlags symflags = (flags & PathResolutionFlags.SymLinkLookupSafe); entry = Resolve(ref target, symflags); } else { if (PathResolutionFlags.DoNotThrowNotFoundException != (PathResolutionFlags.DoNotThrowNotFoundException & flags)) { // FIXME: Provide a MUI resource string for the exception #if VFS_EXCEPTIONS throw new PathTooLongException(); #endif // #if !VFS_EXCEPTIONS } } } else { // Pass the lookup to the DirectoryEntry (and ultimately to the inode itself.) entry = currentDirectory.Lookup(item); // If lookup in the directory entry failed, ask the real INode to perform the lookup. if (entry == null) { IVfsNode node = currentDirectory.Node.Lookup(item); if (node != null) { entry = DirectoryEntry.Allocate(currentDirectory, item, node); } } } // Increment the path component index index++; // Check if we have a new path component? if ((entry == null) && (PathResolutionFlags.DoNotThrowNotFoundException != (PathResolutionFlags.DoNotThrowNotFoundException & flags))) { // FIXME: Move exception messages to MUI resources #if VFS_EXCEPTIONS if (index == max) { throw new FileNotFoundException(@"Failed to resolve the path.", path); } else { throw new DirectoryNotFoundException(@"Failed to resolve the path."); } #endif // #if VFS_EXCEPTIONS } // Set the current resolution directory currentDirectory = entry; // Check if the caller has traverse access to the directory AccessCheck.Perform(currentDirectory, AccessMode.Traverse, AccessCheckFlags.None); } return(currentDirectory); }
private static Symbol FindExplicitlyImplementedMember( Symbol implementingMember, TypeSymbol explicitInterfaceType, string interfaceMemberName, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifierSyntax, DiagnosticBag diagnostics) { if ((object)explicitInterfaceType == null) { return(null); } var memberLocation = implementingMember.Locations[0]; var containingType = implementingMember.ContainingType; switch (containingType.TypeKind) { case TypeKind.Class: case TypeKind.Struct: case TypeKind.Interface: break; default: diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationInNonClassOrStruct, memberLocation, implementingMember); return(null); } if (!explicitInterfaceType.IsInterfaceType()) { //we'd like to highlight just the type part of the name var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name; var location = new SourceLocation(explicitInterfaceSyntax); diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationNotInterface, location, explicitInterfaceType); return(null); } var explicitInterfaceNamedType = (NamedTypeSymbol)explicitInterfaceType; // 13.4.1: "For an explicit interface member implementation to be valid, the class or struct must name an // interface in its base class list that contains a member ..." MultiDictionary <NamedTypeSymbol, NamedTypeSymbol> .ValueSet set = containingType.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics[explicitInterfaceNamedType]; int setCount = set.Count; if (setCount == 0 || !set.Contains(explicitInterfaceNamedType, Symbols.SymbolEqualityComparer.ObliviousNullableModifierMatchesAny)) { //we'd like to highlight just the type part of the name var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name; var location = new SourceLocation(explicitInterfaceSyntax); if (setCount > 0 && set.Contains(explicitInterfaceNamedType, Symbols.SymbolEqualityComparer.IgnoringNullable)) { diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInExplicitlyImplementedInterface, location); } else { diagnostics.Add(ErrorCode.ERR_ClassDoesntImplementInterface, location, implementingMember, explicitInterfaceNamedType); } //do a lookup anyway } // Do not look in itself if (containingType == (object)explicitInterfaceNamedType.OriginalDefinition) { // An error will be reported elsewhere. // Either the interface is not implemented, or it causes a cycle in the interface hierarchy. return(null); } var hasParamsParam = implementingMember.HasParamsParameter(); // Setting this flag to true does not imply that an interface member has been successfully implemented. // It just indicates that a corresponding interface member has been found (there may still be errors). var foundMatchingMember = false; Symbol implementedMember = null; foreach (Symbol interfaceMember in explicitInterfaceNamedType.GetMembers(interfaceMemberName)) { // At this point, we know that explicitInterfaceNamedType is an interface. // However, metadata interface members can be static - we ignore them, as does Dev10. if (interfaceMember.Kind != implementingMember.Kind || !interfaceMember.IsImplementableInterfaceMember()) { continue; } if (MemberSignatureComparer.ExplicitImplementationComparer.Equals(implementingMember, interfaceMember)) { foundMatchingMember = true; // Cannot implement accessor directly unless // the accessor is from an indexed property. if (interfaceMember.IsAccessor() && !((MethodSymbol)interfaceMember).IsIndexedPropertyAccessor()) { diagnostics.Add(ErrorCode.ERR_ExplicitMethodImplAccessor, memberLocation, implementingMember, interfaceMember); } else { if (interfaceMember.MustCallMethodsDirectly()) { diagnostics.Add(ErrorCode.ERR_BogusExplicitImpl, memberLocation, implementingMember, interfaceMember); } else if (hasParamsParam && !interfaceMember.HasParamsParameter()) { // Note: no error for !hasParamsParam && interfaceMethod.HasParamsParameter() // Still counts as an implementation. diagnostics.Add(ErrorCode.ERR_ExplicitImplParams, memberLocation, implementingMember, interfaceMember); } implementedMember = interfaceMember; break; } } } if (!foundMatchingMember) { // CONSIDER: we may wish to suppress this error in the event that another error // has been reported about the signature. diagnostics.Add(ErrorCode.ERR_InterfaceMemberNotFound, memberLocation, implementingMember); } // Make sure implemented member is accessible if ((object)implementedMember != null) { HashSet <DiagnosticInfo> useSiteDiagnostics = null; if (!AccessCheck.IsSymbolAccessible(implementedMember, implementingMember.ContainingType, ref useSiteDiagnostics, throughTypeOpt: null)) { diagnostics.Add(ErrorCode.ERR_BadAccess, memberLocation, implementedMember); } else { switch (implementedMember.Kind) { case SymbolKind.Property: var propertySymbol = (PropertySymbol)implementedMember; checkAccessorIsAccessibleIfImplementable(propertySymbol.GetMethod); checkAccessorIsAccessibleIfImplementable(propertySymbol.SetMethod); break; case SymbolKind.Event: var eventSymbol = (EventSymbol)implementedMember; checkAccessorIsAccessibleIfImplementable(eventSymbol.AddMethod); checkAccessorIsAccessibleIfImplementable(eventSymbol.RemoveMethod); break; } void checkAccessorIsAccessibleIfImplementable(MethodSymbol accessor) { if (accessor.IsImplementable() && !AccessCheck.IsSymbolAccessible(accessor, implementingMember.ContainingType, ref useSiteDiagnostics, throughTypeOpt: null)) { diagnostics.Add(ErrorCode.ERR_BadAccess, memberLocation, accessor); } } } diagnostics.Add(memberLocation, useSiteDiagnostics); } return(implementedMember); }
private void CheckModifiers(Location location, DiagnosticBag diagnostics) { const DeclarationModifiers partialMethodInvalidModifierMask = (DeclarationModifiers.AccessibilityMask & ~DeclarationModifiers.Private) | DeclarationModifiers.Virtual | DeclarationModifiers.Abstract | DeclarationModifiers.Override | DeclarationModifiers.New | DeclarationModifiers.Sealed | DeclarationModifiers.Extern; if (IsPartial && !ReturnsVoid) { diagnostics.Add(ErrorCode.ERR_PartialMethodMustReturnVoid, location); } else if (IsPartial && !ContainingType.IsInterface && (DeclarationModifiers & partialMethodInvalidModifierMask) != 0) { diagnostics.Add(ErrorCode.ERR_PartialMethodInvalidModifier, location); } else if (this.DeclaredAccessibility == Accessibility.Private && (IsVirtual || IsAbstract || IsOverride)) { diagnostics.Add(ErrorCode.ERR_VirtualPrivate, location, this); } else if (IsStatic && (IsOverride || IsVirtual || IsAbstract)) { // A static member '{0}' cannot be marked as override, virtual, or abstract diagnostics.Add(ErrorCode.ERR_StaticNotVirtual, location, this); } else if (IsOverride && (IsNew || IsVirtual)) { // A member '{0}' marked as override cannot be marked as new or virtual diagnostics.Add(ErrorCode.ERR_OverrideNotNew, location, this); } else if (IsSealed && !IsOverride) { // '{0}' cannot be sealed because it is not an override diagnostics.Add(ErrorCode.ERR_SealedNonOverride, location, this); } else if (IsSealed && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.SealedKeyword)); } else if (!ContainingType.IsInterfaceType() && _lazyReturnType.IsStatic) { // '{0}': static types cannot be used as return types diagnostics.Add(ErrorCode.ERR_ReturnTypeIsStaticClass, location, _lazyReturnType); } else if (IsAbstract && IsExtern) { diagnostics.Add(ErrorCode.ERR_AbstractAndExtern, location, this); } else if (IsAbstract && IsSealed) { diagnostics.Add(ErrorCode.ERR_AbstractAndSealed, location, this); } else if (IsAbstract && IsVirtual) { diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this); } else if (IsAbstract && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.AbstractKeyword)); } else if (IsVirtual && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.VirtualKeyword)); } else if (IsAbstract && !ContainingType.IsAbstract && (ContainingType.TypeKind == TypeKind.Class || ContainingType.TypeKind == TypeKind.Submission)) { // '{0}' is abstract but it is contained in non-abstract class '{1}' diagnostics.Add(ErrorCode.ERR_AbstractInConcreteClass, location, this, ContainingType); } else if (IsVirtual && ContainingType.IsSealed) { // '{0}' is a new virtual member in sealed class '{1}' diagnostics.Add(ErrorCode.ERR_NewVirtualInSealed, location, this, ContainingType); } else if (bodySyntaxReferenceOpt == null && IsAsync) { diagnostics.Add(ErrorCode.ERR_BadAsyncLacksBody, location); } else if (bodySyntaxReferenceOpt == null && !IsExtern && !IsAbstract && !IsPartial && !IsExpressionBodied) { diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } else if (ContainingType.IsSealed && this.DeclaredAccessibility.HasProtected() && !this.IsOverride) { diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this); } else if (ContainingType.IsStatic && !IsStatic) { diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, location, Name); } else if (_lazyIsVararg && (IsGenericMethod || ContainingType.IsGenericType || _lazyParameters.Length > 0 && _lazyParameters[_lazyParameters.Length - 1].IsParams)) { diagnostics.Add(ErrorCode.ERR_BadVarargs, location); } else if (_lazyIsVararg && IsAsync) { diagnostics.Add(ErrorCode.ERR_VarargsAsync, location); } }
private void CheckModifiers(bool isExplicitInterfaceImplementation, bool isVararg, bool hasBody, Location location, DiagnosticBag diagnostics) { bool isExplicitInterfaceImplementationInInterface = isExplicitInterfaceImplementation && ContainingType.IsInterface; if (IsPartial && HasExplicitAccessModifier) { Binder.CheckFeatureAvailability(SyntaxNode, MessageID.IDS_FeatureExtendedPartialMethods, diagnostics, location); } if (IsPartial && IsAbstract) { diagnostics.Add(ErrorCode.ERR_PartialMethodInvalidModifier, location); } else if (IsPartial && !HasExplicitAccessModifier && !ReturnsVoid) { diagnostics.Add(ErrorCode.ERR_PartialMethodWithNonVoidReturnMustHaveAccessMods, location, this); } else if (IsPartial && !HasExplicitAccessModifier && HasExtendedPartialModifier) { diagnostics.Add(ErrorCode.ERR_PartialMethodWithExtendedModMustHaveAccessMods, location, this); } else if (IsPartial && !HasExplicitAccessModifier && Parameters.Any(p => p.RefKind == RefKind.Out)) { diagnostics.Add(ErrorCode.ERR_PartialMethodWithOutParamMustHaveAccessMods, location, this); } else if (this.DeclaredAccessibility == Accessibility.Private && (IsVirtual || (IsAbstract && !isExplicitInterfaceImplementationInInterface) || IsOverride)) { diagnostics.Add(ErrorCode.ERR_VirtualPrivate, location, this); } else if (IsStatic && (IsOverride || IsVirtual || IsAbstract)) { // A static member '{0}' cannot be marked as override, virtual, or abstract diagnostics.Add(ErrorCode.ERR_StaticNotVirtual, location, this); } else if (IsOverride && (IsNew || IsVirtual)) { // A member '{0}' marked as override cannot be marked as new or virtual diagnostics.Add(ErrorCode.ERR_OverrideNotNew, location, this); } else if (IsSealed && !IsOverride && !(isExplicitInterfaceImplementationInInterface && IsAbstract)) { // '{0}' cannot be sealed because it is not an override diagnostics.Add(ErrorCode.ERR_SealedNonOverride, location, this); } else if (IsSealed && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.SealedKeyword)); } else if (!ContainingType.IsInterfaceType() && _lazyReturnType.IsStatic) { // '{0}': static types cannot be used as return types diagnostics.Add(ErrorCode.ERR_ReturnTypeIsStaticClass, location, _lazyReturnType.Type); } else if (IsAbstract && IsExtern) { diagnostics.Add(ErrorCode.ERR_AbstractAndExtern, location, this); } else if (IsAbstract && IsSealed && !isExplicitInterfaceImplementationInInterface) { diagnostics.Add(ErrorCode.ERR_AbstractAndSealed, location, this); } else if (IsAbstract && IsVirtual) { diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this.Kind.Localize(), this); } else if (IsAbstract && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.AbstractKeyword)); } else if (IsVirtual && ContainingType.TypeKind == TypeKind.Struct) { // The modifier '{0}' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.VirtualKeyword)); } else if (IsStatic && IsDeclaredReadOnly) { // Static member '{0}' cannot be marked 'readonly'. diagnostics.Add(ErrorCode.ERR_StaticMemberCantBeReadOnly, location, this); } else if (IsAbstract && !ContainingType.IsAbstract && (ContainingType.TypeKind == TypeKind.Class || ContainingType.TypeKind == TypeKind.Submission)) { // '{0}' is abstract but it is contained in non-abstract class '{1}' diagnostics.Add(ErrorCode.ERR_AbstractInConcreteClass, location, this, ContainingType); } else if (IsVirtual && ContainingType.IsSealed) { // '{0}' is a new virtual member in sealed class '{1}' diagnostics.Add(ErrorCode.ERR_NewVirtualInSealed, location, this, ContainingType); } else if (!hasBody && IsAsync) { diagnostics.Add(ErrorCode.ERR_BadAsyncLacksBody, location); } else if (!hasBody && !IsExtern && !IsAbstract && !IsPartial && !IsExpressionBodied) { diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } else if (ContainingType.IsSealed && this.DeclaredAccessibility.HasProtected() && !this.IsOverride) { diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this); } else if (ContainingType.IsStatic && !IsStatic) { diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, location, Name); } else if (isVararg && (IsGenericMethod || ContainingType.IsGenericType || _lazyParameters.Length > 0 && _lazyParameters[_lazyParameters.Length - 1].IsParams)) { diagnostics.Add(ErrorCode.ERR_BadVarargs, location); } else if (isVararg && IsAsync) { diagnostics.Add(ErrorCode.ERR_VarargsAsync, location); } }
/// <remarks> /// Note that the access check is done using the original definitions. This is because we want to avoid /// reductions in accessibility that result from type argument substitution (e.g. if an inaccessible type /// has been passed as a type argument). /// See DevDiv #11967 for an example. /// </remarks> private static bool IsOverriddenSymbolAccessible(Symbol overridden, NamedTypeSymbol overridingContainingType) { HashSet <DiagnosticInfo> useSiteDiagnostics = null; return(AccessCheck.IsSymbolAccessible(overridden.OriginalDefinition, overridingContainingType.OriginalDefinition, ref useSiteDiagnostics)); }
private void CheckModifiers(Location location, DiagnosticBag diagnostics) { if (IsPartial && !ReturnsVoid) { diagnostics.Add(ErrorCode.ERR_PartialMethodMustReturnVoid, location); } else if (IsPartial && !ContainingType.IsInterface && 0 != (DeclarationModifiers & (CSharp.DeclarationModifiers.AccessibilityMask & ~CSharp.DeclarationModifiers.Private | CSharp.DeclarationModifiers.Virtual | CSharp.DeclarationModifiers.Abstract | CSharp.DeclarationModifiers.Override | CSharp.DeclarationModifiers.New | CSharp.DeclarationModifiers.Sealed | CSharp.DeclarationModifiers.Extern))) { diagnostics.Add(ErrorCode.ERR_PartialMethodInvalidModifier, location); } else if (this.DeclaredAccessibility == Accessibility.Private && (IsVirtual || IsAbstract || IsOverride)) { diagnostics.Add(ErrorCode.ERR_VirtualPrivate, location, this); } else if (IsStatic && (IsOverride || IsVirtual || IsAbstract)) { // A static member '{0}' cannot be marked as override, virtual, or abstract diagnostics.Add(ErrorCode.ERR_StaticNotVirtual, location, this); } else if (IsOverride && (IsNew || IsVirtual)) { // A member '{0}' marked as override cannot be marked as new or virtual diagnostics.Add(ErrorCode.ERR_OverrideNotNew, location, this); } else if (IsSealed && !IsOverride) { // '{0}' cannot be sealed because it is not an override diagnostics.Add(ErrorCode.ERR_SealedNonOverride, location, this); } else if (!ContainingType.IsInterfaceType() && this.lazyReturnType.IsStatic) { // '{0}': static types cannot be used as return types diagnostics.Add(ErrorCode.ERR_ReturnTypeIsStaticClass, location, this.lazyReturnType); } else if (IsAbstract && IsExtern) { diagnostics.Add(ErrorCode.ERR_AbstractAndExtern, location, this); } else if (IsAbstract && IsSealed) { diagnostics.Add(ErrorCode.ERR_AbstractAndSealed, location, this); } else if (IsAbstract && IsVirtual) { diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this); } else if (IsAbstract && !ContainingType.IsAbstract && ContainingType.TypeKind == TypeKind.Class) { // '{0}' is abstract but it is contained in non-abstract class '{1}' diagnostics.Add(ErrorCode.ERR_AbstractInConcreteClass, location, this, ContainingType); } else if (IsVirtual && ContainingType.IsSealed) { // '{0}' is a new virtual member in sealed class '{1}' diagnostics.Add(ErrorCode.ERR_NewVirtualInSealed, location, this, ContainingType); } else if (blockSyntaxReference == null && IsAsync) { diagnostics.Add(ErrorCode.ERR_BadAsyncLacksBody, location); } else if (blockSyntaxReference == null && !IsExtern && !IsAbstract && !IsPartial) { diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } else if ( ContainingType.IsSealed && (this.DeclaredAccessibility == Accessibility.Protected || this.DeclaredAccessibility == Accessibility.ProtectedOrInternal) && !this.IsOverride) { diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(ContainingType), location, this); } else if (ContainingType.IsStatic && !IsStatic) { diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, location, Name); } else if (this.lazyIsVararg && (IsGenericMethod || ContainingType.IsGenericType || this.lazyParameters.Length > 0 && this.lazyParameters[this.lazyParameters.Length - 1].IsParams)) { diagnostics.Add(ErrorCode.ERR_BadVarargs, location); } else if (this.lazyIsVararg && IsAsync) { diagnostics.Add(ErrorCode.ERR_VarargsAsync, location); } }
private void PopulateRights(string result, List <Privilege> privList, string PermissionName, AccessCheck acCheck = AccessCheck.Default) { // var resp = response.Content.ReadAsStringAsync().Result; var respObj = JObject.Parse(result); respObj = JObject.Parse(respObj.SelectToken("$.AccessInfo").ToString()); string RoleAccess = respObj.SelectToken("$.RoleAccessRights").ToString(); string PoaAccess = respObj.SelectToken("$.PoaAccessRights").ToString(); string HsmAcess = respObj.SelectToken("$.HsmAccessRights").ToString(); string Access = respObj.SelectToken("$.GrantedAccessRights").ToString(); if (Access == "None") { return; } List <string> accessList = Access.Split(new string[] { ", " }, StringSplitOptions.None).ToList(); foreach (var acc in accessList) { var priv = privList.FirstOrDefault(prv => prv.Label == acc); if (priv == null) { continue; } priv.HasAccess = true; if (RoleAccess.Contains(acc)) { priv.Permissions.Add(new Permission { PermissionType = acCheck == AccessCheck.Default ? PermissionType.Role : PermissionType.TeamRole, Name = PermissionName }); } if (PoaAccess.Contains(acc)) { priv.Permissions.Add(new Permission { PermissionType = PermissionType.Shared, Name = PermissionName }); } if (HsmAcess.Contains(acc)) { priv.Permissions.Add(new Permission { PermissionType = PermissionType.Heirarchy, Name = PermissionName }); } } }