Skip to content

Instantly share code, notes, and snippets.

@RobinHAEVG
RobinHAEVG / ViewModelBase.cs
Created April 8, 2020 05:44
MVVM Event Propagation - Propagates property changes back to the view
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace ExampleProject
{
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = "")
{
@RobinHAEVG
RobinHAEVG / read_file_async.cs
Created February 3, 2020 13:39
Asynchronous C# File Operations
public static async Task<string> ReadAllTextAsync(string filePath)
{
var stringBuilder = new StringBuilder();
using (var fileStream = File.OpenRead(filePath))
using (var streamReader = new StreamReader(fileStream))
{
string line = await streamReader.ReadLineAsync();
while(line != null)
{
stringBuilder.AppendLine(line);
@RobinHAEVG
RobinHAEVG / Entity_JobEntry.cs
Last active February 3, 2020 14:10
C# MSSQL Connection
// NuGet package: EntityFramework from Microsoft
using System.ComponentModel.DataAnnotations;
public class JobEntry
{
[Key]
public int Id { get; set; }
[StringLength(50)]
public string UniqueId { get; set; }
[StringLength(100)]
@RobinHAEVG
RobinHAEVG / get_request.cs
Created January 14, 2020 11:35
C# HTTP Snippets
//using System.Net;
using var wb = new WebClient();
var response = wb.DownloadString(url);
@RobinHAEVG
RobinHAEVG / App.xaml
Last active January 28, 2020 09:22
C#/WPF MVVM Pattern Implementation using MvvmLight
<Application x:Class="ExampleProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ExampleProject.ViewModel"
d1p1:Ignorable="d"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="View/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
@RobinHAEVG
RobinHAEVG / binary_search.cs
Last active April 14, 2020 06:07
C# useful snippets
private static int SearchBinary(int[] array, int searchValue)
{
int min = 0;
int max = array.Length - 1;
while (min <= max)
{
int mid = (min + max) / 2;
if (searchValue == array[mid])
{
return mid;