气泡组件和配置项

This commit is contained in:
2024-09-13 19:39:22 +00:00
parent 4d9de0712e
commit 7adffa4372
73 changed files with 5671 additions and 2047 deletions
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Reflection;
namespace AibisDream.Utility
{
public abstract class SingletonBase<T> where T : SingletonBase<T>
{
private static T _instance;
public static T Instance
{
get
{
if (_instance != null) return _instance;
// 先获取所有非public的构造方法
var ctors = typeof(T).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic);
// 从ctors中获取无参的构造方法
var ctor = Array.Find(ctors, c => c.GetParameters().Length == 0);
if (ctor == null)
throw new Exception("Non-public ctor() not found!");
// 调用构造方法
_instance = ctor.Invoke(null) as T;
return _instance;
}
}
}
}