Skip to content

Instantly share code, notes, and snippets.

View KirillOsenkov's full-sized avatar

Kirill Osenkov KirillOsenkov

View GitHub Profile
var sourceRepo = Repository.Factory.GetCoreV3(NuGetConstants.V3FeedUrl);
var resource = await sourceRepo.GetResourceAsync<FindPackageByIdResource>();
resource.GetAllVersionsAsync("packageId", new SourceCacheContext(), NullLogger.Instance, CancellationToken.None);
@StephenCleary
StephenCleary / FnvHash.cs
Created October 6, 2019 14:15
FNV-1a hash in C#
/// <summary>
/// A hash combiner that is implemented with the Fowler/Noll/Vo algorithm (FNV-1a). This is a mutable struct for performance reasons.
/// </summary>
public struct FnvHash
{
/// <summary>
/// The starting point of the FNV hash.
/// </summary>
public const int Offset = unchecked((int)2166136261);
@KirillOsenkov
KirillOsenkov / AddGeneratedFile.csproj
Last active April 17, 2025 05:12
Sample of generating a .cs file during build and adding it to the compilation
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<GeneratedText><![CDATA[
using System%3B
<!DOCTYPE html>
<html>
<head>
<style>
.editor { font-family: 'Roboto Mono', monospace; font-size: 12px; outline: none; overflow-y: auto; padding-left: 48px; counter-reset: line; }
.editor div { display: block; position: relative; white-space: pre-wrap; }
.editor div::before { content: counter(line); counter-increment: line; position: absolute; right: calc(100% + 16px); opacity: 0.5; }
</style>
</head>
@badamczewski
badamczewski / Morph.cs
Created December 1, 2020 14:11
Text Morphing in WPF
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace WPFAnimations
/// <summary>
/// Export a <see cref="IClassifierProvider"/>
/// </summary>
[Export(typeof(IClassifierProvider))]
[ContentType("code")]
internal class VideoCommentClassifierProvider : IClassifierProvider
{
[Export(typeof(ClassificationTypeDefinition))]
[Name("video comment")]
internal ClassificationTypeDefinition VideoCommentClassificationType = null;
@sayedihashimi
sayedihashimi / msbuild-error-format.md
Last active May 13, 2024 20:38
MSBuild and Visual Studio Known Error Message Formats

MSBuild and Visual Studio Known Error Message Formats

When a tool is executed that outputs some text, MSBuild will examine the text for errors and warnings. Many tools use a known format to report these messages. By default, MSBuild will examine the text and report errors and/or warnings based on the output. This behavior can be changed or disabled by using these parameters on the Exec task: IgnoreStandardErrorWarningFormat, CustomErrorRegularExpression, and CustomWarningRegularExpression.

NOTE: If you do decide to use your own regular expression to detect error and warnings, then

#nullable disable
#pragma warning disable IDE0004, IDE0049, IDE0052, IDE0055, IDE0060, CS1998, CS0626
using System.Runtime.CompilerServices;
using static System.Runtime.CompilerServices.Unsafe;
class A
{
Delegate _x;
public object X
using System;
using System.Threading.Tasks;
using System.Linq;
Console.WriteLine("yeah true");
class Keywords {
public unsafe dynamic select() {
var var = new int*[] {};
var set = (IGrouping<int*[], IGrouping<int*[], object>>) null;
@Washi1337
Washi1337 / TinySharp.cs
Last active January 5, 2025 18:55
A program to emit a tiny .NET binary program printing Hello World to the standard output. Blog post: https://blog.washi.dev/posts/tinysharp/
using System.Text;
using AsmResolver;
using AsmResolver.DotNet;
using AsmResolver.DotNet.Builder.Metadata.Blob;
using AsmResolver.DotNet.Builder.Metadata.Strings;
using AsmResolver.DotNet.Code.Cil;
using AsmResolver.DotNet.Signatures;
using AsmResolver.IO;
using AsmResolver.PE;
using AsmResolver.PE.DotNet.Builder;