public SyntaxTree Read(Delegate @delegate) { Contract.Assert(@delegate != null); try { return(_cache.GetOrAdd(@delegate, key => new Lazy <SyntaxTree>(() => _actualReader.Read(key), LazyThreadSafetyMode.ExecutionAndPublication)).Value); } catch (Exception) { _cache.TryRemove(@delegate, out _); throw; } }
public static DecompilationResult CreateFromDelegate <TCursor, TRes>(IDelegateReader reader, Function <TCursor, TRes> function) { var method = reader.Read(function)?.FirstMethodOrDefault(); if (method is null) { throw new Exception("Unable to extract method from delegate"); } var parameters = method.Parameters.ToArray(); if (parameters.Length != 3) { throw new Exception($"Expected method with 3 arguments, got {parameters.Length}"); } var cursorName = parameters[0].Name; var argsName = parameters[1].Name; var keysName = parameters[2].Name; return(new DecompilationResult(method.Body, cursorName, argsName, keysName)); }
static SyntaxTree GetSyntaxTree(MyFunc func) { return(reader.Read(func)); }