This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
using static System.Console; | |
using System.IO; | |
namespace usingapp | |
{ | |
class Program | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var paths = new string[] {@"C:\myapp\mscorlib.dll", @"C:\myapp\myapp.dll"}; | |
var resolver = new PathAssemblyResolver(paths); | |
using (var lc = new MetadataLoadContext(resolver)) | |
{ | |
Assembly a = lc.LoadFromAssemblyName("myapp"); | |
Type myInterface = a.GetType("MyApp.IPluginInterface"); | |
foreach (Type t in a.GetTypes()) | |
{ | |
if (t.IsClass && myInterface.IsAssignableFrom(t)) | |
Console.WriteLine($"Class {t.FullName} implements IPluginInterface"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ILogger | |
{ | |
void Log(LogLevel level, string message); | |
void Log(Exception ex) => Log(LogLevel.Error, ex.ToString()); // New overload | |
} | |
class ConsoleLogger : ILogger | |
{ | |
public void Log(LogLevel level, string message) { ... } | |
// Log(Exception) gets default implementation | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slice = a[i1..i2]; // { 3, 4, 5 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index i1 = 3; // number 3 from beginning | |
Index i2 = ^4; // number 4 from end | |
int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
Console.WriteLine($"{a[i1]}, {a[i2]}"); // "3, 6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static ReadOnlySpan<byte> CRLF => new byte[] { (byte)'\r', (byte)'\n' }; | |
public static void ReadLines(ReadOnlySequence<byte> sequence) | |
{ | |
SequenceReader<byte> reader = new SequenceReader<byte>(sequence); | |
while (!reader.End) | |
{ | |
if (!reader.TryReadToAny(out ReadOnlySpan<byte> line, CRLF, advancePastDelimiter:false)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async IAsyncEnumerable<int> GetBigResultsAsync() | |
{ | |
await foreach (var result in GetResultsAsync()) | |
{ | |
if (result > 20) yield return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Utf8JsonReaderLoop(ReadOnlySpan<byte> dataUtf8) | |
{ | |
var json = new Utf8JsonReader(dataUtf8, isFinalBlock: true, state: default); | |
while (json.Read()) | |
{ | |
JsonTokenType tokenType = json.TokenType; | |
ReadOnlySpan<byte> valueSpan = json.ValueSpan; | |
switch (tokenType) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 1, | |
"isRoot": true, | |
"tools": { | |
"dotnetsay": { | |
"version": "2.1.4", | |
"commands": [ | |
"dotnetsay" | |
] | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 1, | |
"isRoot": true, | |
"tools": {} | |
} |