Skip to content

Instantly share code, notes, and snippets.

View ohlawdie's full-sized avatar
😟

Ohlawdie ohlawdie

😟
  • Michigan
View GitHub Profile
@ohlawdie
ohlawdie / TupleInCLR
Last active February 11, 2020 22:47
tuple #note
// With identity conversions you may have generic variance in mind, however, this is not possible due to
// Identity conversions are mostly important for tuples when it comes to constructed types. If you could easily convert from (int, int) to (int x, int y) but not from IEnumerable<(int, int)> to IEnumerable(<int x, int y>) you would be quite annoyed.
//Although you can ignore some preceding information and ignore what the CLR does with tuples, you'll be able to do more with tuples and better understand the behavior.
//Unlike anonymous types, in which unique sequence of property names within an assembly causes the compiler to generate a new type, typles don't require any extra types to be generated by the compiler. Instead, it uses a new set of types from the framework.
//Tuples in C# 7are implemented using the System.ValueTuple. A description of any type of is very much like the description of tuple types from earlier: it's a value type with public fields. You might expect the ValueTuple to be static - i
@ohlawdie
ohlawdie / removeXMLwRegex
Last active December 23, 2019 19:20
#xml #regex
/.*?\n
Regex for removing xml comments
@ohlawdie
ohlawdie / callback.cs
Last active February 11, 2020 22:53
Callback #delegate #callback
If you're used to function pointers in C, a delegate is basically a pair of pointers rolled into one:
A pointer to an object (optional)
A pointer to a method of that object
That means a single delegate passes all the information needed to locate a function in your program, whether it's a static method or associated with an object.
You define them like this in C#:
public delegate void FooCallbackType( int a, int b, int c );
@ohlawdie
ohlawdie / filesystem.cs
Last active December 22, 2019 00:08
msdn filesystem
class FileSysInfo
{
static void Main()
{
// You can also use System.Environment.GetLogicalDrives to
// obtain names of all logical drives on the computer.
System.IO.DriveInfo di = new System.IO.DriveInfo(@"C:\");
Console.WriteLine(di.TotalFreeSpace);
Console.WriteLine(di.VolumeLabel);
@ohlawdie
ohlawdie / filestackrec.cs
Last active February 11, 2020 22:52
File Recursion #file #recursion
public class FileStackRec
{
static void Main(string[] args)
{
// Specify the starting folder on the command line, or in
// Visual Studio in the Project > Properties > Debug pane.
TraverseTree(args[0]);
Console.WriteLine("Press any key");
Console.ReadKey();
@ohlawdie
ohlawdie / MethodBinding.cs
Last active February 11, 2020 22:48
MethodInfo #reflection
public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
{
List<FlexMethodInfo> methods = new List<FlexMethodInfo>();
if (typeName == "Product")
{
methods.Add(new FlexMethodInfo("Concatenate", typeName));
methods.Add(new FlexMethFlexMethodInfo("Register", typeName));
return methods.ToArray();
}
@ohlawdie
ohlawdie / helpvBuffer.cs
Last active February 11, 2020 22:52
#buffer
class BufferClassDemo
{
// Display the array elements from right to left in hexadecimal.
public static void DisplayArray( short[ ] arr )
{
Console.Write( " arr:" );
for( int loopX = arr.Length - 1; loopX >= 0; loopX-- )
Console.Write( " {0:X4}", arr[ loopX ] );
Console.WriteLine( );
}
@ohlawdie
ohlawdie / MethodSyntaxes.fs
Last active February 11, 2020 22:41
Method Syntaxes F# #FSharp
// Instance method definition.
[ attributes ]
member [inline] self-identifier.method-name parameter-list [ : return-type ] =
method-body
// Static method definition.
[ attributes ]
static member [inline] method-name parameter-list [ : return-type ] =
method-body
@ohlawdie
ohlawdie / ExtensionOfLinqBuilder.fs
Last active February 11, 2020 22:46
Ext of LinqBuilder #linq F#
type Microsoft.FSharp.Linq.QueryBuilder with
[<CustomOperation("existsNot")>]
member _.ExistsNot (source: QuerySource<'T, 'Q>, predicate) =
Enumerable.Any (source.Source, Func<_,_>(predicate)) |> not
@ohlawdie
ohlawdie / ExplicitFieldaccess.fs
Last active February 11, 2020 22:40
ExplicitField VAL #F F# #Let
//Line 4 and 17
type MyType() =
let mutable myInt1 = 10
[<DefaultValue>] val mutable myInt2 : int
[<DefaultValue>] val mutable myString : string
member this.SetValsAndPrint( i: int, str: string) =
myInt1 <- i
this.myInt2 <- i + 1