-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCecilEnumSerializerFactory.cs
More file actions
30 lines (24 loc) · 1008 Bytes
/
CecilEnumSerializerFactory.cs
File metadata and controls
30 lines (24 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using Mono.Cecil;
namespace Stride.Core.AssemblyProcessor;
/// <summary>
/// Generates enum serializer type from a given enum type.
/// </summary>
public class CecilEnumSerializerFactory : ICecilSerializerFactory
{
private readonly TypeReference genericEnumSerializerType;
public CecilEnumSerializerFactory(TypeReference genericEnumSerializerType)
{
this.genericEnumSerializerType = genericEnumSerializerType;
}
public TypeReference? GetSerializer(TypeReference objectType)
{
var resolvedObjectType = objectType.Resolve();
if (resolvedObjectType?.IsEnum == true)
{
return genericEnumSerializerType.MakeGenericType(objectType);
}
return null;
}
}