1
0
mirror of https://github.com/aelurum/AssetStudio.git synced 2025-08-15 06:54:27 -04:00
Files
.github
AssetStudio
AssetStudio.PInvoke
AssetStudioCLI
AssetStudioFBXNative
AssetStudioFBXWrapper
AssetStudioGUI
AssetStudioUtility
Audio
CSspv
Disassembler.cs
EnumValuesExtensions.cs
Instruction.cs
LICENSE
Module.cs
OperandType.cs
ParsedInstruction.cs
Reader.cs
SpirV.Core.Grammar.cs
SpirV.Meta.cs
Types.cs
CubismLive2DExtractor
Smolv
Unity.CecilTools
Unity.SerializationLogic
AssemblyLoader.cs
AssetStudioUtility.csproj
ImageExtensions.cs
ImageFormat.cs
ModelConverter.cs
ModelExporter.cs
MonoBehaviourConverter.cs
MyAssemblyResolver.cs
SerializedTypeHelper.cs
ShaderConverter.cs
SpirVShaderConverter.cs
SpriteHelper.cs
Texture2DConverter.cs
Texture2DExtensions.cs
Texture2DSwitchDeswizzler.cs
TypeDefinitionConverter.cs
Texture2DDecoderNative
Texture2DDecoderWrapper
.gitattributes
.gitignore
AssetStudio.sln
CHANGELOG.md
LICENSE
README.md
AssetStudio/AssetStudioUtility/CSspv/EnumValuesExtensions.cs
2020-08-12 22:11:26 +08:00

42 lines
1.0 KiB
C#

#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6
using System;
using System.Linq;
using System.Reflection;
namespace SpirV
{
public static class EnumValuesExtensions
{
public static Array GetEnumValues(this System.Type _this)
{
TypeInfo typeInfo = _this.GetTypeInfo ();
if (!typeInfo.IsEnum) {
throw new ArgumentException ("GetEnumValues: Type '" + _this.Name + "' is not an enum");
}
return
(
from field in typeInfo.DeclaredFields
where field.IsLiteral
select field.GetValue (null)
)
.ToArray();
}
public static string GetEnumName(this System.Type _this, object value)
{
TypeInfo typeInfo = _this.GetTypeInfo ();
if (!typeInfo.IsEnum) {
throw new ArgumentException ("GetEnumName: Type '" + _this.Name + "' is not an enum");
}
return
(
from field in typeInfo.DeclaredFields
where field.IsLiteral && (uint)field.GetValue(null) == (uint)value
select field.Name
)
.First();
}
}
}
#endif