List <LocalVariableInfo> GetLocals() { DynamicMethod dm = ReflectionExtensions.TryGetDynamicMethod( this.method as MethodInfo) ?? this.method as DynamicMethod; if (dm != null) { var localSig = dm.GetLocalSignature(); List <LocalVariableInfo> locals = null; using (var reader = new System.IO.BinaryReader( new System.IO.MemoryStream(localSig))) { VariableFlags flags; var ilr = new ILReader(reader, resolver); var sig = ilr.ReadByte(); if (sig != 0x7) { throw new System.IO.InvalidDataException( "Signature code is not valid"); } // read the compressed local count value var localCount = ilr.ReadSerializedInt32(); locals = new List <LocalVariableInfo>(localCount); // read and resolve the local type signatures for (int i = 0; i < localCount; ++i) { var type = ilr.ReadTypeSignature(out flags); locals.Add(new LocalVariableInfo(i, type, (flags | VariableFlags.Pinned) == VariableFlags.Pinned)); } } return(locals); } else { return(this.method.GetMethodBody()?.LocalVariables .Select(lvi => new LocalVariableInfo( lvi.LocalIndex, lvi.LocalType, lvi.IsPinned)) .ToList()); } }