Skip to content

Instantly share code, notes, and snippets.

View sachintha81's full-sized avatar

Sach sachintha81

View GitHub Profile
@sachintha81
sachintha81 / LoopEnum.cs
Last active December 6, 2019 06:27
Loop through Enum
// Typed version
var values = Enum.GetValues(typeof(Foos)).Cast<Foos>();
// Helper function
public static class EnumUtil {
public static IEnumerable<T> GetValues<T>() {
return Enum.GetValues(typeof(T)).Cast<T>();
}
}
@sachintha81
sachintha81 / deleteall.bat
Created June 9, 2017 20:26
Batch script to delete all files in current and sub folders excluding certain extensions.
@echo off
forfiles /s /c "cmd /c (if NOT @ext==\"bat\" del /s /q @path)"
@sachintha81
sachintha81 / TrueRandomNumbers.cs
Created January 30, 2017 22:28
C# True (almost) Random Number Generator
//The following sample uses the Cryptography class to simulate the roll of a dice.
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
class RNGCSP
{
private static RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
@sachintha81
sachintha81 / FileHashRetriever.cs
Created January 23, 2017 19:51
C# - Retrieve MD5 Hash of a File
using System;
using System.IO;
using System.Security.Cryptography;
namespace FileHashCompare
{
class Program
{
static void Main(string[] args)
{
@sachintha81
sachintha81 / DragDropToTextBox.cs
Created January 13, 2017 21:33
C# - Drag Drop a File/Folder into a TextBox
using System;
using System.Collections.Generic;
using System.Windows;
using System.Collections.ObjectModel;
namespace TextBoxDragDrop
{
public partial class TextBoxDragDrop : Window
{
private void txtPath_PreviewDragOver(object sender, DragEventArgs e)
@sachintha81
sachintha81 / ColorLibrary.cs
Created January 13, 2017 21:32
WPF + C# Color Handling
namespace ColorLibrary
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
@sachintha81
sachintha81 / IndentStringWithTabs.cs
Created January 13, 2017 21:30
Indenting C# String Data with Tabs
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StringIndent
{
public class StringIndent
@sachintha81
sachintha81 / ColorCodeDGV.xaml
Last active December 18, 2019 06:47
WPF + C# : Display Data and Color Code a DataGrid using Binding
<Window x:Class="ColorLibrary.MainWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ColorLibrary"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="MainWindow" Height="500" Width="400">
<Window.Resources>
@sachintha81
sachintha81 / MoveListViewItems.cs
Created January 13, 2017 21:26
WPF + C# Move Multiple Items from one ListView to Another
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace ListViewOperations.SOURCE.GUI
{
public partial class ListViewOperations : Window
{
@sachintha81
sachintha81 / WPFMessengerClass.cs
Created January 13, 2017 21:23
Messenger Class for the WPF + MVVM Pattern
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MVVMMessenger
{
public class Messenger