Aetheria/Assets/Scripts/MessagePack/Internal/ReflectionExtensions.cs
hyperion51 a0c8dbee72 Initial Client/Server Communication
#1
Followed the MagicOnion quickstart guide, borrowing code from the chat sample app to get something working
2020-02-26 17:48:40 +00:00

49 lines
1.6 KiB
C#

// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Reflection;
using System.Runtime.CompilerServices;
namespace MessagePack.Internal
{
internal static class ReflectionExtensions
{
public static bool IsNullable(this System.Reflection.TypeInfo type)
{
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Nullable<>);
}
public static bool IsPublic(this System.Reflection.TypeInfo type)
{
return type.IsPublic;
}
public static bool IsAnonymous(this System.Reflection.TypeInfo type)
{
return type.GetCustomAttribute<CompilerGeneratedAttribute>() != null
&& type.IsGenericType && type.Name.Contains("AnonymousType")
&& (type.Name.StartsWith("<>") || type.Name.StartsWith("VB$"))
&& (type.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic;
}
public static bool IsIndexer(this System.Reflection.PropertyInfo propertyInfo)
{
return propertyInfo.GetIndexParameters().Length > 0;
}
public static bool IsConstructedGenericType(this System.Reflection.TypeInfo type)
{
return type.AsType().IsConstructedGenericType;
}
public static MethodInfo GetGetMethod(this PropertyInfo propInfo)
{
return propInfo.GetMethod;
}
public static MethodInfo GetSetMethod(this PropertyInfo propInfo)
{
return propInfo.SetMethod;
}
}
}