static FormatterCache() { #if UNITY_2018_3_OR_NEWER && !NETFX_CORE var attr = (MessagePackFormatterAttribute)typeof(T).GetCustomAttributes(typeof(MessagePackFormatterAttribute), true).FirstOrDefault(); #else MessagePackFormatterAttribute attr = typeof(T).GetTypeInfo().GetCustomAttribute <MessagePackFormatterAttribute>(); #endif if (attr == null) { return; } var formatterType = attr.FormatterType; if (formatterType.IsGenericType && !formatterType.IsConstructedGenericType) { formatterType = formatterType.MakeGenericType(typeof(T).GetGenericArguments()); } if (attr.Arguments == null) { Formatter = (IMessagePackFormatter <T>)Activator.CreateInstance(formatterType); } else { Formatter = (IMessagePackFormatter <T>)Activator.CreateInstance(formatterType, attr.Arguments); } }
static FormatterCache() { #if UNITY_WSA && !NETFX_CORE var attr = (MessagePackFormatterAttribute)typeof(T).GetCustomAttributes(typeof(MessagePackFormatterAttribute), true).FirstOrDefault(); #else MessagePackFormatterAttribute attr = typeof(T).GetTypeInfo().GetCustomAttribute <MessagePackFormatterAttribute>(); #endif if (attr == null) { return; } if (attr.Arguments == null) { Formatter = (IMessagePackFormatter <T>)Activator.CreateInstance(attr.FormatterType); } else { Formatter = (IMessagePackFormatter <T>)Activator.CreateInstance(attr.FormatterType, attr.Arguments); } }