Skip to content

Instantly share code, notes, and snippets.

💤
Sleeping...

walterlv walterlv

💤
Sleeping...
Block or report user

Report or block walterlv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View WindowBlur.cs
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using Walterlv.Demo.Interop.Native;
namespace Walterlv.Demo.Interop
{
public class WindowBlur
{
@walterlv
walterlv / CommandArgumentAttribute.cs
Created Oct 21, 2017
Provide a reflection based wrapper for `Microsoft.Extensions.CommandlineUtils` Library.
View CommandArgumentAttribute.cs
using System;
namespace Mdmeta.Core
{
/// <summary>
/// Specify a property to receive argument of command from the user.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class CommandArgumentAttribute : Attribute
{
@walterlv
walterlv / AwaiterInterfaces.cs
Created Jul 11, 2018
Custom awaiter with background UI thread
View AwaiterInterfaces.cs
using System.Runtime.CompilerServices;
namespace Walterlv.Threading
{
/// <summary>
/// 表示一个可等待对象,如果一个方法返回此类型的实例,则此方法可以使用 `await` 异步等待。
/// </summary>
/// <typeparam name="TAwaiter">用于给 await 确定返回时机的 IAwaiter 的实例。</typeparam>
public interface IAwaitable<out TAwaiter> where TAwaiter : IAwaiter
{
View CachePool.cs
using System;
using System.Collections.Generic;
using Walterlv.Annotations;
namespace Walterlv
{
/// <summary>
/// 如果获取 <typeparamref name="TSource"/> 对应信息的过程比较耗时(例如反射),
/// 则可使用 <see cref="CachePool{TSource,TCache}"/> 对此过程进行缓存。
/// </summary>
@walterlv
walterlv / AsyncBox.cs
Last active Jul 7, 2019
A UI container for async loading.
View AsyncBox.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Threading;
using Walterlv.Demo;
@walterlv
walterlv / FileWatcher.cs
Last active Mar 19, 2019
FileWatcher that helps you to watch a single file change even if the file or it's owner folders does not exists.
View FileWatcher.cs
using System;
using System.IO;
namespace Walterlv.IO
{
public sealed class FileWatcher
{
/// <summary>监视的文件。</summary>
private readonly FileInfo _file;
@walterlv
walterlv / ContinuousPartOperation.cs
Last active Mar 19, 2019
An awaitable for waiting a part of a loop.
View ContinuousPartOperation.cs
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Walterlv
{
/// <summary>
/// 为一个持续操作中的一部分提供可异步等待的操作。
/// </summary>
@walterlv
walterlv / SelfInstaller.cs
Created Feb 27, 2019
这是一个简单的自更新程序的类。使用此类型,程序初次运行的时候会安装自己,如果已安装旧版本会更新自己,如果已安装最新则直接运行。
View SelfInstaller.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Principal;
namespace Walterlv.Installing
{
@walterlv
walterlv / ExceptionDescriptor.cs
Last active Mar 24, 2019
Get the key descriptor of an Exception instance so that we can determine whether two exceptions are the same.
View ExceptionDescriptor.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Walterlv
{
/// <summary>
/// 包含一个 <see cref="Exception"/> 对象的关键特征,可使用此对象的实例判断两个不同的异常实例是否极有可能表示同一个异常。
/// </summary>
@walterlv
walterlv / VisualScalingExtensions
Created Apr 25, 2019
Calculate WPF visual scaling ratios to user monitor device.
View VisualScalingExtensions
using System;
using System.Windows;
using System.Windows.Media;
namespace Walterlv
{
public static class VisualScalingExtensions
{
/// <summary>
/// 获取一个 <paramref name="visual"/> 在显示设备上的尺寸相对于自身尺寸的缩放比。
You can’t perform that action at this time.