Skip to content

Commit 32e541e

Browse files
authored
ApplicationId F# snippets (#7901)
1 parent eb604f8 commit 32e541e

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net48</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="program.fs" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//<Snippet1>
2+
open System
3+
open System.Collections
4+
open System.Text
5+
open System.Security.Policy
6+
open System.Reflection
7+
open System.Security
8+
open System.Security.Permissions
9+
10+
[<SecurityPermission(SecurityAction.Demand, ControlDomainPolicy = true)>]
11+
let main _ =
12+
//<Snippet2>
13+
printfn $"Full name = {AppDomain.CurrentDomain.ActivationContext.Identity.FullName}"
14+
//</Snippet2>
15+
//<Snippet3>
16+
printfn $"Code base = {AppDomain.CurrentDomain.ActivationContext.Identity.CodeBase}"
17+
//</Snippet3>
18+
//<Snippet6>
19+
//<Snippet7>
20+
let asi = ApplicationSecurityInfo AppDomain.CurrentDomain.ActivationContext
21+
22+
printfn $"ApplicationId.Name property = {asi.ApplicationId.Name}"
23+
//</Snippet7>
24+
//<Snippet8>
25+
if asi.ApplicationId.Culture <> null then
26+
printfn $"ApplicationId.Culture property = {asi.ApplicationId.Culture}"
27+
//</Snippet8>
28+
//<Snippet9>
29+
printfn $"ApplicationId.ProcessorArchitecture property = {asi.ApplicationId.ProcessorArchitecture}"
30+
//</Snippet9>
31+
//<Snippet10>
32+
printfn $"ApplicationId.Version property = {asi.ApplicationId.Version}"
33+
//</Snippet10>
34+
//<Snippet11>
35+
// To display the value of the public key, enumerate the Byte array for the property.
36+
printf "ApplicationId.PublicKeyToken property = "
37+
let pk = asi.ApplicationId.PublicKeyToken
38+
for i = 0 to pk.GetLength 0 - 1 do
39+
printf $"{pk[i]:x}"
40+
//</Snippet11>
41+
//</Snippet6>
42+
Console.Read()
43+
//</Snippet1>

xml/System/ApplicationId.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
The following code example displays the <xref:System.ApplicationId> properties by obtaining the <xref:System.ApplicationId> from an <xref:System.Security.Policy.ApplicationSecurityInfo> instance created using the <xref:System.ActivationContext> for the currently executing manifest-based application.
6868
6969
:::code language="csharp" source="~/snippets/csharp/System/ApplicationId/Overview/program.cs" id="Snippet1":::
70+
:::code language="fsharp" source="~/snippets/fsharp/System/ApplicationId/Overview/program.fs" id="Snippet1":::
7071
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ApplicationIdentity/VB/program.vb" id="Snippet1":::
7172
7273
]]></format>
@@ -241,6 +242,7 @@
241242
The following code example displays the <xref:System.ApplicationId.Culture%2A> property by obtaining the <xref:System.ApplicationId> from an <xref:System.Security.Policy.ApplicationSecurityInfo> instance created using the <xref:System.ActivationContext> for the currently executing manifest-based application. This code example is part of a larger example provided for the <xref:System.ApplicationId> class.
242243
243244
:::code language="csharp" source="~/snippets/csharp/System/ApplicationId/Overview/program.cs" id="Snippet8":::
245+
:::code language="fsharp" source="~/snippets/fsharp/System/ApplicationId/Overview/program.fs" id="Snippet8":::
244246
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ApplicationIdentity/VB/program.vb" id="Snippet8":::
245247
246248
]]></format>
@@ -404,6 +406,7 @@
404406
The following code example displays the <xref:System.ApplicationId.Name%2A> property by obtaining the <xref:System.ApplicationId> from an <xref:System.Security.Policy.ApplicationSecurityInfo> instance created using the <xref:System.ActivationContext> for the currently executing manifest-based application. This code example is part of a larger example provided for the <xref:System.ApplicationId> class.
405407
406408
:::code language="csharp" source="~/snippets/csharp/System/ApplicationId/Overview/program.cs" id="Snippet7":::
409+
:::code language="fsharp" source="~/snippets/fsharp/System/ApplicationId/Overview/program.fs" id="Snippet7":::
407410
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ApplicationIdentity/VB/program.vb" id="Snippet7":::
408411
409412
]]></format>
@@ -460,6 +463,7 @@
460463
The following code example displays the <xref:System.ApplicationId.ProcessorArchitecture%2A> property by obtaining the <xref:System.ApplicationId> from an <xref:System.Security.Policy.ApplicationSecurityInfo> instance created using the <xref:System.ActivationContext> for the currently executing manifest-based application. This code example is part of a larger example provided for the <xref:System.ApplicationId> class.
461464
462465
:::code language="csharp" source="~/snippets/csharp/System/ApplicationId/Overview/program.cs" id="Snippet9":::
466+
:::code language="fsharp" source="~/snippets/fsharp/System/ApplicationId/Overview/program.fs" id="Snippet9":::
463467
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ApplicationIdentity/VB/program.vb" id="Snippet9":::
464468
465469
]]></format>
@@ -517,6 +521,7 @@
517521
The following code example displays the <xref:System.ApplicationId.PublicKeyToken%2A> property by obtaining the <xref:System.ApplicationId> from an <xref:System.Security.Policy.ApplicationSecurityInfo> instance created using the <xref:System.ActivationContext> for the currently executing manifest-based application. This code example is part of a larger example provided for the <xref:System.ApplicationId> class.
518522
519523
:::code language="csharp" source="~/snippets/csharp/System/ApplicationId/Overview/program.cs" id="Snippet11":::
524+
:::code language="fsharp" source="~/snippets/fsharp/System/ApplicationId/Overview/program.fs" id="Snippet11":::
520525
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ApplicationIdentity/VB/program.vb" id="Snippet11":::
521526
522527
]]></format>
@@ -620,6 +625,7 @@
620625
The following code example displays the <xref:System.ApplicationId.Version%2A> property by obtaining the <xref:System.ApplicationId> from an <xref:System.Security.Policy.ApplicationSecurityInfo> instance created using the <xref:System.ActivationContext> for the currently executing manifest-based application. This code example is part of a larger example provided for the <xref:System.ApplicationId> class.
621626
622627
:::code language="csharp" source="~/snippets/csharp/System/ApplicationId/Overview/program.cs" id="Snippet10":::
628+
:::code language="fsharp" source="~/snippets/fsharp/System/ApplicationId/Overview/program.fs" id="Snippet10":::
623629
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ApplicationIdentity/VB/program.vb" id="Snippet10":::
624630
625631
]]></format>

0 commit comments

Comments
 (0)