-
-
Save ApocDev/037565557874c65f3198f962459eb447 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// A simple type cache to alleviate the reflection lookups. Checking for simple types is done once per type | |
| /// encountered. Rather than every time. (Saves many CPU cycles. Reflection is slow) | |
| /// </summary> | |
| /// <typeparam name="T"></typeparam> | |
| public static class TypeCache<T> | |
| { | |
| static TypeCache() | |
| { | |
| Type = typeof(T); | |
| IsSimpleType = true; | |
| switch (Type.GetTypeCode(Type)) | |
| { | |
| case TypeCode.Object: | |
| case TypeCode.DBNull: | |
| case TypeCode.Empty: | |
| case TypeCode.DateTime: | |
| IsSimpleType = false; | |
| break; | |
| } | |
| } | |
| // ReSharper disable StaticMemberInGenericType | |
| public static bool IsSimpleType { get; } | |
| public static Type Type { get; } | |
| // ReSharper restore StaticMemberInGenericType | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment