Skip to content

Instantly share code, notes, and snippets.

@TheFo2sh
TheFo2sh / ShowProgressAttribute.cs
Created August 18, 2019 22:11
ShowProgressAttribute
public class ShowProgressAttribute :MethodInterceptionAspect
{
private string _title;
public ShowProgressAttribute(string title)
{
_title = title;
}
public override async Task OnInvokeAsync(MethodInterceptionArgs args)
{
public class MainPageViewModel
{
[DefaultValue("")]
public string Name { get; set; }
public string WelcomeMsg => $"Hello {Name}";
[Serializable]
public class MainPageViewModelConfiguration : ConfigurationProvider<MainPageViewModel>
{
public MainPageViewModelConfiguration()
{
public class CommandAsync<T> : IMPCommand
{
private readonly Func<T,Task> _executeTask;
private readonly Predicate<object> _canExecute;
[Serializable]
public class MethodLockedAttribute : MethodInterceptionAspect
{
private int maximum_concurrency_number;
private static ConcurrentDictionary<int,SemaphoreSlim> SemaphoreSlimRepo=new ConcurrentDictionary<int, SemaphoreSlim>();
public MethodLockedAttribute(int maximumConcurrencyNumber)
{
maximum_concurrency_number = maximumConcurrencyNumber;
}
[Serializable]
public class RequireUserConfirmationAttribute : MethodInterceptionAspect
{
private string message;
private string cancelText;
private string okText;
private string title;
public RequireUserConfirmationAttribute(string title,string message,string okText, string cancelText)
{
static class LinQToTaskExtensions
{
public static async Task<TResult> Select<TSource, TResult>(
this Task<TSource> source, Func<TSource, TResult> selector)
{
var sourceResult = await source;
if (sourceResult == null)
return default(TResult);
return selector.Invoke(sourceResult);
}
static class LinQToTaskExtensions
{
public static Func<Task<TResult>> Select<TSource, TResult>(
this Task<TSource> source, Func<TSource, TResult> selector)
{
return async () =>
{
var sourceResult = await source;
if (sourceResult == null)
return default(TResult);
public class CommandAsync<T> : ICommand
{
private CancellationTokenSource cancellationTokenSource;
private readonly Func<T, CancellationToken, Task> _executeTask;
private readonly Predicate<T> _canExecute;
private bool _locked;
public class ObservableCancellationTokenSource<T> : CancellationTokenSource,IDisposable
{
private readonly IDisposable _subscription;
public ObservableCancellationTokenSource(IObservable<T> observable)
{
_subscription = observable.Subscribe(token=>this.Cancel());
}