Skip to content

Instantly share code, notes, and snippets.

View jonathascosta's full-sized avatar

Jonathas Costa jonathascosta

  • Porto, Portugal
View GitHub Profile
@jonathascosta
jonathascosta / rulesproperty.snippet
Last active December 11, 2015 03:48
Rules property snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Rules Property</Title>
<Author>Jonathas Piazzarollo Costa</Author>
<Shortcut>rulesproperty</Shortcut>
<Description>Creates a Rules property.</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
@jonathascosta
jonathascosta / stopwatch.snippet
Last active December 11, 2015 03:48
Stopwatch snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Stopwatch</Title>
<Author>Jonathas Piazzarollo Costa</Author>
<Shortcut>stopwatch</Shortcut>
<Description>Surrounds code with Stopwatch.</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
@jonathascosta
jonathascosta / gist:4528916
Created January 14, 2013 09:38
Copy properties from an object to another object
public void CopyProperties(object from, object to)
{
foreach (var p in ((object)from).GetType().GetProperties())
{
var toProperty = to.GetType().GetProperty(p.Name);
var fromValue = p.GetValue(from, null);
if (toProperty.PropertyType.IsValueType)
{
var convertedValue = Convert.ChangeType(fromValue, toProperty.PropertyType);
toProperty.SetValue(to, convertedValue, null);
@jonathascosta
jonathascosta / SimNaoType.cs
Created December 7, 2012 06:57
Tipo de suporte a colunas S/N no Oracle
using System;
using System.Data;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
namespace Framework.DataAccess.NHibernate.UserTypes
{
[Serializable]
public class SimNaoType : IUserType
if (entity.GetType() != typeof(LogAuditoriaEntity) && (entity is AuditableEntity))
{
try
{
var logAuditoria = new LogAuditoriaEntity
{
NomeTabela = ObterNomeTabela(persister),
TipoOperacao = operacao,
TxtComando = ObterComandoSql(session),
ForeignId = id.ToString()
@jonathascosta
jonathascosta / gist:1363986
Created November 14, 2011 13:52
Problem 30
public static long Solve()
{
var powers = new List<long>();
var numbers = new List<long>();
for (int i = 0; i < 10; i++)
powers.Add((long)BigInteger.Pow(i, 5));
for (int a = 0; a < 10; a++)
for (int b = 0; b < 10; b++)
@jonathascosta
jonathascosta / StateMachine.cs
Created October 28, 2011 11:40
Simple State Machine API
using System;
using System.Collections.Generic;
using System.Linq;
namespace Architecture.StateMachine
{
/// <summary>
/// Representa uma máquina de estados.
/// </summary>
/// <typeparam name="T">Tipo do estado.</typeparam>
@jonathascosta
jonathascosta / Competencia.cs
Created October 20, 2011 19:49
Classe Competência para lidar com mês/ano
public class Competencia
{
public Competencia(int mes, int ano)
{
try
{
new DateTime(ano, mes, 1);
}
catch (Exception)
{
@jonathascosta
jonathascosta / ExtStoreResult.cs
Created September 15, 2011 16:44
ActionResult with Javascript for a Ext.Store
using System.Web.Mvc;
using Newtonsoft.Json;
namespace ActionResults
{
public class ExtStoreResult : ActionResult
{
public virtual string StoreName { get; set; }
public virtual object StoreData { get; set; }
@jonathascosta
jonathascosta / gist:987676
Created May 23, 2011 21:41 — forked from juanplopes/gist:987646
String Extensions
public static class TypeExtensions
{
public static Type GetValueTypeIfNullable(this Type type)
{
return type.IsNullable() ? type.GetGenericArguments()[0] : type;
}
public static bool IsNullable(this Type type)
{
return (type.IsGenericType && typeof(Nullable<>) == type.GetGenericTypeDefinition());