Skip to content

Commit

Permalink
Changed VisualStudioDevelopmentEnvironment to WIndowsDevelopmentEnvir…
Browse files Browse the repository at this point in the history
…oment

Just less classes to manage and also moves the logic for selecting the correct one to the class assembly itself.
  • Loading branch information
ByronMayne committed Oct 23, 2023
1 parent 4f595b1 commit fa6e353
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 55 deletions.
10 changes: 10 additions & 0 deletions src/Plugins/SourceGenerator.Foundations.Windows/EnvironmentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SGF
{
internal enum EnvironmentType
{
Unknown,
VisualStudio,
VSCode,
Rider
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Serilog.Core;
using SGF.Interop.VisualStudio;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace SGF
{

/// <summary>
/// Represents a enviroment where the user is authoring code in Visual Studio
/// </summary>
internal class WindowsDevelopmentEnvironment : IDevelopmentEnviroment
{
public EnvironmentType Type { get; }


public WindowsDevelopmentEnvironment()
{
Type = EnvironmentType.VisualStudio;

if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("VisualStudioVersion")))
{
Type = EnvironmentType.VisualStudio;
}
}

/// <inheritdoc cref="IDevelopmentEnviroment"/>
public bool AttachDebugger(int processId)
{
switch (Type)
{
case EnvironmentType.VisualStudio:
VisualStudioInterop.AttachDebugger();
break;
}
return true;
}

/// <inheritdoc cref="IDevelopmentEnviroment"/>
public IEnumerable<ILogEventSink> GetLogSinks()
{
switch (Type)
{
case EnvironmentType.VisualStudio:
yield return new VisualStudioLogEventSink();
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,21 @@ string assemblyVersion
try
{

Assembly? environmentAssembly = null;
Type? developmentEnvironment = null;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
AssemblyName windowsAssemblyName = new AssemblyName($"SourceGenerator.Foundations.Windows, Version={assemblyVersion}, Culture=neutral, PublicKeyToken=null");
Assembly windowsEnvironmentAssembly = Assembly.Load(windowsAssemblyName);
environmentAssembly = Assembly.Load(windowsAssemblyName);
}

if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("VisualStudioVersion")))
{
developmentEnvironment = windowsEnvironmentAssembly.GetType("SGF.VisualStudioEnvironment");
}
if(environmentAssembly != null)
{
developmentEnvironment = environmentAssembly
.GetTypes()
.Where(typeof(IDevelopmentEnviroment).IsAssignableFrom)
.FirstOrDefault();
}

if (developmentEnvironment != null)
Expand Down

0 comments on commit fa6e353

Please sign in to comment.