1
This commit is contained in:
41
Core/Sharp/BITSharp.cs
Normal file
41
Core/Sharp/BITSharp.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class BITSharp
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, Type> Dictionary = new();
|
||||
static Assembly[] assemblies;
|
||||
public static bool TryGetTypeFromFullName(string fullClassName,out Type type)
|
||||
{
|
||||
type = GetTypeFromFullName(fullClassName);
|
||||
return type is not null ? true : false;
|
||||
}
|
||||
public static Type GetTypeFromFullName(string fullClassName)
|
||||
{
|
||||
return Dictionary.GetOrAdd(fullClassName, SearchType);
|
||||
}
|
||||
static Type SearchType(string fullName)
|
||||
{
|
||||
assemblies = assemblies??AppDomain.CurrentDomain.GetAssemblies();
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
var type = assembly.GetType(fullName,false);
|
||||
if (type is not null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user