Skip to content

Instantly share code, notes, and snippets.

public class AsyncCompletion
{
private static readonly TaskCompletionSource<Unit> CompletedSource;
static AsyncCompletion()
{
CompletedSource = new TaskCompletionSource<Unit>();
CompletedSource.SetResult(Unit.Default);
}
/*
* 引入voidable修饰符,用于修饰泛型参数。
* 被修饰的泛型参数T,可以在代码里具体化为void类型。
*/
class Task<voidable T> { } // 带有voidable修饰
class List<T> { } // 不带voidable修饰
/*
// 添加一个扩展方法
public static class WebClientExtensions {
public static Task<string> DownloadStringAsync(
this WebClient client,
Uri uri,
CancellationToken cancellationToken,
int timeout) {
public static IEnumerable<TResult> SelectNonNull<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TResult> selector)
where TResult : class
{
return source != null ? source.Select(selector).Where(i => i != null) : Enumerable.Empty<TResult>();
}
public class TicksToDateTimeCaller {
private static DateTime TicksToDateTime(long ticks) {
return new DateTime(ticks);
}
public TResult Call<T, TResult>(T arg) {
return (TResult)(object)TicksToDateTime((long)(object)arg);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
static object UseBox(int num)
{
return num;
}
private class IntWrapper
{
public int Num;
}
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<ControlTemplate TargetType="DataGridCell" x:Key="TestCell">
<Border Name="PART_CellBorder" SnapsToDevicePixels="True" BorderBrush="Red" BorderThickness="2">
<ContentPresenter Name="PART_ContentPresenter" Content="{Binding}" />
</Border>
Build FAILED.
"C:\projects\RazorEngine\RazorEngine-3.6.4\src\RazorEngine.sln" (Build t
arget) (1) ->
"C:\projects\RazorEngine\RazorEngine-3.6.4\src\test\Test.RazorEngine.Cor
e\Test.RazorEngine.Core.csproj" (default target) (3) ->
(CoreCompile target) ->
IsolatedRazorEngineServiceTestFixture.cs(180,71): error CS0122: 'Razor
Engine.Compilation.CompilerServiceBase.DynamicTemplateNamespace' is inac
cessible due to its protection level [C:\projects\RazorEngine\RazorEngin
@JeffreyZhao
JeffreyZhao / SelectiveReceive.fs
Created July 15, 2009 11:24
Selective Receive with F# MailboxProcessor
#light
open Microsoft.FSharp.Control
let counter =
MailboxProcessor.Start(fun inbox ->
let rec loop() =
async {
let! msg = inbox.Scan(fun x ->
match x with
@JeffreyZhao
JeffreyZhao / Crawler.cs
Created July 15, 2009 16:47
A simple web crawler based on ActorLite
namespace Crawling
{
public class Crawler : Actor<Message>, ICrawlingHandler
{
protected override void Receive(Message message)
{
message(this);
}
public Crawler(Monitor monitor)