Skip to content

Commit 72918ee

Browse files
VineethReyyav-vreyya
and
v-vreyya
authored
Fix style in coretoolhost Project (#4387)
* coretoolhost style changes * corrections- coretoolshost style --------- Co-authored-by: v-vreyya <v-vreyya@DESKTOP-RT7L5HG>
1 parent b07029b commit 72918ee

File tree

9 files changed

+75
-81
lines changed

9 files changed

+75
-81
lines changed

src/CoreToolsHost/AppLoader/AppLoader.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT License. See License.txt in the project root for license information.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.Runtime.InteropServices;
55

@@ -11,31 +11,31 @@ namespace CoreToolsHost
1111
// export COREHOST_TRACE=1
1212

1313
/// <summary>
14-
/// Manages loading hostfxr
14+
/// Manages loading hostfxr.
1515
/// </summary>
1616
internal sealed class AppLoader : IDisposable
1717
{
1818
private IntPtr _hostfxrHandle = IntPtr.Zero;
1919
private IntPtr _hostContextHandle = IntPtr.Zero;
2020
private bool _disposed;
21-
private bool isVerbose = false;
21+
private bool _isVerbose = false;
2222

2323
internal int RunApplication(string? assemblyPath, string[] commandLineArgs)
2424
{
2525
ArgumentNullException.ThrowIfNull(assemblyPath, nameof(assemblyPath));
2626

2727
unsafe
2828
{
29-
var parameters = new NetHost.get_hostfxr_parameters
29+
var parameters = new NetHost.HostFxrParameters
3030
{
31-
size = sizeof(NetHost.get_hostfxr_parameters),
32-
assembly_path = GetCharArrayPointer(assemblyPath)
31+
Size = sizeof(NetHost.HostFxrParameters),
32+
AssemblyPath = GetCharArrayPointer(assemblyPath)
3333
};
3434

35-
isVerbose = commandLineArgs.Contains(DotnetConstants.Verbose);
35+
_isVerbose = commandLineArgs.Contains(DotnetConstants.Verbose);
3636

3737
var hostfxrFullPath = NetHost.GetHostFxrPath(&parameters);
38-
Logger.LogVerbose(isVerbose, $"hostfxr path:{hostfxrFullPath}");
38+
Logger.LogVerbose(_isVerbose, $"hostfxr path:{hostfxrFullPath}");
3939

4040
_hostfxrHandle = NativeLibrary.Load(hostfxrFullPath);
4141

@@ -45,7 +45,7 @@ internal int RunApplication(string? assemblyPath, string[] commandLineArgs)
4545
return -1;
4646
}
4747

48-
Logger.LogVerbose(isVerbose, $"hostfxr loaded.");
48+
Logger.LogVerbose(_isVerbose, $"hostfxr loaded.");
4949

5050
var commandLineArguments = commandLineArgs.Prepend(assemblyPath).ToArray();
5151
var error = HostFxr.Initialize(commandLineArguments.Length, commandLineArguments, IntPtr.Zero, out _hostContextHandle);
@@ -60,7 +60,8 @@ internal int RunApplication(string? assemblyPath, string[] commandLineArgs)
6060
{
6161
return error;
6262
}
63-
Logger.LogVerbose(isVerbose, $"hostfxr initialized with {assemblyPath}");
63+
64+
Logger.LogVerbose(_isVerbose, $"hostfxr initialized with {assemblyPath}");
6465

6566
return HostFxr.Run(_hostContextHandle);
6667
}
@@ -84,14 +85,14 @@ private void Dispose(bool disposing)
8485
if (_hostfxrHandle != IntPtr.Zero)
8586
{
8687
NativeLibrary.Free(_hostfxrHandle);
87-
Logger.LogVerbose(isVerbose, $"Freed hostfxr library handle");
88+
Logger.LogVerbose(_isVerbose, $"Freed hostfxr library handle");
8889
_hostfxrHandle = IntPtr.Zero;
8990
}
9091

9192
if (_hostContextHandle != IntPtr.Zero)
9293
{
9394
HostFxr.Close(_hostContextHandle);
94-
Logger.LogVerbose(isVerbose, $"Closed hostcontext handle");
95+
Logger.LogVerbose(_isVerbose, $"Closed hostcontext handle");
9596
_hostContextHandle = IntPtr.Zero;
9697
}
9798

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,43 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT License. See License.txt in the project root for license information.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.Runtime.InteropServices;
55

66
namespace CoreToolsHost
77
{
8-
static partial class HostFxr
8+
internal static partial class HostFxr
99
{
10-
#pragma warning disable CS0649
11-
public unsafe struct hostfxr_initialize_parameters
12-
{
13-
public nint size;
14-
public char* host_path;
15-
public char* dotnet_root;
16-
};
17-
#pragma warning restore CS0649
18-
1910
[LibraryImport("hostfxr", EntryPoint = "hostfxr_initialize_for_dotnet_command_line",
2011
#if OS_LINUX
21-
StringMarshalling = StringMarshalling.Utf8
12+
StringMarshalling = StringMarshalling.Utf8)]
2213
#else
23-
StringMarshalling = StringMarshalling.Utf16
14+
StringMarshalling = StringMarshalling.Utf16)]
2415
#endif
25-
)]
26-
public unsafe static partial int Initialize(
16+
public static unsafe partial int Initialize(
2717
int argc,
2818
string[] argv,
2919
IntPtr parameters,
30-
out IntPtr host_context_handle
31-
);
20+
out IntPtr hostContextHandle);
3221

