ScriptEngine: Serialize static fields

This commit is contained in:
Simon Lübeß
2024-04-13 00:10:35 +02:00
parent df13aa8596
commit 949ab4ebb0
16 changed files with 504 additions and 244 deletions
@@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace GlitchyEngine.Extensions;
/// <summary>
/// Extends the <see cref="FieldInfo"/>-class with useful methods.
/// </summary>
public static class FieldInfoExtension
{
/// <summary>
/// Returns <see langword="true"/> if the field has the specified attribute.
/// </summary>
/// <typeparam name="T">The type of the attribte.</typeparam>
public static bool HasCustomAttribute<T>(this FieldInfo fiedInfo) where T : Attribute
{
return fiedInfo.GetCustomAttribute<T>() != null;
}
}
@@ -0,0 +1,19 @@
using System;
using System.Reflection;
namespace GlitchyEngine.Extensions;
/// <summary>
/// Extends <see cref="MemberInfo"/> with useful methods.
/// </summary>
public static class MemberInfoExtension
{
/// <summary>
/// Returns <see langword="true"/> if the member has the specified attribute.
/// </summary>
/// <typeparam name="T">The type of the attribute.</typeparam>
public static bool HasCustomAttribute<T>(this MemberInfo memberInfo) where T : Attribute
{
return memberInfo.GetCustomAttribute<T>() != null;
}
}
+13
View File
@@ -227,4 +227,17 @@ public static class TypeExtension
return nameBuilder.ToString();
}
/// <summary>
/// Returns <see langword="true"/> if the type has at least one static field; <see langword="false"/> otherwise.
/// </summary>
public static bool HasStaticFields(this Type type)
{
foreach (FieldInfo _ in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
{
return true;
}
return false;
}
}