mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
ScriptEngine: Serialize static fields
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user