Skip to content

Instantly share code, notes, and snippets.

@hebus
hebus / Comparison<T>
Created June 12, 2013 09:45
Effectuer un tri à l'aide du delegate Comparison<T>
// récupération de la liste de tous les fonds à partir du web service
AlterCodificationClient client = new AlterCodificationClient();
List<AcfundsDTO> funds = client.AllFunds().ToList<AcfundsDTO>();
// tri alphabétique croissant
funds.Sort((Comparison<AcfundsDTO>)delegate(AcfundsDTO a, AcfundsDTO b)
{ return a.aftrkname.CompareTo(b.aftrkname); });
// afficher le contenu de la liste triée
foreach (AcfundsDTO item in funds)
{
if(obj == null){
obj = new Obj();
}
return obj;
// peut être remplacé par
return obj = obj ?? new Obj();
@hebus
hebus / Extension c#
Last active June 5, 2018 15:55
Exemples d'extensions
// Permet de savoir si une valeur de type int contient 0, MinValue ou MaxVaue
public static bool IsZeroOrEmpty(this int value)
{
return ((value == 0) || (value == int.MinValue) || (value == int.MaxValue));
}
// Activer le double buffering d'un DatagridView
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
Type type = dgv.GetType();
@hebus
hebus / Lazy instanciation
Last active December 18, 2015 11:09
Instanciation d'un singleton en mode Lazy
The LasyList<T> only works with an IQueryable<T> source. It is an implementation of IList<T> and works by populating a private List with all results from the specified IQueryable<T>. The initialization occurs the first time you access any of the IList<T> members.
Example usage would be
var myList = new LazyList(products.Where(p => p.Name.StartsWith("T"));
//initialization occurs here
Console.Write(myList.Count);
The System.Lazy<T> class works with any type and is not limited to IQueryable<T>. Lazy initialization occurs the first time the Lazy<T>.Value property is accessed.
@hebus
hebus / Delete .svn
Created June 19, 2013 15:15
Supprimer tous les dossiers .svn d'un dossier via une commande DOS
for /R %%i in (.svn) do rd /S /Q "%%i"
pause
@hebus
hebus / timedlock
Last active December 25, 2015 06:19
TimedLock (C#) By Andrew Baker
using System;
using System.Threading;
/// <summary>
/// A class demonstrating how to use timed locks.
/// </summary>
class TimedLockDemo
{
/// <summary>
/// Private resource, used to demonstrate the timed lock.
@hebus
hebus / ConvertToMultiDimArray
Created October 24, 2013 08:50
Convert Object to multidimensional array
public static object[,] ConvertToMultiDimArray<T>(T[] datasource)
{
if (datasource != null)
{
Type t = typeof(T);
PropertyInfo[] pi = t.GetProperties();
object[,] r = new object[datasource.Length, pi.Length];
for (int row = 0; row < datasource.Length; row++)
{
@hebus
hebus / gist:8859102
Created February 7, 2014 08:36
Read an embedded resource .net
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
string resourceName = @"<<namespace + full path>>.mail.html";
string mailbody = string.Empty;
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
using (StreamReader sr = new StreamReader(stream))
{
mailbody = sr.ReadToEnd();
}
}
@hebus
hebus / SqlBulkCopy
Created March 25, 2014 13:16
Copy huge data from one table to another using SqlBulkCopy
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
bulkCopy("dbo.table1", "dbo.table2");
sw.Stop();
Console.WriteLine("Elapsed={0}", sw.Elapsed);
Console.Read();
}
@hebus
hebus / gist:c2112f34c610be3dc4f4
Created August 12, 2015 08:50
Convert Oracle RAW Date to Date
-- conversion RAW DATE en DATE
DECLARE dt DATE := NULL;
BEGIN
DBMS_STATS.CONVERT_RAW_VALUE('7871081A010101', dt);
DBMS_OUTPUT.put_line(to_char(dt,'DD-MON-YYYY'));
END;
/