修改命名空间
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Windows;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.Common.Assists;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Assists;
|
||||
|
||||
public sealed record SingletonViewAssist<T>
|
||||
where T : Window, new()
|
||||
{
|
||||
private static T _instance;
|
||||
private static readonly object Padlock = new();
|
||||
|
||||
private SingletonViewAssist() { }
|
||||
|
||||
public static T GetInstance(out bool isNewCreate)
|
||||
{
|
||||
isNewCreate = false;
|
||||
//double-check locking
|
||||
if (_instance == null)
|
||||
{
|
||||
isNewCreate = true;
|
||||
lock (Padlock)
|
||||
{
|
||||
_instance ??= new T();
|
||||
_instance.Closed += OnWindowClosed;
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
private static void OnWindowClosed(object sender, EventArgs e)
|
||||
{
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user