diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/cs/Inherited1.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/cs/Inherited1.cs index 1659f862f72d4..8b4921691962c 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/cs/Inherited1.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/cs/Inherited1.cs @@ -5,68 +5,64 @@ [InheritedAttribute] public class BaseA { - [InheritedAttribute] - public virtual void MethodA() - {} + [InheritedAttribute] + public virtual void MethodA() + { } } public class DerivedA : BaseA { - public override void MethodA() - {} -} + public override void MethodA() + { } +} -[NotInheritedAttribute] +[NotInheritedAttribute] public class BaseB { - [NotInheritedAttribute] - public virtual void MethodB() - {} + [NotInheritedAttribute] + public virtual void MethodB() + { } } public class DerivedB : BaseB { - public override void MethodB() - {} + public override void MethodB() + { } } public class Example { - public static void Main() - { - Type typeA = typeof(DerivedA); - Console.WriteLine("DerivedA has Inherited attribute: {0}", - typeA.GetCustomAttributes(typeof(InheritedAttribute), true).Length > 0); - MethodInfo memberA = typeA.GetMethod("MethodA"); - Console.WriteLine("DerivedA.MemberA has Inherited attribute: {0}\n", - memberA.GetCustomAttributes(typeof(InheritedAttribute), true).Length > 0); - - Type typeB = typeof(DerivedB); - Console.WriteLine("DerivedB has Inherited attribute: {0}", - typeB.GetCustomAttributes(typeof(InheritedAttribute), true).Length > 0); - MethodInfo memberB = typeB.GetMethod("MethodB"); - Console.WriteLine("DerivedB.MemberB has Inherited attribute: {0}", - memberB.GetCustomAttributes(typeof(InheritedAttribute), true).Length > 0); - } + public static void Main() + { + Type typeA = typeof(DerivedA); + Console.WriteLine($"DerivedA has Inherited attribute: {typeA.GetCustomAttributes(typeof(InheritedAttribute), true).Length > 0}"); + MethodInfo memberA = typeA.GetMethod(nameof(DerivedA.MethodA)); + Console.WriteLine($"DerivedA.MemberA has Inherited attribute: {memberA.GetCustomAttributes(typeof(InheritedAttribute), true).Length > 0}\n"); + + Type typeB = typeof(DerivedB); + Console.WriteLine($"DerivedB has NotInherited attribute: {typeB.GetCustomAttributes(typeof(NotInheritedAttribute), true).Length > 0}"); + MethodInfo memberB = typeB.GetMethod(nameof(DerivedB.MethodB)); + Console.WriteLine($"DerivedB.MemberB has NotInherited attribute: {memberB.GetCustomAttributes(typeof(NotInheritedAttribute), true).Length > 0}"); + } } // The example displays the following output: // DerivedA has Inherited attribute: True // DerivedA.MemberA has Inherited attribute: True // -// DerivedB has Inherited attribute: False -// DerivedB.MemberB has Inherited attribute: False +// DerivedB has NotInherited attribute: False +// DerivedB.MemberB has NotInherited attribute: False // // -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | - AttributeTargets.Property | AttributeTargets.Field, +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | + AttributeTargets.Property | AttributeTargets.Field, Inherited = true)] public class InheritedAttribute : Attribute -{} +{ } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | - AttributeTargets.Property | AttributeTargets.Field, + AttributeTargets.Property | AttributeTargets.Field, Inherited = false)] public class NotInheritedAttribute : Attribute -{} -// \ No newline at end of file +{ } +// diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb index 675746bcfa163..7f3a437d21698 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb @@ -5,42 +5,38 @@ Option Strict On Imports System.Reflection Public Class BaseA - Public Overridable Sub MethodA() - End Sub + Public Overridable Sub MethodA() + End Sub End Class Public Class DerivedA : Inherits BaseA - Public Overrides Sub MethodA - End Sub -End Class + Public Overrides Sub MethodA() + End Sub +End Class Public Class BaseB - Public Overridable Sub MethodB() - End Sub + Public Overridable Sub MethodB() + End Sub End Class Public Class DerivedB : Inherits BaseB - Public Overrides Sub MethodB - End Sub -End Class + Public Overrides Sub MethodB() + End Sub +End Class Module Example - Public Sub Main() - Dim typeA As Type = GetType(DerivedA) - Console.WriteLine("DerivedA has Inherited attribute: {0}", - typeA.GetCustomAttributes(GetType(InheritedAttribute), True).Length > 0) - Dim memberA As MethodInfo = typeA.GetMethod("MethodA") - Console.WriteLine("DerivedA.MemberA has Inherited attribute: {0}", - memberA.GetCustomAttributes(GetType(InheritedAttribute), True).Length > 0) - Console.WriteLine() - - Dim typeB As Type = GetType(DerivedB) - Console.WriteLine("DerivedB has Inherited attribute: {0}", - typeB.GetCustomAttributes(GetType(InheritedAttribute), True).Length > 0) - Dim memberB As MethodInfo = typeB.GetMethod("MethodB") - Console.WriteLine("DerivedB.MemberB has Inherited attribute: {0}", - memberB.GetCustomAttributes(GetType(InheritedAttribute), True).Length > 0) - End Sub + Public Sub Main() + Dim typeA As Type = GetType(DerivedA) + Console.WriteLine($"DerivedA has Inherited attribute: {typeA.GetCustomAttributes(GetType(InheritedAttribute), True).Length > 0}") + Dim memberA As MethodInfo = typeA.GetMethod(NameOf(DerivedA.MethodA)) + Console.WriteLine($"DerivedA.MemberA has Inherited attribute: {memberA.GetCustomAttributes(GetType(InheritedAttribute), True).Length > 0}") + Console.WriteLine() + + Dim typeB As Type = GetType(DerivedB) + Console.WriteLine($"DerivedB has NotInherited attribute: {typeB.GetCustomAttributes(GetType(NotInheritedAttribute), True).Length > 0}") + Dim memberB As MethodInfo = typeB.GetMethod(NameOf(DerivedB.MethodB)) + Console.WriteLine($"DerivedB.MemberB has Inherited attribute: {memberB.GetCustomAttributes(GetType(NotInheritedAttribute), True).Length > 0}") + End Sub End Module ' The example displays the following output: ' DerivedA has Inherited attribute: True @@ -51,15 +47,15 @@ End Module ' ' - + Public Class InheritedAttribute : Inherits Attribute End Class + Or AttributeTargets.Property Or AttributeTargets.Field, + Inherited:=False)> Public Class NotInheritedAttribute : Inherits Attribute End Class '