void ExecuteSnippet(ProfilingAction action, ProfilingSnippet snippet) { var preExecutePayload = snippet.PreExecute(m_Options); var executePayload = action.action(preExecutePayload, snippet, m_Options); snippet.PostExecute(executePayload, m_Options); }
private static IEnumerable <ProfilingAction> GetProfilingSnippetActions() { return(Utils.GetAllMethodsWithAttribute <ProfilingActionAttribute>().Select(methodInfo => { var action = new ProfilingAction(); action.name = methodInfo.GetCustomAttributes(typeof(ProfilingActionAttribute), false).Cast <ProfilingActionAttribute>().First().name; try { if (methodInfo.ReturnType == typeof(void)) { var d = Delegate.CreateDelegate(typeof(Action <object, ProfilingSnippet, ProfilingSnippetOptions>), methodInfo) as Action <object, ProfilingSnippet, ProfilingSnippetOptions>; action.action = (o, s, options) => { d(o, s, options); return null; }; } else { action.action = Delegate.CreateDelegate(typeof(Func <object, ProfilingSnippet, ProfilingSnippetOptions, object>), methodInfo) as Func <object, ProfilingSnippet, ProfilingSnippetOptions, object>; } } catch (Exception ex) { Debug.LogError($"Cannot create delegate for ProfilingAction: {action.name}: {ex.Message}"); return null; } return action; }).Where(a => a != null)); }