-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba48f34
commit 4079d4e
Showing
3 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
test/TestAssemblies/BasicUsage/Attributes/TryLifetimeAttribute.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Rougamo; | ||
using Rougamo.Context; | ||
using Rougamo.Metadatas; | ||
using System.Collections.Generic; | ||
|
||
namespace BasicUsage.Attributes | ||
{ | ||
[Advice(Feature.OnEntry)] | ||
public abstract class TryLifetimeAttribute : MoAttribute | ||
{ | ||
public override void OnEntry(MethodContext context) | ||
{ | ||
var list = (List<object>)context.Arguments[0]; | ||
list.Add(this); | ||
} | ||
} | ||
|
||
[Lifetime(Lifetime.Singleton)] | ||
public class SingletonAttribute : TryLifetimeAttribute | ||
{ | ||
} | ||
|
||
[Lifetime(Lifetime.Pooled)] | ||
public class PooledAttribute : TryLifetimeAttribute | ||
{ | ||
} | ||
|
||
[Lifetime(Lifetime.Pooled)] | ||
public class PooledAttribute<T> : TryLifetimeAttribute, IResettable | ||
{ | ||
public T Value { get; set; } | ||
|
||
public bool TryReset() | ||
{ | ||
Value = default; | ||
return true; | ||
} | ||
} | ||
|
||
[Lifetime(Lifetime.Transient)] | ||
public class TransientAttribute : TryLifetimeAttribute | ||
{ | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
using BasicUsage.Attributes; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace BasicUsage | ||
{ | ||
public class LifetimeUseCase | ||
{ | ||
[Singleton] | ||
public void Singleton(List<object> list) | ||
{ | ||
} | ||
|
||
[Singleton] | ||
public void SingletonNested(List<object> list) | ||
{ | ||
SingletonNestedCore(list); | ||
} | ||
|
||
[Singleton] | ||
private void SingletonNestedCore(List<object> list) | ||
{ | ||
} | ||
|
||
[Singleton] | ||
public async Task SingletonAsync(List<object> list) | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
[Singleton] | ||
public async Task SingletonNestedAsync(List<object> list) | ||
{ | ||
await SingletonNestedCoreAsync(list); | ||
} | ||
|
||
[Singleton] | ||
private async Task SingletonNestedCoreAsync(List<object> list) | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
[Singleton] | ||
public IEnumerable<int> SingletonIterator(List<object> list) | ||
{ | ||
yield return 1; | ||
} | ||
|
||
[Singleton] | ||
public IEnumerable<int> SingletonNestedIterator(List<object> list) | ||
{ | ||
foreach (var item in SingletonNestedIteratorCore(list)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
[Singleton] | ||
private IEnumerable<int> SingletonNestedIteratorCore(List<object> list) | ||
{ | ||
yield return 1; | ||
} | ||
|
||
[Singleton] | ||
public async IAsyncEnumerable<int> SingletonAiterator(List<object> list) | ||
{ | ||
await Task.Yield(); | ||
yield return 1; | ||
} | ||
|
||
[Singleton] | ||
public async IAsyncEnumerable<int> SingletonNestedAiterator(List<object> list) | ||
{ | ||
await foreach (var item in SingletonNestedAiteratorCore(list)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
[Singleton] | ||
private async IAsyncEnumerable<int> SingletonNestedAiteratorCore(List<object> list) | ||
{ | ||
await Task.Yield(); | ||
yield return 1; | ||
} | ||
|
||
[Pooled] | ||
public void Pooled(List<object> list) | ||
{ | ||
} | ||
|
||
[Pooled] | ||
public void PooledNested(List<object> list) | ||
{ | ||
PooledNestedCore(list); | ||
} | ||
|
||
[Pooled] | ||
private void PooledNestedCore(List<object> list) | ||
{ | ||
} | ||
|
||
[Pooled] | ||
public async Task PooledAsync(List<object> list) | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
[Pooled] | ||
public async Task PooledNestedAsync(List<object> list) | ||
{ | ||
await PooledNestedCoreAsync(list); | ||
} | ||
|
||
[Pooled] | ||
private async Task PooledNestedCoreAsync(List<object> list) | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
[Pooled] | ||
public IEnumerable<int> PooledIterator(List<object> list) | ||
{ | ||
yield return 1; | ||
} | ||
|
||
[Pooled] | ||
public IEnumerable<int> PooledNestedIterator(List<object> list) | ||
{ | ||
foreach (var item in PooledNestedIteratorCore(list)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
[Pooled] | ||
private IEnumerable<int> PooledNestedIteratorCore(List<object> list) | ||
{ | ||
yield return 1; | ||
} | ||
|
||
[Pooled] | ||
public async IAsyncEnumerable<int> PooledAiterator(List<object> list) | ||
{ | ||
await Task.Yield(); | ||
yield return 1; | ||
} | ||
|
||
[Pooled] | ||
public async IAsyncEnumerable<int> PooledNestedAiterator(List<object> list) | ||
{ | ||
await foreach (var item in PooledNestedAiteratorCore(list)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
[Pooled] | ||
private async IAsyncEnumerable<int> PooledNestedAiteratorCore(List<object> list) | ||
{ | ||
await Task.Yield(); | ||
yield return 1; | ||
} | ||
|
||
[Pooled<int>(Value = 1)] | ||
public void GenericPooled(List<object> list) | ||
{ | ||
} | ||
|
||
[Pooled<int>(Value = 2)] | ||
public async Task GenericPooledAsync(List<object> list) | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Transient] | ||
public void Transient(List<object> list) | ||
{ | ||
} | ||
|
||
[Transient] | ||
public void TransientNested(List<object> list) | ||
{ | ||
TransientNestedCore(list); | ||
} | ||
|
||
[Transient] | ||
private void TransientNestedCore(List<object> list) | ||
{ | ||
} | ||
|
||
[Transient] | ||
public async Task TransientAsync(List<object> list) | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
[Transient] | ||
public async Task TransientNestedAsync(List<object> list) | ||
{ | ||
await TransientNestedCoreAsync(list); | ||
} | ||
|
||
[Transient] | ||
private async Task TransientNestedCoreAsync(List<object> list) | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
[Transient] | ||
public IEnumerable<int> TransientIterator(List<object> list) | ||
{ | ||
yield return 1; | ||
} | ||
|
||
[Transient] | ||
public IEnumerable<int> TransientNestedIterator(List<object> list) | ||
{ | ||
foreach (var item in TransientNestedIteratorCore(list)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
[Transient] | ||
private IEnumerable<int> TransientNestedIteratorCore(List<object> list) | ||
{ | ||
yield return 1; | ||
} | ||
|
||
[Transient] | ||
public async IAsyncEnumerable<int> TransientAiterator(List<object> list) | ||
{ | ||
await Task.Yield(); | ||
yield return 1; | ||
} | ||
|
||
[Transient] | ||
public async IAsyncEnumerable<int> TransientNestedAiterator(List<object> list) | ||
{ | ||
await foreach (var item in TransientNestedAiteratorCore(list)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
|
||
[Transient] | ||
private async IAsyncEnumerable<int> TransientNestedAiteratorCore(List<object> list) | ||
{ | ||
await Task.Yield(); | ||
yield return 1; | ||
} | ||
} | ||
} |