3322
[LibraryImport("hostfxr", EntryPoint = "hostfxr_run_app")]
34-
public static partial int Run(IntPtr host_context_handle);
23+
public static partial int Run(IntPtr hostContextHandle);
3524

3625
[LibraryImport("hostfxr", EntryPoint = "hostfxr_set_runtime_property_value",
3726
#if OS_LINUX
38-
StringMarshalling = StringMarshalling.Utf8
27+
StringMarshalling = StringMarshalling.Utf8)]
3928
#else
40-
StringMarshalling = StringMarshalling.Utf16
29+
StringMarshalling = StringMarshalling.Utf16)]
4130
#endif
42-
)]
43-
public static partial int SetAppContextData(IntPtr host_context_handle, string name, string value);
31+
public static partial int SetAppContextData(IntPtr hostContextHandle, string name, string value);
4432

4533
[LibraryImport("hostfxr", EntryPoint = "hostfxr_close")]
46-
public static partial int Close(IntPtr host_context_handle);
34+
public static partial int Close(IntPtr hostContextHandle);
35+
36+
public unsafe struct HostFXRInitializeParameters
37+
{
38+
public nint Size;
39+
public char* HostPath;
40+
public char* DotnetRoot;
41+
}
4742
}
4843
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT License. See License.txt in the project root for license information.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.Runtime.InteropServices;
55

