public static MethodInfo[] GetMethodsFor(Type item) { if (Cache.TryGetValue(item, out var res)) { return(res); } throw new LackingMethodsException(item); }
public static void InvokeMethod <TItem>(MethodInfo method, object instance, TItem item) { if (!MethodInfoCache.TryGetValue(method, out var invoke)) { invoke = method .GetSingleInvokable(); MethodInfoCache.TryAdd(method, invoke); } invoke(instance, item); }
internal static MessageDefinition GetDefinitionForType(Type type) { // cache if (Definitions.TryGetValue(type, out var res)) { return(res); } // if it is a message if (!AttributeCache <MessageAttribute> .TryHasAttribute(type, out var msgAttrib)) { res = default; Definitions.TryAdd(type, res); return(res); } var repeatable = AttributeCache <RepeatableAttribute> .TryHasAttribute(type, out var _); // store properties var props = type.GetProperties(); var max = 0; var msgProps = new MessageProperty[props.Length]; for (var j = 0; j < props.Length; j++) { var i = props[j]; if (HandleItem(i, out var prop)) { msgProps[max++] = prop; } } // resize the array if needed if (msgProps.Length != max) { var newMsgProps = new MessageProperty[max]; Array.Copy(msgProps, 0, newMsgProps, 0, max); msgProps = newMsgProps; } var msgDef = new MessageDefinition( msgAttrib[0].Type, msgProps, repeatable ); Definitions.TryAdd(type, msgDef); return(msgDef); }