mono.reflection-1.0+git20110407+d2343843/0000755000175000017500000000000011620311317017556 5ustar directhexdirecthexmono.reflection-1.0+git20110407+d2343843/Mono.Reflection.csproj0000755000175000017500000000513411620310714024007 0ustar directhexdirecthex Debug AnyCPU 9.0.30729 2.0 {97B010AB-0756-46DC-B75A-7A6C4F6FF28D} Library Properties Mono.Reflection Mono.Reflection v3.5 512 true mono.snk true full false bin\Debug\ DEBUG;TRACE prompt 4 pdbonly true bin\Release\ TRACE prompt 4 3.5 mono.reflection-1.0+git20110407+d2343843/mono.snk0000755000175000017500000000112411620310714021244 0ustar directhexdirecthex$RSA2y™wÒÐ:Žkêz.tèѯ̓è…t•+´€¡,‘4GM$GÃ~hÀ€SoÏNF^úÙÕ—.öžŸm6pª—/³ ±‰MŒñH‹Ö±/·F_I÷ ûµ.dËÄ/^d%F+øŠŠ¥±øŒ=Q¡Ð¢YåÚ_êz³®œÏ{õ i¬sÿ9­~À \¿@9Oñ©Ïmono.reflection-1.0+git20110407+d2343843/Mono.Reflection.nuspec0000644000175000017500000000160111620310714023774 0ustar directhexdirecthex Mono.Reflection 1.0.0.0 Mono.Reflection Jb Evain Jb Evain http://opensource.org/licenses/mit-license.php false http://github.com/jbevain/mono.reflection/ Complement for System.Reflection, including an IL disassembler. en-US assembly assemblies module modules il cil msil bytecode reflection disassembler mono.reflection-1.0+git20110407+d2343843/README0000755000175000017500000000123111620310714020436 0ustar directhexdirecthexMono.Reflection -- Mono.Reflection is an helper library to complement the System.Reflection and System.Reflection.Emit namespaces. It is known to work on both Mono 2.4 and .net 3.5. API -- bool Image.IsAssembly (string) bool Image.IsAssembly (Stream) Test whether a file is a managed assembly or not. FieldInfo BackingFieldResolver.GetBackingField (this PropertyInfo) Returns the field backing a property or throws an InvalidOperationException. IList Disassembler.GetInstructions (this MethodBase) Disassemble a list of IL instructions from the method body or throws an ArgumentException if the method doesn't provide a body. mono.reflection-1.0+git20110407+d2343843/Mono.Reflection.sln0000755000175000017500000000255511620310714023307 0ustar directhexdirecthexMicrosoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Reflection", "Mono.Reflection.csproj", "{97B010AB-0756-46DC-B75A-7A6C4F6FF28D}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Reflection.Tests", "Test\Mono.Reflection.Tests.csproj", "{51FCE249-1187-46EC-96A6-E507889E700D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {97B010AB-0756-46DC-B75A-7A6C4F6FF28D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {97B010AB-0756-46DC-B75A-7A6C4F6FF28D}.Debug|Any CPU.Build.0 = Debug|Any CPU {97B010AB-0756-46DC-B75A-7A6C4F6FF28D}.Release|Any CPU.ActiveCfg = Release|Any CPU {97B010AB-0756-46DC-B75A-7A6C4F6FF28D}.Release|Any CPU.Build.0 = Release|Any CPU {51FCE249-1187-46EC-96A6-E507889E700D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {51FCE249-1187-46EC-96A6-E507889E700D}.Debug|Any CPU.Build.0 = Debug|Any CPU {51FCE249-1187-46EC-96A6-E507889E700D}.Release|Any CPU.ActiveCfg = Release|Any CPU {51FCE249-1187-46EC-96A6-E507889E700D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/0000755000175000017500000000000011620310714022557 5ustar directhexdirecthexmono.reflection-1.0+git20110407+d2343843/Mono.Reflection/ILPattern.cs0000755000175000017500000001153511620310714024760 0ustar directhexdirecthex// // ILPattern.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Reflection.Emit; namespace Mono.Reflection { public abstract class ILPattern { public static ILPattern Optional (OpCode opcode) { return Optional (OpCode (opcode)); } public static ILPattern Optional (params OpCode [] opcodes) { return Optional (Sequence (opcodes.Select (opcode => OpCode (opcode)).ToArray ())); } public static ILPattern Optional (ILPattern pattern) { return new OptionalPattern (pattern); } class OptionalPattern : ILPattern { ILPattern pattern; public OptionalPattern (ILPattern optional) { this.pattern = optional; } public override void Match (MatchContext context) { pattern.TryMatch (context); } } public static ILPattern Sequence (params ILPattern [] patterns) { return new SequencePattern (patterns); } class SequencePattern : ILPattern { ILPattern [] patterns; public SequencePattern (ILPattern [] patterns) { this.patterns = patterns; } public override void Match (MatchContext context) { foreach (var pattern in patterns) { pattern.Match (context); if (!context.success) break; } } } public static ILPattern OpCode (OpCode opcode) { return new OpCodePattern (opcode); } class OpCodePattern : ILPattern { OpCode opcode; public OpCodePattern (OpCode opcode) { this.opcode = opcode; } public override void Match (MatchContext context) { if (context.instruction == null) { context.success = false; return; } context.success = context.instruction.OpCode == opcode; context.Advance (); } } public static ILPattern Either (ILPattern a, ILPattern b) { return new EitherPattern (a, b); } class EitherPattern : ILPattern { ILPattern a; ILPattern b; public EitherPattern (ILPattern a, ILPattern b) { this.a = a; this.b = b; } public override void Match (MatchContext context) { if (!a.TryMatch (context)) b.Match (context); } } public abstract void Match (MatchContext context); protected static Instruction GetLastMatchingInstruction (MatchContext context) { if (context.instruction == null) return null; return context.instruction.Previous; } public bool TryMatch (MatchContext context) { var instruction = context.instruction; Match (context); if (context.success) return true; context.Reset (instruction); return false; } public static MatchContext Match (MethodBase method, ILPattern pattern) { if (method == null) throw new ArgumentNullException ("method"); if (pattern == null) throw new ArgumentNullException ("pattern"); var instructions = method.GetInstructions (); if (instructions.Count == 0) throw new ArgumentException (); var context = new MatchContext (instructions [0]); pattern.Match (context); return context; } } public sealed class MatchContext { internal Instruction instruction; internal bool success; Dictionary data = new Dictionary (); public bool IsMatch { get { return success; } set { success = true; } } internal MatchContext (Instruction instruction) { Reset (instruction); } public bool TryGetData (object key, out object value) { return data.TryGetValue (key, out value); } public void AddData (object key, object value) { data.Add (key, value); } internal void Reset (Instruction instruction) { this.instruction = instruction; this.success = true; } internal void Advance () { this.instruction = this.instruction.Next; } } } mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/Image.cs0000755000175000017500000000614211620310714024136 0ustar directhexdirecthex// // Image.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.IO; namespace Mono.Reflection { public sealed class Image : IDisposable { long position; Stream stream; Image (Stream stream) { this.stream = stream; this.position = stream.Position; this.stream.Position = 0; } bool Advance (int length) { if (stream.Position + length >= stream.Length) return false; stream.Seek (length, SeekOrigin.Current); return true; } bool MoveTo (uint position) { if (position >= stream.Length) return false; stream.Position = position; return true; } void IDisposable.Dispose () { stream.Position = position; } ushort ReadUInt16 () { return (ushort) (stream.ReadByte () | (stream.ReadByte () << 8)); } uint ReadUInt32 () { return (uint) (stream.ReadByte () | (stream.ReadByte () << 8) | (stream.ReadByte () << 16) | (stream.ReadByte () << 24)); } bool IsManagedAssembly () { if (stream.Length < 318) return false; if (ReadUInt16 () != 0x5a4d) return false; if (!Advance (58)) return false; if (!MoveTo (ReadUInt32 ())) return false; if (ReadUInt32 () != 0x00004550) return false; if (!Advance (20)) return false; if (!Advance (ReadUInt16 () == 0x20b ? 222 : 206)) return false; return ReadUInt32 () != 0; } public static bool IsAssembly (string file) { if (file == null) throw new ArgumentNullException ("file"); using (var stream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read)) return IsAssembly (stream); } public static bool IsAssembly (Stream stream) { if (stream == null) throw new ArgumentNullException ("stream"); if (!stream.CanRead) throw new ArgumentException ("Can not read from stream"); if (!stream.CanSeek) throw new ArgumentException ("Can not seek in stream"); using (var image = new Image (stream)) return image.IsManagedAssembly (); } } } mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/BackingFieldResolver.cs0000755000175000017500000000664211620310714027145 0ustar directhexdirecthex// // BackingFieldResolver.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Reflection; using System.Reflection.Emit; namespace Mono.Reflection { public static class BackingFieldResolver { class FieldPattern : ILPattern { public static object FieldKey = new object (); ILPattern pattern; public FieldPattern (ILPattern pattern) { this.pattern = pattern; } public override void Match (MatchContext context) { pattern.Match (context); if (!context.success) return; var match = GetLastMatchingInstruction (context); var field = (FieldInfo) match.Operand; context.AddData (FieldKey, field); } } static ILPattern Field (OpCode opcode) { return new FieldPattern (ILPattern.OpCode (opcode)); } static ILPattern GetterPattern = ILPattern.Sequence ( ILPattern.Optional (OpCodes.Nop), ILPattern.Either ( Field (OpCodes.Ldsfld), ILPattern.Sequence ( ILPattern.OpCode (OpCodes.Ldarg_0), Field (OpCodes.Ldfld))), ILPattern.Optional ( ILPattern.Sequence ( ILPattern.OpCode (OpCodes.Stloc_0), ILPattern.OpCode (OpCodes.Br_S), ILPattern.OpCode (OpCodes.Ldloc_0))), ILPattern.OpCode (OpCodes.Ret)); static ILPattern SetterPattern = ILPattern.Sequence ( ILPattern.Optional (OpCodes.Nop), ILPattern.OpCode (OpCodes.Ldarg_0), ILPattern.Either ( Field (OpCodes.Stsfld), ILPattern.Sequence ( ILPattern.OpCode (OpCodes.Ldarg_1), Field (OpCodes.Stfld))), ILPattern.OpCode (OpCodes.Ret)); static FieldInfo GetBackingField (MethodInfo method, ILPattern pattern) { var result = ILPattern.Match (method, pattern); if (!result.success) throw new ArgumentException (); object value; if (!result.TryGetData (FieldPattern.FieldKey, out value)) throw new InvalidOperationException (); return (FieldInfo) value; } public static FieldInfo GetBackingField (this PropertyInfo self) { if (self == null) throw new ArgumentNullException ("self"); var getter = self.GetGetMethod (true); if (getter != null) return GetBackingField (getter, GetterPattern); var setter = self.GetSetMethod (true); if (setter != null) return GetBackingField (setter, SetterPattern); throw new ArgumentException (); } } } mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/MethodBodyReader.cs0000755000175000017500000001631411620310714026277 0ustar directhexdirecthex// // MethodBodyReader.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; namespace Mono.Reflection { class MethodBodyReader { static readonly OpCode [] one_byte_opcodes; static readonly OpCode [] two_bytes_opcodes; static MethodBodyReader () { one_byte_opcodes = new OpCode [0xe1]; two_bytes_opcodes = new OpCode [0x1f]; var fields = typeof (OpCodes).GetFields ( BindingFlags.Public | BindingFlags.Static); foreach (var field in fields) { var opcode = (OpCode) field.GetValue (null); if (opcode.OpCodeType == OpCodeType.Nternal) continue; if (opcode.Size == 1) one_byte_opcodes [opcode.Value] = opcode; else two_bytes_opcodes [opcode.Value & 0xff] = opcode; } } readonly MethodBase method; readonly MethodBody body; readonly Module module; readonly Type [] type_arguments; readonly Type [] method_arguments; readonly ByteBuffer il; readonly ParameterInfo [] parameters; readonly IList locals; readonly List instructions = new List (); MethodBodyReader (MethodBase method) { this.method = method; this.body = method.GetMethodBody (); if (this.body == null) throw new ArgumentException ("Method has no body"); var bytes = body.GetILAsByteArray (); if (bytes == null) throw new ArgumentException ("Can not get the body of the method"); if (!(method is ConstructorInfo)) method_arguments = method.GetGenericArguments (); if (method.DeclaringType != null) type_arguments = method.DeclaringType.GetGenericArguments (); this.parameters = method.GetParameters (); this.locals = body.LocalVariables; this.module = method.Module; this.il = new ByteBuffer (bytes); } void ReadInstructions () { Instruction previous = null; while (il.position < il.buffer.Length) { var instruction = new Instruction (il.position, ReadOpCode ()); ReadOperand (instruction); if (previous != null) { instruction.Previous = previous; previous.Next = instruction; } instructions.Add (instruction); previous = instruction; } ResolveBranches (); } void ReadOperand (Instruction instruction) { switch (instruction.OpCode.OperandType) { case OperandType.InlineNone: break; case OperandType.InlineSwitch: int length = il.ReadInt32 (); int base_offset = il.position + (4 * length); int [] branches = new int [length]; for (int i = 0; i < length; i++) branches [i] = il.ReadInt32 () + base_offset; instruction.Operand = branches; break; case OperandType.ShortInlineBrTarget: instruction.Operand = (((sbyte) il.ReadByte ()) + il.position); break; case OperandType.InlineBrTarget: instruction.Operand = il.ReadInt32 () + il.position; break; case OperandType.ShortInlineI: if (instruction.OpCode == OpCodes.Ldc_I4_S) instruction.Operand = (sbyte) il.ReadByte (); else instruction.Operand = il.ReadByte (); break; case OperandType.InlineI: instruction.Operand = il.ReadInt32 (); break; case OperandType.ShortInlineR: instruction.Operand = il.ReadSingle (); break; case OperandType.InlineR: instruction.Operand = il.ReadDouble (); break; case OperandType.InlineI8: instruction.Operand = il.ReadInt64 (); break; case OperandType.InlineSig: instruction.Operand = module.ResolveSignature (il.ReadInt32 ()); break; case OperandType.InlineString: instruction.Operand = module.ResolveString (il.ReadInt32 ()); break; case OperandType.InlineTok: case OperandType.InlineType: case OperandType.InlineMethod: case OperandType.InlineField: instruction.Operand = module.ResolveMember (il.ReadInt32 (), type_arguments, method_arguments); break; case OperandType.ShortInlineVar: instruction.Operand = GetVariable (instruction, il.ReadByte ()); break; case OperandType.InlineVar: instruction.Operand = GetVariable (instruction, il.ReadInt16 ()); break; default: throw new NotSupportedException (); } } void ResolveBranches () { foreach (var instruction in instructions) { switch (instruction.OpCode.OperandType) { case OperandType.ShortInlineBrTarget: case OperandType.InlineBrTarget: instruction.Operand = GetInstruction (instructions, (int) instruction.Operand); break; case OperandType.InlineSwitch: var offsets = (int []) instruction.Operand; var branches = new Instruction [offsets.Length]; for (int j = 0; j < offsets.Length; j++) branches [j] = GetInstruction (instructions, offsets [j]); instruction.Operand = branches; break; } } } static Instruction GetInstruction (List instructions, int offset) { var size = instructions.Count; if (offset < 0 || offset > instructions [size - 1].Offset) return null; int min = 0; int max = size - 1; while (min <= max) { int mid = min + ((max - min) / 2); var instruction = instructions [mid]; var instruction_offset = instruction.Offset; if (offset == instruction_offset) return instruction; if (offset < instruction_offset) max = mid - 1; else min = mid + 1; } return null; } object GetVariable (Instruction instruction, int index) { if (TargetsLocalVariable (instruction.OpCode)) return GetLocalVariable (index); return GetParameter (index); } static bool TargetsLocalVariable (OpCode opcode) { return opcode.Name.Contains ("loc"); } LocalVariableInfo GetLocalVariable (int index) { return locals [index]; } ParameterInfo GetParameter (int index) { if (!method.IsStatic) index--; return parameters [index]; } OpCode ReadOpCode () { byte op = il.ReadByte (); return op != 0xfe ? one_byte_opcodes [op] : two_bytes_opcodes [il.ReadByte ()]; } public static List GetInstructions (MethodBase method) { var reader = new MethodBodyReader (method); reader.ReadInstructions (); return reader.instructions; } } } mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/Instruction.cs0000755000175000017500000000745711620310714025447 0ustar directhexdirecthex// // Instruction.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Reflection.Emit; using System.Text; namespace Mono.Reflection { public sealed class Instruction { int offset; OpCode opcode; object operand; Instruction previous; Instruction next; public int Offset { get { return offset; } } public OpCode OpCode { get { return opcode; } } public object Operand { get { return operand; } internal set { operand = value; } } public Instruction Previous { get { return previous; } internal set { previous = value; } } public Instruction Next { get { return next; } internal set { next = value; } } public int Size { get { int size = opcode.Size; switch (opcode.OperandType) { case OperandType.InlineSwitch: size += (1 + ((int []) operand).Length) * 4; break; case OperandType.InlineI8: case OperandType.InlineR: size += 8; break; case OperandType.InlineBrTarget: case OperandType.InlineField: case OperandType.InlineI: case OperandType.InlineMethod: case OperandType.InlineString: case OperandType.InlineTok: case OperandType.InlineType: case OperandType.ShortInlineR: size += 4; break; case OperandType.InlineVar: size += 2; break; case OperandType.ShortInlineBrTarget: case OperandType.ShortInlineI: case OperandType.ShortInlineVar: size += 1; break; } return size; } } internal Instruction (int offset, OpCode opcode) { this.offset = offset; this.opcode = opcode; } public override string ToString () { var instruction = new StringBuilder (); AppendLabel (instruction, this); instruction.Append (':'); instruction.Append (' '); instruction.Append (opcode.Name); if (operand == null) return instruction.ToString (); instruction.Append (' '); switch (opcode.OperandType) { case OperandType.ShortInlineBrTarget: case OperandType.InlineBrTarget: AppendLabel (instruction, (Instruction) operand); break; case OperandType.InlineSwitch: var labels = (Instruction []) operand; for (int i = 0; i < labels.Length; i++) { if (i > 0) instruction.Append (','); AppendLabel (instruction, labels [i]); } break; case OperandType.InlineString: instruction.Append ('\"'); instruction.Append (operand); instruction.Append ('\"'); break; default: instruction.Append (operand); break; } return instruction.ToString (); } static void AppendLabel (StringBuilder builder, Instruction instruction) { builder.Append ("IL_"); builder.Append (instruction.offset.ToString ("x4")); } } } mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/Disassembler.cs0000755000175000017500000000304411620310714025527 0ustar directhexdirecthex// // Disassembler.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Collections.Generic; using System.Reflection; namespace Mono.Reflection { public static class Disassembler { public static IList GetInstructions (this MethodBase self) { if (self == null) throw new ArgumentNullException ("self"); return MethodBodyReader.GetInstructions (self).AsReadOnly (); } } } mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/AssemblyInfo.cs0000755000175000017500000000117211620310714025505 0ustar directhexdirecthexusing System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle ("Mono.Reflection")] [assembly: AssemblyDescription ("")] [assembly: AssemblyConfiguration ("")] [assembly: AssemblyCompany ("Novell, Inc.")] [assembly: AssemblyProduct ("Mono.Reflection")] [assembly: AssemblyCopyright ("Copyright © Novell, Inc. 2009 - 2010")] [assembly: AssemblyTrademark ("")] [assembly: AssemblyCulture ("")] [assembly: ComVisible (false)] [assembly: Guid ("61b023e8-6ba6-4fa3-8026-3841abdba125")] [assembly: AssemblyVersion ("1.0.0.0")] [assembly: AssemblyFileVersion ("1.0.0.0")] mono.reflection-1.0+git20110407+d2343843/Mono.Reflection/ByteBuffer.cs0000755000175000017500000000631511620310714025153 0ustar directhexdirecthex// // ByteBuffer.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; namespace Mono.Reflection { class ByteBuffer { internal byte [] buffer; internal int position; public ByteBuffer (byte [] buffer) { this.buffer = buffer; } public byte ReadByte () { CheckCanRead (1); return buffer [position++]; } public byte [] ReadBytes (int length) { CheckCanRead (length); var value = new byte [length]; Buffer.BlockCopy (buffer, position, value, 0, length); position += length; return value; } public short ReadInt16 () { CheckCanRead (2); short value = (short) (buffer [position] | (buffer [position + 1] << 8)); position += 2; return value; } public int ReadInt32 () { CheckCanRead (4); int value = buffer [position] | (buffer [position + 1] << 8) | (buffer [position + 2] << 16) | (buffer [position + 3] << 24); position += 4; return value; } public long ReadInt64 () { CheckCanRead (8); uint low = (uint) (buffer [position] | (buffer [position + 1] << 8) | (buffer [position + 2] << 16) | (buffer [position + 3] << 24)); uint high = (uint) (buffer [position + 4] | (buffer [position + 5] << 8) | (buffer [position + 6] << 16) | (buffer [position + 7] << 24)); long value = (((long) high) << 32) | low; position += 8; return value; } public float ReadSingle () { if (!BitConverter.IsLittleEndian) { var bytes = ReadBytes (4); Array.Reverse (bytes); return BitConverter.ToSingle (bytes, 0); } CheckCanRead (4); float value = BitConverter.ToSingle (buffer, position); position += 4; return value; } public double ReadDouble () { if (!BitConverter.IsLittleEndian) { var bytes = ReadBytes (8); Array.Reverse (bytes); return BitConverter.ToDouble (bytes, 0); } CheckCanRead (8); double value = BitConverter.ToDouble (buffer, position); position += 8; return value; } void CheckCanRead (int count) { if (position + count > buffer.Length) throw new ArgumentOutOfRangeException (); } } } mono.reflection-1.0+git20110407+d2343843/Test/0000755000175000017500000000000011620311317020475 5ustar directhexdirecthexmono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection.Tests.csproj0000755000175000017500000000600711620310714026027 0ustar directhexdirecthex Debug AnyCPU 9.0.30729 2.0 {51FCE249-1187-46EC-96A6-E507889E700D} Library Properties Mono.Reflection.Tests Mono.Reflection.Tests v3.5 512 true full false bin\Debug\ DEBUG;TRACE prompt 4 AllRules.ruleset pdbonly true bin\Release\ TRACE prompt 4 AllRules.ruleset 3.5 {97B010AB-0756-46DC-B75A-7A6C4F6FF28D} Mono.Reflection target.dll mono.reflection-1.0+git20110407+d2343843/Test/target.il0000755000175000017500000000632211620310714022317 0ustar directhexdirecthex.assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89) .ver 2:0:0:0 } .assembly target {} .module target.dll .class private Test extends [mscorlib]System.Object { .method public specialname rtspecialname instance void .ctor () cil managed { ldarg.0 call instance void [mscorlib]System.Object::.ctor () ret } .field private string str .method public instance string ReadField () cil managed { ldarg.0 ldfld string Test::str ret } .method public instance void WriteField (string val) cil managed { ldarg.0 ldarg val stfld string Test::str ret } .method public instance class [mscorlib]System.Type TypeOfString () cil managed { ldtoken [mscorlib]System.String call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle (valuetype [mscorlib]System.RuntimeTypeHandle) ret } .method public instance int32 ShortBranch (int32 i) cil managed { ldarg.1 ldc.i4.0 ble.s negative ldarg.1 ret negative: ldc.i4.m1 ret } .method public instance int32 Branch (int32 i) cil managed { ldarg.1 ldc.i4.0 ble negative ldarg.1 ret negative: ldc.i4.m1 ret } .method public instance int32 Switch (int32 i) cil managed { ldarg.1 switch (zero, one, two, other) br.s other zero: ldc.i4.0 ret one: ldc.i4.1 ret two: ldc.i4.2 ret other: ldc.i4.m1 ret } // optimized instance property .field private bool opan .property instance bool OPan () { .get instance bool Test::get_OPan () .set instance void Test::set_OPan (bool) } .method public hidebysig specialname instance bool get_OPan () cil managed { ldarg.0 ldfld bool Test::opan ret } .method public hidebysig specialname instance void set_OPan (bool val) cil managed { ldarg.0 ldarg.1 stfld bool Test::opan ret } // optimized static property .field private static bool sopan .property bool SOPan () { .get bool Test::get_SOPan () .set void Test::set_SOPan (bool) } .method public hidebysig specialname static bool get_SOPan () cil managed { ldsfld bool Test::sopan ret } .method public hidebysig specialname static void set_SOPan (bool val) cil managed { ldarg.0 stsfld bool Test::sopan ret } // unoptimized instance property .field private bool upan .property instance bool UPan () { .get instance bool Test::get_UPan () .set instance void Test::set_UPan (bool) } .method public hidebysig specialname instance bool get_UPan () cil managed { .locals init (bool b) nop ldarg.0 ldfld bool Test::upan stloc.0 br.s retval retval: ldloc.0 ret } .method public hidebysig specialname instance void set_UPan (bool val) cil managed { nop ldarg.0 ldarg.1 stfld bool Test::upan ret } // unoptimized static property .field private static bool supan .property bool SUPan () { .get bool Test::get_SUPan () .set void Test::set_SUPan (bool) } .method public hidebysig specialname static bool get_SUPan () cil managed { .locals init (bool val) nop ldsfld bool Test::supan stloc.0 br.s retval retval: ldloc.0 ret } .method public hidebysig specialname static void set_SUPan (bool val) cil managed { nop ldarg.0 stsfld bool Test::supan ret } } mono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection/0000755000175000017500000000000011620310714023476 5ustar directhexdirecthexmono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection/DisassemblerTest.cs0000755000175000017500000000607211620310714027312 0ustar directhexdirecthex// // DisassemblerTest.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.IO; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; namespace Mono.Reflection { [TestFixture] public class DisassemblerTest : BaseReflectionTest { [Test] public void DefaultConstructor () { AssertMethod (@" IL_0000: ldarg.0 IL_0001: call void System.Object::.ctor() IL_0006: ret ", ".ctor"); } [Test] public void ReadField () { AssertMethod (@" IL_0000: ldarg.0 IL_0001: ldfld string Test::str IL_0006: ret ", "ReadField"); } [Test] public void WriteField () { AssertMethod (@" IL_0000: ldarg.0 IL_0001: ldarg val IL_0005: stfld string Test::str IL_000a: ret ", "WriteField"); } [Test] public void TypeOfString () { AssertMethod (@" IL_0000: ldtoken string IL_0005: call System.Type System.Type::GetTypeFromHandle(System.RuntimeTypeHandle) IL_000a: ret ", "TypeOfString"); } [Test] public void ShortBranch () { AssertMethod (@" IL_0000: ldarg.1 IL_0001: ldc.i4.0 IL_0002: ble.s IL_0006 IL_0004: ldarg.1 IL_0005: ret IL_0006: ldc.i4.m1 IL_0007: ret ", "ShortBranch"); } [Test] public void Branch () { AssertMethod (@" IL_0000: ldarg.1 IL_0001: ldc.i4.0 IL_0002: ble IL_0009 IL_0007: ldarg.1 IL_0008: ret IL_0009: ldc.i4.m1 IL_000a: ret ", "Branch"); } [Test] public void Switch () { AssertMethod (@" IL_0000: ldarg.1 IL_0001: switch (IL_0018, IL_001a, IL_001c, IL_001e) IL_0016: br.s IL_001e IL_0018: ldc.i4.0 IL_0019: ret IL_001a: ldc.i4.1 IL_001b: ret IL_001c: ldc.i4.2 IL_001d: ret IL_001e: ldc.i4.m1 IL_001f: ret ", "Switch"); } static void AssertMethod (string code, string method_name) { var method = GetMethod (method_name); Assert.AreEqual (Normalize (code), Normalize (Formatter.FormatMethodBody (method))); } static string Normalize (string str) { return str.Trim ().Replace ("\r\n", "\n"); } } } mono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection/BaseReflectionTest.cs0000755000175000017500000000503411620310714027557 0ustar directhexdirecthex// // DisassemblerTest.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.IO; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; namespace Mono.Reflection { public abstract class BaseReflectionTest { protected static MethodBase GetMethod (string name) { return test_target.GetType ("Test").GetMember (name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance) [0] as MethodBase; } protected static PropertyInfo GetProperty (string name) { return test_target.GetType ("Test").GetProperty (name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); } protected static FieldInfo GetField (string name) { return test_target.GetType ("Test").GetField (name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); } static Assembly test_target = LoadTestTarget (); static Assembly LoadTestTarget () { var stream = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("target.dll"); return Assembly.Load (ToArray (stream)); } static byte [] ToArray (Stream stream) { var buffer = new byte [16 * 1024]; using (MemoryStream ms = new MemoryStream ()) { int read; while ((read = stream.Read (buffer, 0, buffer.Length)) > 0) ms.Write (buffer, 0, read); return ms.ToArray (); } } } } mono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection/Formatter.cs0000755000175000017500000001423311620310714025776 0ustar directhexdirecthex// // Formatter.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.IO; using System.Reflection; using System.Reflection.Emit; using System.Text; namespace Mono.Reflection { public static class Formatter { public static string FormatInstruction (Instruction instruction) { var writer = new StringWriter (); WriteInstruction (writer, instruction); return writer.ToString (); } public static string FormatMethodBody (MethodBase method) { var writer = new StringWriter (); WriteMethodBody (writer, method); return writer.ToString (); } public static void WriteMethodBody (TextWriter writer, MethodBase method) { foreach (var instruction in method.GetInstructions ()) { writer.Write ('\t'); WriteInstruction (writer, instruction); writer.WriteLine (); } } public static void WriteInstruction (TextWriter writer, Instruction instruction) { writer.Write (FormatLabel (instruction.Offset)); writer.Write (": "); writer.Write (instruction.OpCode.Name); WriteOperand (writer, instruction); } static string FormatLabel (int offset) { string label = "000" + offset.ToString ("x"); return "IL_" + label.Substring (label.Length - 4); } static string FormatLabel (Instruction instruction) { return FormatLabel (instruction.Offset); } static bool TargetsLocalVariable (OpCode opcode) { return opcode.Name.Contains ("loc"); } static void WriteOperand (TextWriter writer, Instruction instruction) { var opcode = instruction.OpCode; var operand = instruction.Operand; if (opcode.OperandType == OperandType.InlineNone) return; writer.Write (' '); switch (opcode.OperandType) { case OperandType.ShortInlineBrTarget: case OperandType.InlineBrTarget: writer.Write (FormatLabel ((Instruction) operand)); return; case OperandType.InlineSwitch: WriteLabelList (writer, (Instruction []) operand); return; case OperandType.InlineString: writer.Write ("\"" + operand.ToString () + "\""); return; case OperandType.ShortInlineVar: case OperandType.InlineVar: if (TargetsLocalVariable (opcode)) { var local = (LocalVariableInfo) operand; writer.Write ("V_{0}", local.LocalIndex); return; } var parameter = (ParameterInfo) operand; writer.Write (parameter.Name); return; case OperandType.InlineTok: case OperandType.InlineType: case OperandType.InlineMethod: case OperandType.InlineField: var member = (MemberInfo) operand; switch (member.MemberType) { case MemberTypes.Constructor: case MemberTypes.Method: WriteMethodReference (writer, (MethodBase) member); return; case MemberTypes.Field: WriteFieldReference (writer, (FieldInfo) member); return; case MemberTypes.TypeInfo: case MemberTypes.NestedType: writer.Write (FormatTypeReference ((Type) member)); return; default: throw new NotSupportedException (); } case OperandType.InlineI: case OperandType.ShortInlineI: case OperandType.InlineR: case OperandType.ShortInlineR: case OperandType.InlineI8: writer.Write (ToInvariantCultureString (operand)); return; default: throw new NotSupportedException (); } } static void WriteLabelList (TextWriter writer, Instruction [] targets) { writer.Write ("("); for (int i = 0; i < targets.Length; i++) { if (i != 0) writer.Write (", "); writer.Write (FormatLabel (targets [i])); } writer.Write (")"); } static string ToInvariantCultureString (object value) { IConvertible convertible = value as IConvertible; return (null != convertible) ? convertible.ToString (System.Globalization.CultureInfo.InvariantCulture) : value.ToString (); } static void WriteFieldReference (TextWriter writer, FieldInfo field) { writer.Write (FormatTypeReference (field.FieldType)); writer.Write (' '); writer.Write (field.DeclaringType.FullName); writer.Write ("::"); writer.Write (field.Name); } static void WriteMethodReference (TextWriter writer, MethodBase method) { writer.Write (method is ConstructorInfo ? FormatTypeReference (typeof (void)) : FormatTypeReference (((MethodInfo) method).ReturnType)); writer.Write (' '); writer.Write (method.DeclaringType.FullName); writer.Write ("::"); writer.Write (method.Name); writer.Write ("("); var parameters = method.GetParameters (); for (int i = 0; i < parameters.Length; ++i) { if (i > 0) writer.Write (", "); writer.Write (FormatTypeReference (parameters [i].ParameterType)); } writer.Write (")"); } static string FormatTypeReference (Type type) { string name = type.FullName; switch (name) { case "System.Void": return "void"; case "System.String": return "string"; case "System.Int16": return "int16"; case "System.Int32": return "int32"; case "System.Long": return "int64"; case "System.Boolean": return "bool"; case "System.Single": return "float32"; case "System.Double": return "float64"; default: return name; } } } } mono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection/AssemblyInfo.cs0000755000175000017500000000120611620310714026422 0ustar directhexdirecthexusing System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle ("Mono.Reflection.Tests")] [assembly: AssemblyDescription ("")] [assembly: AssemblyConfiguration ("")] [assembly: AssemblyCompany ("Novell, Inc.")] [assembly: AssemblyProduct ("Mono.Reflection.Tests")] [assembly: AssemblyCopyright ("Copyright © Novell, Inc. 2009 - 2010")] [assembly: AssemblyTrademark ("")] [assembly: AssemblyCulture ("")] [assembly: ComVisible (false)] [assembly: Guid ("5f470471-07a4-4f0a-b33c-986b559528f6")] [assembly: AssemblyVersion ("1.0.0.0")] [assembly: AssemblyFileVersion ("1.0.0.0")] mono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection/ImageTest.cs0000755000175000017500000000304711620310714025716 0ustar directhexdirecthex// // ImageTest.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.IO; using NUnit.Framework; namespace Mono.Reflection { [TestFixture] public class ImageTest : BaseReflectionTest { [Test] public void Assembly () { Assert.IsTrue (Image.IsAssembly ("Mono.Reflection.dll")); } [Test] public void NotAssembly () { Assert.IsFalse (Image.IsAssembly ("Mono.Reflection.pdb")); } } } mono.reflection-1.0+git20110407+d2343843/Test/Mono.Reflection/BackingFieldResolverTest.cs0000755000175000017500000000403111620310714030712 0ustar directhexdirecthex// // DisassemblerTest.cs // // Author: // Jb Evain (jbevain@novell.com) // // (C) 2009 - 2010 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.IO; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; namespace Mono.Reflection { [TestFixture] public class BackingFieldResolverTest : BaseReflectionTest { [Test] public void StaticOptimizedProperty () { AssertBackingField ("sopan", "SOPan"); } [Test] public void StaticUnoptimizedProperty () { AssertBackingField ("supan", "SUPan"); } [Test] public void InstanceOptimizedProperty () { AssertBackingField ("opan", "OPan"); } [Test] public void InstanceUnoptimizedProperty () { AssertBackingField ("upan", "UPan"); } static void AssertBackingField (string field_name, string property_name) { var field = GetField (field_name); var property = GetProperty (property_name); Assert.AreEqual (field, property.GetBackingField ()); } } }