mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-19 07:59:47 +03:00
create NResUI
This commit is contained in:
64
NResUI/Utils.cs
Normal file
64
NResUI/Utils.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace NResUI
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
public static bool IsDirectory(this FileSystemInfo info)
|
||||
{
|
||||
// get the file attributes for file or directory
|
||||
FileAttributes attr = info.Attributes;
|
||||
|
||||
//detect whether its a directory or file
|
||||
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsDirectoryPath(this string path)
|
||||
{
|
||||
return Directory.Exists(path);
|
||||
}
|
||||
|
||||
public static void ClearContent(this DirectoryInfo directoryInfo)
|
||||
{
|
||||
foreach (var directory in directoryInfo.EnumerateDirectories())
|
||||
{
|
||||
directory.Delete(true);
|
||||
}
|
||||
|
||||
foreach (var file in directoryInfo.EnumerateFiles())
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> GetAssignableTypesFromAssembly<T>(Assembly assembly)
|
||||
{
|
||||
return assembly.ExportedTypes
|
||||
.Where(t => t.IsAssignableTo(typeof(T)) && t is {IsAbstract: false, IsInterface: false});
|
||||
}
|
||||
|
||||
public static IList<Type> GetAssignableTypes<T>()
|
||||
{
|
||||
var executingAssembly = Assembly.GetExecutingAssembly();
|
||||
var referencedAssemblyNames = executingAssembly.GetReferencedAssemblies();
|
||||
var types = referencedAssemblyNames.SelectMany(
|
||||
name =>
|
||||
GetAssignableTypesFromAssembly<T>(Assembly.Load(name))
|
||||
)
|
||||
.Concat(
|
||||
GetAssignableTypesFromAssembly<T>(executingAssembly)
|
||||
)
|
||||
.ToList();
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(this string? str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user