chore: memberInfo.HasAttribute method added

This commit is contained in:
Syntriax 2025-04-22 21:08:46 +03:00 committed by Syntriax
parent a3a8fb4e84
commit 336e7e16e7
3 changed files with 6 additions and 5 deletions

View File

@ -62,7 +62,7 @@ public class InstanceConverter : IEngineTypeYamlConverter
foreach (PropertyInfo propertyInfo in typeData.Properties)
{
if (propertyInfo.GetCustomAttribute<IgnoreSerializationAttribute>() is not null)
if (propertyInfo.HasAttribute<IgnoreSerializationAttribute>())
continue;
emitter.Emit(new Scalar(propertyInfo.Name));
@ -78,11 +78,11 @@ public class InstanceConverter : IEngineTypeYamlConverter
foreach (FieldInfo fieldInfo in typeData.Fields)
{
if (fieldInfo.GetCustomAttribute<System.Runtime.CompilerServices.CompilerGeneratedAttribute>() is not null)
if (fieldInfo.HasAttribute<System.Runtime.CompilerServices.CompilerGeneratedAttribute>())
continue;
// if (fieldInfo.GetCustomAttribute<SerializeAttribute>() is null)
// continue;
if (!fieldInfo.HasAttribute<SerializeAttribute>())
continue;
emitter.Emit(new Scalar(fieldInfo.Name));
object? fieldValue = fieldInfo.GetValue(value);

View File

@ -9,7 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\Engine.Core\Engine.Core.csproj" />
<ProjectReference Include="..\..\YamlDotNet\YamlDotNet\YamlDotNet.csproj" />
<ProjectReference Include="..\YamlDotNet\YamlDotNet\YamlDotNet.csproj" />
</ItemGroup>
</Project>

View File

@ -4,6 +4,7 @@ namespace Syntriax.Engine.Serialization;
internal static class Utils
{
internal static bool HasAttribute<T>(this MemberInfo memberInfo) where T : Attribute => memberInfo.GetCustomAttribute<T>() is not null;
internal static bool IsEnumerable(this Type type) => typeof(System.Collections.IEnumerable).IsAssignableFrom(type) && type != typeof(string);
internal static TypeData GetTypeData(this Type objectType)