albahari / uncapsulator Goto Github PK
View Code? Open in Web Editor NEWFluent API for .NET reflection, via a dynamic proxy
License: MIT License
Fluent API for .NET reflection, via a dynamic proxy
License: MIT License
I use Uncapsulator for testing private members.
in one of my use cases I saw this error:
Unable to cast object of type 'LINQPad.Uncapsulator.Uncapsulator' to type 'System.Runtime.CompilerServices.INotifyCompletion'
run this code in Linqpad to see the error:
await new RssService().Uncapsulate().IngestSubEpisodes(new List { new Episode { Id = "1" } });
public class RssService
{
private static readonly SemaphoreLocker _locker = new SemaphoreLocker();
private readonly DatabaseSimulator _context = new DatabaseSimulator();
protected async Task IngestSubEpisodes(List<Episode> episodes)
{
var options = new ParallelOptions { MaxDegreeOfParallelism = 1 };
await Parallel.ForEachAsync(episodes, options, async (episode, token) =>
{
var subEpisodes = await _locker.LockAsync(async () =>
{
return await _context.SubEpisodes;
});
});
}
}
public class Episode { public string Id; }
public class SubEpisode { public string Id; public string EpisodeId; }
public class SemaphoreLocker
{
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
public async Task<T> LockAsync<T>(Func<Task<T>> worker)
{
await _semaphore.WaitAsync();
try
{
return await worker();
}
finally
{
_semaphore.Release();
}
}
}
public class DatabaseSimulator
{
public Task<List> SubEpisodes
{
get
{
return Task.FromResult(new List { new SubEpisode { Id = "1" } });
}
}
}
void Main() // LinqPad 6 v6.9.7 x64 beta
{
var list = new List<string> { "hello" };
var uncapsulatedList = list.Uncapsulate();
uncapsulatedList.Dump(); // private "_items" array is not shown
uncapsulatedList.Dump(includePrivate: true); // doesn't work either
uncapsulatedList._items.Dump(); // explicit access works though
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.