This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Mono.Cecil; | |
using LinFu.AOP.Interfaces; | |
using LinFu.AOP.Cecil; | |
namespace CSLInjectionDemo | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PropertyGroup> | |
<PostWeaveTaskLocation>$(MSBuildProjectDirectory)\$(OutputPath)\..\..\..\lib\LinFu.Core.dll</PostWeaveTaskLocation> | |
</PropertyGroup> | |
<UsingTask TaskName="PostWeaveTask" AssemblyFile="$(PostWeaveTaskLocation)" /> | |
<Target Name="AfterBuild"> | |
<PostWeaveTask TargetFile="$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).dll" InterceptAllExceptions="true" /> | |
</Target> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleExceptionHandler : IExceptionHandler | |
{ | |
public bool CanCatch(IExceptionHandlerInfo exceptionHandlerInfo) | |
{ | |
return true; | |
} | |
public void Catch(IExceptionHandlerInfo exceptionHandlerInfo) | |
{ | |
var exception = exceptionHandlerInfo.Exception; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IExceptionHandlerInfo | |
{ | |
Exception Exception { get; } | |
IInvocationInfo InvocationInfo { get; } | |
object ReturnValue { get; set; } | |
bool ShouldSkipRethrow { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void ModifyTargetMethod(MethodDefinition targetMethod) | |
{ | |
// In this example, we are going to redirect all Console.WriteLine calls | |
// to the FakeConsole.WriteLine() method | |
var module = targetMethod.Module; | |
var body = targetMethod.Body; | |
// In order to use FakeConsole.WriteLine(), we need to use Cecil to "import" | |
// the method into the modified assembly's module | |
var writeLine = module.Import(typeof (FakeConsole).GetMethod("WriteLine")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<configuration> | |
<appSettings> | |
<add key="sdkDir" value="C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin"/> | |
<add key="sdkDirUnderVista" value="C:\Program Files (x86)\Microsoft.NET\SDK\v2.0\Bin"/> | |
</appSettings> | |
<startup> | |
<supportedRuntime version="v2.0.50727"/> | |
</startup> | |
</configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var testHarness = new TestHarness(); | |
// The processors decide which methods should be replaced and how they should behave once the method is called | |
var consoleTestProcessor = new ConsoleTestProcessor(); | |
testHarness.Processors.Add(consoleTestProcessor); | |
var fileSystemTestProcessor = new FileSystemTestProcessor(); | |
fileSystemTestProcessor.AddMockFile(@"c:\foo.txt", "bar"); | |
testHarness.Processors.Add(fileSystemTestProcessor); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public FlushContentsTo([NotNull] outputStream : Stream) : uint | |
requires outputStream.CanWrite | |
{ | |
def startPosition = 0; | |
_heap.Seek(startPosition); | |
outputStream.Seek(startPosition); | |
def bytes = _heap.ToArray(); | |
def writer = BinaryWriter(outputStream); | |
writer.Write(bytes); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Nemerle; | |
using Nemerle.Assertions; | |
using Nemerle.Collections; | |
using Nemerle.Text; | |
using Nemerle.Utility; | |
using System; | |
using System.IO; | |
using System.Collections.Generic; | |
using System.Linq; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ShouldMatch(this stream : Stream, other : Stream) : void | |
{ | |
def hash = stream.GetHash(); | |
def otherHash = other.GetHash(); | |
mutable smallerStream = other; | |
when(other.Length > stream.Length) | |
{ | |
smallerStream = stream; | |
} |
OlderNewer