Skip to content

Instantly share code, notes, and snippets.

View gustavodaquino's full-sized avatar

Gustavo Aquino gustavodaquino

  • Mercado Livre
  • São Paulo, Brasil
View GitHub Profile
@gustavodaquino
gustavodaquino / IRepository.cs
Last active June 27, 2019 12:55
Unit of Work - C#
public interface IRepository<T> where T : BaseEntity
{
IUnitOfWork UnitOfWork { get; }
IQueryable<T> All<T>() where T : BaseEntity;
T Find<T>(Expression<Func<T, bool>> predicate) where T : BaseEntity;
bool Contains<T>(Expression<Func<T, bool>> predicate) where T : BaseEntity;
}
@gustavodaquino
gustavodaquino / clear-git.txt
Created June 27, 2019 00:50
Remover todos os arquivos versionados e adicioná-los.
git rm -rf --cached .
git add .
@gustavodaquino
gustavodaquino / xml-serialization.cs
Created December 18, 2017 19:10
Serializing a C# class to XML
[Serializable]
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
var serializer = new XmlSerializer(typeof(Person));
string xml;
@gustavodaquino
gustavodaquino / print-divs.sass
Created December 18, 2017 19:07
Ajuste de espaçamento das grids para impressão
@media print {
div.panel {
page-break-inside: avoid;
}
.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
float: left;
}
.col-sm-12 {
@gustavodaquino
gustavodaquino / MemoryStreamExample.cs
Created July 10, 2017 22:24
C# program that uses the MemoryStream type
using System;
using System.IO;
class Program
{
static void Main()
{
// Read all bytes in from a file on the disk.
byte[] file = File.ReadAllBytes("C:\\ICON1.png");
@gustavodaquino
gustavodaquino / foreach.cs
Created June 13, 2017 20:28
Compiler-generated code for a foreach loop using the iterator pattern.
List<Person>.Enumerator e = people.GetEnumerator();
try
{
Person v;
while (e.MoveNext())
v = e.Current;
}
finally
{
System.IDisposable d = e as System.IDisposable;
@gustavodaquino
gustavodaquino / AssertionConcern.cs
Created May 24, 2017 02:46
[C#] AssertionConcern Snippet
public class AssertionConcern
{
public static void AssertArgumentEquals(object object1, object object2, string message)
{
if (!object1.Equals(object2))
{
throw new InvalidOperationException(message);
}
}
@gustavodaquino
gustavodaquino / dispose-pattern.cs
Created May 8, 2017 04:37
Basic Dispose Pattern in C#
public class DisposableResourceHolder : IDisposable {
private SafeHandle resource; // handle to a resource
public DisposableResourceHolder(){
this.resource = ... // allocates the resource
}
public void Dispose(){
Dispose(true);
@gustavodaquino
gustavodaquino / linq-join-example.cs
Created May 5, 2017 18:56
[C#] Example using Join Extension Method from LINQ.
var query = _context.TableOuter
.Join(_context.TableInner,
outer => outer.Id,
inner => inner.ForeignId,
(outer, inner) => new
{
outer,
inner
})
.Where(x => x.inner.Property == value).Select(x => x.inner).SingleOrDefault();
@gustavodaquino
gustavodaquino / profiling-query-generated-entity-framework.cs
Last active May 5, 2017 18:56
Show actual query generated by Entity Framework.
using (MyContext context = new MyContext())
{
// This will show the SQL in the Output -> Debug window.
context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
// LINQ expressions below...
}