66
namespace CoreToolsHost
77
{
88
internal class NetHost
99
{
10-
public unsafe struct get_hostfxr_parameters
11-
{
12-
public nint size;
13-
14-
// Optional.Path to the application assembly,
15-
// If specified, hostfxr is located from this directory if present (For self-contained deployments)
16-
public char* assembly_path;
17-
public char* dotnet_root;
18-
}
19-
2010
[DllImport("nethost", CharSet = CharSet.Auto)]
21-
private unsafe static extern int get_hostfxr_path(
11+
private static extern unsafe int GetHostFXRPath(
2212
[Out] char[] buffer,
2313
[In] ref int buffer_size,
24-
get_hostfxr_parameters* parameters);
14+
HostFxrParameters* parameters);
2515

26-
internal unsafe static string GetHostFxrPath(get_hostfxr_parameters* parameters)
16+
internal static unsafe string GetHostFxrPath(HostFxrParameters* parameters)
2717
{
2818
char[] buffer = new char[200];
2919
int bufferSize = buffer.Length;
3020

31-
int rc = get_hostfxr_path(buffer, ref bufferSize, parameters);
21+
int rc = GetHostFXRPath(buffer, ref bufferSize, parameters);
3222

3323
if (rc != 0)
3424
{
@@ -37,5 +27,15 @@ internal unsafe static string GetHostFxrPath(get_hostfxr_parameters* parameters)
3727

3828
return new string(buffer, 0, bufferSize - 1);
3929
}
30+
31+
public unsafe struct HostFxrParameters
32+
{
33+
public nint Size;
34+
35+
// Optional.Path to the application assembly,
36+
// If specified, hostfxr is located from this directory if present (For self-contained deployments)
37+
public char* AssemblyPath;
38+
public char* DotnetRoot;
39+
}
4040
}
4141
}

src/CoreToolsHost/DotnetConstants.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
63

74
namespace CoreToolsHost
85
{

src/CoreToolsHost/Environment/EnvironmentUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT License. See License.txt in the project root for license information.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
namespace CoreToolsHost
55
{
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT License. See License.txt in the project root for license information.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
namespace CoreToolsHost;
55

66
internal static class EnvironmentVariables
77
{
88
/// <summary>
9-
/// The worker runtime. Example value: "dotnet-isolated"
9+
/// The worker runtime. Example value: "dotnet-isolated".
1010
/// </summary>
1111
internal const string FunctionsWorkerRuntime = "FUNCTIONS_WORKER_RUNTIME";
1212

1313
/// <summary>
14-
/// Determines if Functions InProc NET8 is enabled for a .NET 8 in-proc app
14+
/// Determines if Functions InProc NET8 is enabled for a .NET 8 in-proc app.
1515
/// </summary>
1616
internal const string FunctionsInProcNet8Enabled = "FUNCTIONS_INPROC_NET8_ENABLED";
1717
}

src/CoreToolsHost/LocalSettingsJsonParser.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
54
using System.Text.Json;
6-
using System.Threading.Tasks;
75

86
namespace CoreToolsHost
97
{
@@ -15,12 +13,13 @@ internal static class LocalSettingsJsonParser
1513

1614
if (File.Exists(fullPath))
1715
{
18-
string fileContent = "";
16+
string fileContent = string.Empty;
1917
using (var fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
2018
using (var streamReader = new StreamReader(fileStream))
2119
{
2220
fileContent = await streamReader.ReadToEndAsync();
2321
}
22+
2423
if (!string.IsNullOrEmpty(fileContent))
2524
{
2625
var localSettingsJObject = JsonDocument.Parse(fileContent, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true });

src/CoreToolsHost/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT License. See License.txt in the project root for license information.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.Globalization;
55

src/CoreToolsHost/Program.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT License. See License.txt in the project root for license information.
3-
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
43

54
using System.Text.Json;
65

76
namespace CoreToolsHost
87
{
98
internal class Program
109
{
11-
static bool isVerbose = false;
12-
13-
static async Task Main(string[] args)
10+
private static bool _isVerbose = false;
11+
12+
public static async Task Main(string[] args)
1413
{
15-
isVerbose = args.Contains(DotnetConstants.Verbose);
14+
_isVerbose = args.Contains(DotnetConstants.Verbose);
1615

17-
Logger.LogVerbose(isVerbose, "Starting CoreToolsHost");
16+
Logger.LogVerbose(_isVerbose, "Starting CoreToolsHost");
1817

1918
var localSettingsJson = await LocalSettingsJsonParser.GetLocalSettingsJsonAsJObjectAsync();
2019

2120
if (localSettingsJson is null)
2221
{
23-
Logger.LogVerbose(isVerbose, "No local.settings.json file was found");
22+
Logger.LogVerbose(_isVerbose, "No local.settings.json file was found");
2423
}
2524

26-
bool projectOptsIntoDotnet8 =
25+
bool projectOptsIntoDotnet8 =
26+
2727
// local.settings.json must be the source of the configuration
2828
localSettingsJson is not null && localSettingsJson.RootElement.TryGetProperty("Values", out JsonElement valuesElement)
29+
2930
// The runtime must be specified as "dotnet"
3031
&& ElementExistsWithValue(valuesElement, EnvironmentVariables.FunctionsWorkerRuntime, DotnetConstants.DotnetWorkerRuntime)
32+
3133
// The .NET 8 enablement configuration must be provided
3234
&& ElementExistsWithValue(valuesElement, EnvironmentVariables.FunctionsInProcNet8Enabled, "1");
3335

34-
Logger.LogVerbose(isVerbose, $"Loading .NET {(projectOptsIntoDotnet8 ? 8 : 6)} host");
36+
Logger.LogVerbose(_isVerbose, $"Loading .NET {(projectOptsIntoDotnet8 ? 8 : 6)} host");
3537

3638
try
3739
{
@@ -48,19 +50,19 @@ static async Task Main(string[] args)
4850
private static bool ElementExistsWithValue(JsonElement element, string key, string value)
4951
{
5052
return !string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)
51-
&& element.TryGetProperty(key, out JsonElement property)
52-
&& !string.IsNullOrEmpty(property.ToString())
53-
&& string.Equals(property.ToString(), value, StringComparison.OrdinalIgnoreCase);
53+
&& element.TryGetProperty(key, out JsonElement property)
54+
&& !string.IsNullOrEmpty(property.ToString())
55+
&& string.Equals(property.ToString(), value, StringComparison.OrdinalIgnoreCase);
5456
}
5557

5658
private static void LoadHostAssembly(AppLoader appLoader, string[] args, bool isNet8InProc)
5759
{
5860
string filePath = Path.Combine(
5961
AppContext.BaseDirectory, // current directory
60-
isNet8InProc ? DotnetConstants.InProc8DirectoryName: DotnetConstants.InProc6DirectoryName,
62+
isNet8InProc ? DotnetConstants.InProc8DirectoryName : DotnetConstants.InProc6DirectoryName,
6163
DotnetConstants.ExecutableName);
6264

63-
Logger.LogVerbose(isVerbose, $"File path to load: {filePath}");
65+
Logger.LogVerbose(_isVerbose, $"File path to load: {filePath}");
6466

6567
appLoader.RunApplication(filePath, args);
6668
}

0 commit comments

Comments
 (0)