-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
70 lines (61 loc) · 1.93 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Diagnostics;
namespace AttributesOnLocalFunctions
{
/// <summary>
/// Attributes on local functions
/// https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.windowsruntime.returnvaluenameattribute?view=netcore-3.1
/// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/local-function-attributes
/// </summary>
class Program
{
static void Main(string[] args)
{
Foo();
Bar();
Baz();
object[] attributes = typeof(PipelineFactory).GetMethod("GetPipelineName")
.ReturnTypeCustomAttributes
.GetCustomAttributes(false);
foreach (var attribute in attributes)
{
if (attribute is ReturnValueIgnoredAttribute returnValue)
{
Console.WriteLine($"DefaultValue: {returnValue.DefaultValue} TypeId: {returnValue.TypeId}");
}
}
}
[Conditional("DEBUG")]
static void Foo()
{
Console.WriteLine("I running at DEBUG");
}
[Conditional("NETCOREAPP3_1")]
static void Bar()
{
Console.WriteLine("I running at NETCOREAPP3_1");
}
[Conditional("BETA")]
static void Baz()
{
Console.WriteLine("I running at BETA");
}
}
class PipelineFactory
{
[return: ReturnValueIgnored("Transaction Data Pipeline")]
public string GetPipelineName()
{
return "Health Data Pipeline";
}
}
[AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false)]
class ReturnValueIgnoredAttribute : Attribute
{
public ReturnValueIgnoredAttribute(string defaultValue)
{
DefaultValue = defaultValue;
}
public string DefaultValue { get; set; }
}
}