Skip to content

Commit 9b9c937

Browse files
authored
System.AttributeTargets F# snippet (#7525)
* System.AttributeTargets F# snippets * Update AttributeTargets.xml
1 parent 41b8272 commit 9b9c937

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//<Snippet1>
2+
open System
3+
4+
// This attribute is only valid on a class.
5+
[<AttributeUsage(AttributeTargets.Class)>]
6+
type ClassTargetAttribute() =
7+
inherit Attribute()
8+
9+
// This attribute is only valid on a method.
10+
[<AttributeUsage(AttributeTargets.Method)>]
11+
type MethodTargetAttribute() =
12+
inherit Attribute()
13+
14+
// This attribute is only valid on a constructor.
15+
[<AttributeUsage(AttributeTargets.Constructor)>]
16+
type ConstructorTargetAttribute() =
17+
inherit Attribute()
18+
19+
// This attribute is only valid on a field.
20+
[<AttributeUsage(AttributeTargets.Field)>]
21+
type FieldTargetAttribute() =
22+
inherit Attribute()
23+
24+
// This attribute is valid on a class or a method.
25+
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Method)>]
26+
type ClassMethodTargetAttribute() =
27+
inherit Attribute()
28+
29+
// This attribute is valid on a generic type parameter.
30+
[<AttributeUsage(AttributeTargets.GenericParameter)>]
31+
type GenericParameterTargetAttribute() =
32+
inherit Attribute()
33+
34+
// This attribute is valid on any target.
35+
[<AttributeUsage(AttributeTargets.All)>]
36+
type AllTargetsAttribute() =
37+
inherit Attribute()
38+
39+
[<ClassTarget>]
40+
[<ClassMethodTarget>]
41+
[<AllTargets>]
42+
type TestClassAttribute [<ConstructorTarget>] [<AllTargets>] () =
43+
[<FieldTarget>]
44+
[<AllTargets>]
45+
let myInt = 0
46+
47+
[<MethodTarget>]
48+
[<ClassMethodTarget>]
49+
[<AllTargets>]
50+
member _.Method1() = ()
51+
52+
member _.GenericMethod<[<GenericParameterTarget; AllTargets>] 'T>(x: 'T) = ()
53+
54+
//</Snippet1>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="attrtargs.fs" />
8+
</ItemGroup>
9+
</Project>

xml/System/AttributeTargets.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
7373
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/AttrTargs/CPP/attrtargs.cpp" id="Snippet1":::
7474
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/AttrTargs/CS/attrtargs.cs" id="Snippet1":::
75+
:::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/AttrTargs/FS/attrtargs.fs" id="Snippet1":::
7576
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/AttrTargs/VB/AttrTargs.vb" id="Snippet1":::
7677
7778
]]></format>

0 commit comments

Comments
 (0)