
Class Inheritance Demands
An inherited demand applied to a class has the effect of demanding that all classes derived from the parent class have the specified permission. For example, if class B is to inherit from class A and class A is protected by an inheritance demand, then B must be granted that permission in order to run. If class B is granted that permission and derives from class A, then class C must also have the permission demanded by A, if it is to derive from B. This demand can be applied only declaratively.
The following code example uses an inheritance demand to require that any class that inherits from the MyClass1 class must have the custom permission CustomPermissionAttribute. This permission is a hypothetical custom permission and does not exist in the .NET Framework. The demand is made by passing the CustomPermissionAttribute a SecurityAction..::.InheritanceDemand enumeration value.
<CustomPermissionAttribute(SecurityAction.InheritanceDemand)> _
Public Class MyClass1
Public Sub New()
End Sub
Public Overridable Function ReadData() As String
' Access a custom resource.
End Function
End Class
[CustomPermissionAttribute(SecurityAction.InheritanceDemand)]
public class MyClass
{
public MyClass()
{
}
public virtual string ReadData()
{
// Access a custom resource.
}
}