Skip to content

Instantly share code, notes, and snippets.

View luis-fss's full-sized avatar
:octocat:
Hey

Luis Fernando de Souza Santos luis-fss

:octocat:
Hey
View GitHub Profile
public class DataTranslator
{
public static Func<IDataRecord, T> CreateTranslator<T>(IDataRecord record)
{
Type targetType = typeof(T);
string cacheKey = string.Format("{0}-Translator", targetType);
var cachedTranslator = WebContextCache.GetItem<Func<IDataRecord, T>>(cacheKey);
if (cachedTranslator != null)
@mhart
mhart / gist:1464358
Created December 12, 2011 02:22
QueryOverStub
public class QueryOverStub<TRoot, TSub> : IQueryOver<TRoot, TSub>
{
private readonly TRoot _singleOrDefault;
private readonly IList<TRoot> _list;
private readonly ICriteria _root = MockRepository.GenerateStub<ICriteria>();
public QueryOverStub(IList<TRoot> list)
{
_list = list;
}
@danielwertheim
danielwertheim / Factory.cs
Created December 28, 2011 20:36
Some fun with private ctors
public static class Factory<T> where T : class
{
private static readonly Func<T> FactoryFn;
static Factory()
{
//FactoryFn = CreateUsingActivator();
FactoryFn = CreateUsingLambdas();
}
@giggio
giggio / BindingEstaticoDinamico.cs
Created February 16, 2012 01:14
Exemplo de binding estático e dinâmico em C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestProject3
{
[TestClass]
public class BindingTest
{
[TestMethod]
public void EstaticoString()
{
@NOtherDev
NOtherDev / LoquaciousXml.cs
Created February 18, 2012 21:32
Loquacious XML builder
internal class NodeBuilder
{
private readonly XmlDocument _doc;
private readonly XmlNode _node;
public NodeBuilder(XmlDocument doc, XmlNode node)
{
_doc = doc;
_node = node;
}
@philipmat
philipmat / json_entity_converter.cs
Created February 20, 2012 10:17
JSON Entity Converter
void Main()
{
var co = new Company { Id = 1, Name = "Moof Inc." };
var clarus = new Contact { Id = 1, Name = "Clarus" };
var mark = new Contact { Id = 2, Name = "Mark" };
co.AddContact(clarus);
co.AddContact(mark);
co.MainContact = clarus;
// Attempt #1: Straight up, no converter
@liammclennan
liammclennan / blog_connascence_methods.md
Created July 5, 2012 22:36
Named Method Arguments: From connascence of position to connascence of name

From wikipedia:

Two software components are connascent if a change in one would require the other to be modified in order to maintain the overall correctness of the system.

Connascence is a useful tool for discussing different types of coupling that occur within software.

Again from wikipedia, "connascence of name is when multiple components must agree on the name of an entity". Connascence of name one is of the list harmful and most unavoidable types of connascence because it is simple to reason about and change. While connascence of name is still connascence, and therefore bad, it is among the most amenable to refactoring. If the name of something changes then everything that refers to that thing by name must also change. This is a simple change that can be mostly statically determined and applied by tools.

Connascence of position is present when changing the order of something necessitates a change elsewhere. An example is the order of function arguments. If the order of a function's arguments is

@JulianRooze
JulianRooze / Expressions.cs
Created November 26, 2012 17:12
Build expressions
class Employee
{
public IList<Order> Orders { get; set; }
}
class Order
{
public int OrderID { get; set; }
public IList<Customer> Customers { get; set; }
@luis-fss
luis-fss / NugetCommandLineTips.txt
Created November 18, 2015 23:49
Nuget command line tips
Nuget command line – uninstall package from all projects
> Get-Project -All | Uninstall-Package <package name>
@NOtherDev
NOtherDev / ControllerActionInvokerWithDefaultJsonResult.cs
Created September 22, 2012 17:26
ASP.NET MVC: Replacing the default ActionInvoker to do something useful with non-ActionResult return types
// ASP.NET MVC: Replacing the default ActionInvoker to do something useful with non-ActionResult return types
// See more: http://notherdev.blogspot.com/2012/09/non-actionresult-return-type-aspnet-mvc.html
public class MyControllerFactory : DefaultControllerFactory
{
public override IController CreateController(RequestContext context, string controllerName)
{
var controller = base.CreateController(context, controllerName);
return ReplaceActionInvoker(controller);
}