Skip to content

Instantly share code, notes, and snippets.

View christiannagel's full-sized avatar
💭
working on the new book Pragmatic Microservices with C# and Azure

Christian Nagel christiannagel

💭
working on the new book Pragmatic Microservices with C# and Azure
View GitHub Profile
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button Foreground="{StaticResource ApplicationHeaderForegroundThemeBrush}"
AutomationProperties.Name="Group Title"
Click="Header_Click"
Style="{StaticResource TextBlockButtonStyle}" >
<StackPanel Orientation="Horizontal">
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button Foreground="{StaticResource ApplicationHeaderForegroundThemeBrush}"
AutomationProperties.Name="Group Title"
Click="Header_Click"
Style="{StaticResource TextBlockButtonStyle}" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid GroupPadding="0,0,70,0" Background="BlueViolet" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
@christiannagel
christiannagel / ArrayPool.cs
Last active May 26, 2017 08:41
Allocate and use a simple array
private static void UsingSimpleArrays()
{
Console.WriteLine(nameof(UsingSimpleArrays));
for (int i = 0; i < 20; i++)
{
LocalUseOfArray(i);
}
Console.WriteLine();
Console.WriteLine();
}
@christiannagel
christiannagel / ArrayPool.cs
Created May 26, 2017 09:35
Creating arrays while using the GC
private static void UsingSimpleArraysWithGC()
{
Console.WriteLine(nameof(UsingSimpleArraysWithGC));
for (int i = 0; i < 20; i++)
{
GC.Collect(0);
LocalUseOfArray(i);
}
Console.WriteLine();
Console.WriteLine();
@christiannagel
christiannagel / ArrayPool.cs
Created May 26, 2017 09:54
Use a shared ArrayPool
private static void LocalUseOfSharedPool(int i)
{
int[] arr = ArrayPool<int>.Shared.Rent(ARRAYSIZE);
ShowAddress($"simple array {i}", arr);
FillTheArray(arr);
UseTheArray(arr);
ArrayPool<int>.Shared.Return(arr);
}
@christiannagel
christiannagel / ArrayPool.cs
Last active June 4, 2017 05:58
Show memory address of array
unsafe private static void ShowAddress(string name, int[] item)
{
fixed (int* addr = item)
{
Console.Write($"\t0x{(ulong)addr:X}");
}
}
@christiannagel
christiannagel / EnumerableExtensions.cs
Created July 20, 2017 14:02
Where with error information delayed
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
foreach (T item in source)
{
if (predicate(item))
{
yield return item;
@christiannagel
christiannagel / EnumerableExtensions.cs
Created July 20, 2017 14:16
Where with earlier error information using a separate method
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
return WhereImpl(source, predicate);
}
private static IEnumerable<T> WhereImpl<T>(IEnumerable<T> source, Func<T, bool> predicate)
{
@christiannagel
christiannagel / Program.cs
Last active July 22, 2017 07:10
ArgumentNullException with yield
string[] names = { "James", "Niki", "John", "Gerhard", "Jack" };
var q = names.Where(null);
foreach (var n in q) // callstack position for exception
{
Console.WriteLine(n);
}