View argument-passing-matrix.linq
void Main() | |
{ | |
var obj = new SomeObject(); | |
var val = new SomeValue { n = 999 }; | |
Original_Object(obj); | |
Original_Value(val); | |
Original_Object_Ref(ref obj); | |
Original_Value_Ref(ref val); | |
Console.WriteLine(val.n); | |
} |
View Main.cs
/* the following will print | |
A: val1=123, val2=456 | |
B: val1=123 | |
With C, we also have 456 | |
C: val1=123 | |
B: done | |
A: done | |
Press any key to exit | |
*/ |
View EnumeratorMethodShowcase.txt
// The following C# code from LINQPad (free windows app) uses a method (Test) that | |
// returns an enumeration. Have a look how the IL code that the compiler generates | |
// looks like: | |
static IEnumerable<int> Test() | |
{ | |
yield return 100; | |
var n = Rand.Range(200, 500); | |
yield return n; | |
yield return 600; |
View ListAllOpenFiles.swift
// see https://developer.apple.com/forums/thread/655225 | |
func openFilePaths() -> [String] { | |
(0..<getdtablesize()).map { fd in | |
// Return "" for invalid file descriptors. | |
var flags: CInt = 0 | |
guard fcntl(fd, F_GETFL, &flags) >= 0 else { | |
return "" | |
} | |
// Return "?" for file descriptors not associated with a path, for | |
// example, a socket. |
View ExceptionHandler.cs
using HarmonyLib; | |
using RimWorld; | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Reflection; | |
using Verse; | |
using Verse.Sound; |
View CustomStatePerPawn.cs
// helper class for scribing ref-deep dicts | |
public class Scribe_Dictionary<T, S> | |
{ | |
List<T> tmpKeys; | |
List<S> tmpVals; | |
public void Scribe(ref Dictionary<T, S> dict, string name) | |
{ | |
if (Verse.Scribe.mode == LoadSaveMode.Saving) | |
{ |
View CallingBaseMethodWorkaround.cs
// use in LINQPad | |
delegate string Test1Delegate(int n, ref float f); | |
void Main() | |
{ | |
var bar = new Bar(); | |
var baseTest1 = (Test1Delegate)GetBaseMethod(typeof(Foo).GetMethod("Test1"), bar); | |
var f = 789f; |
View PatchBasics.cs
// This source can be executed directly from the (free) LINQPad (use "Language: C# Program") | |
public static void Main(String[] args) | |
{ | |
var harmony = new Harmony("test"); | |
harmony.PatchAll(); | |
Test1.Run(); | |
Test2.Run(); | |
} |
View TranspilerBasics.cs
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il, MethodBase original) | |
{ | |
// create new local variables | |
var local = il.DeclareLocal(typeof(TheType)); | |
// create new labels for jumping | |
var label = il.DefineLabel(); | |
// inspect original methods properties | |
var args = original.GetParameters(); |
View OffLimits.shader
Shader "Unlit/OffLimits" | |
{ | |
Properties { | |
_Color1 ("Color 1", Color) = (0,0,0,1) | |
_Color2 ("Color 2", Color) = (1,1,1,1) | |
_Size ("Size", Float) = 0 | |
_Tiling ("Tiling", Range(0.1, 10)) = 1 | |
_Direction ("Direction", Range(0, 1)) = 0 | |
_WarpScale ("Warp Scale", Range(0, 1)) = 0 | |
_WarpTiling ("Warp Tiling", Range(0.01, 20)) = 1 |
NewerOlder