Skip to content

Instantly share code, notes, and snippets.

View ericnewton76's full-sized avatar

Eric Newton ericnewton76

  • Orlando Florida
View GitHub Profile
@ericnewton76
ericnewton76 / example.cs
Last active November 16, 2023 20:08
C# language proposal: loose keyword
webserviceproxynamespace.LatLng latlng = new webserviceProxy().GetLatLng("Orlando, FL, 32803");
anotherproxynamespace.LatLng latlng2 = new anotherwebservice().GetPosition("Orlando", "FL", "32803");
//this other library wants a LatLng object
var map = new Mapping.MapManager();
map.MarkPosition(loose latlng); //parameter type is Mapping.LatLng but latlng is webserviceproxynamespace.LatLng type, should work!
map.MarkPosition(loose latlng2); //parameter type is Mapping.LatLng but latlng2 is anotherproxynamespace.LatLng type, should work!
//how does this work?
@ericnewton76
ericnewton76 / NLogLoggerExtensions.cs
Created November 29, 2017 20:53
NLog contribution logger extension for logging an action.
public static class NLogLoggerExtensions
{
public static void LogAction(this NLog.ILogger Log, Action action, string startingVerb, string completedVerb, string format, params object[] args)
{
try
{
if(Log.IsDebugEnabled)
{
Log.Debug(format.Replace("[verb]", startingVerb), args);
}
@ericnewton76
ericnewton76 / Util.EmptyFallbacks
Created November 15, 2016 16:41
A routine for genera
public static partial class Utils
{
/// <summary>
/// Checks each supplied value for a non-null value, returning first one supplied.
/// It is recommend to use EmptyFallbacks(Func&lt;string&gt;) overload for any less than trivial value retrievals.
/// </summary>
/// <example>
/// var value = Util.EmptyFallbacks(dictionary["key"], someothervalue, "default value");
/// </example>
/// <param name="values"></param>
@ericnewton76
ericnewton76 / ValidationCheckBuilder.cs
Last active August 29, 2015 13:57
Builds a complete list of items that pass or fail validation checks.
using System;
using System.Collections.Generic;
public class ValidateCheckBuilder
{
private List<ValidationCheck> _validationchecks = new List<ValidationCheck>();
public IEnumerable<ValidationCheck> ValidationChecks { get { return this._validationchecks; } }
private bool? _allValid;
public bool AllValid { get { return _allValid.GetValueOrDefault(); } }
@ericnewton76
ericnewton76 / StringBuilderExtensions.cs
Last active December 20, 2015 07:19
An extension to StringBuilder for ReplaceAt functionality. Given an index, and optional length, and a string to overwrite, this method overwrites an area of characters.
namespace System.Text
{
internal static class StringBuilderExtensions
{
#if EXTENSIONS_SUPPORTED
public static StringBuilder ReplaceAt(this StringBuilder sb, string value, int index, int count)
{
return StringBuilderExtensions.ReplaceAt(sb, value, index, count);
}
#endif