Skip to content

Commit

Permalink
#31: Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Miista committed May 2, 2024
1 parent 5d1800e commit 42b0921
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ Shim structShim = Shim.Replace(() => Is.A<MyStruct>().DoSomething()).With(

_Note: You cannot shim methods on specific instances of Value Types_

### Shim operators

```csharp
var operatorShim = Shim.Replace(() => Is.A<TimeSpan>() + Is.A<TimeSpan>()).With(
delegate(TimeSpan l, TimeSpan r) { return TimeSpan.Zero; });
```
### Isolating your code

```csharp
Expand All @@ -137,10 +143,47 @@ PoseContext.Isolate(() =>

// Outputs "doing someting else with myClass"
myClass.DoSomething();

// Outputs '00:00:00'
Console.WriteLine(TimeSpan.FromDays(1) + TimeSpan.FromSeconds(2));

}, consoleShim, dateTimeShim, classPropShim, classShim, myClassShim, structShim);
}, consoleShim, dateTimeShim, classPropShim, classShim, myClassShim, structShim, operatorShim);
```

## Shimming operators
Operator shimming requires that the class/struct overloads the operator in question.

Poser supports shimming operators of the following kind:
* Arithmetic
* `+x`
* `-x`
* `!x`
* `~x`
* `++`
* `--`
* `x + y`
* `x - y`
* `x / y`
* `x % y`
* `x & y`
* `x | y`
* `x ^ y`
* `x << y`
* `x >> y`
* Equality
* `x == y`
* `x != y`
* Comparison
* `x < y`
* `x > y`
* `x <= y`
* `x >= y`

### Unsupported operators
Shimming of the following operators is not supported:
- `true` and `false` because I cannot find a good way to express the operation in an expression tree.
- `x >>> y` because expression trees cannot contain this operator. This is a limitation on the part of the compiler.

## Caveats & Limitations

* **Breakpoints** - At this time any breakpoints set anywhere in the isolated code and its execution path will not be hit. However, breakpoints set within a shim replacement delegate are hit.
Expand Down

0 comments on commit 42b0921

Please sign in to comment.