New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching language of C#
C#
[TestFixture]
  public class ObjectTests
  {
      #region Setup/Teardown
 
      [SetUp]
      public void SetUp()
      {
          _id1 = Guid.NewGuid();
          _id2 = Guid.NewGuid();
Today @ 2:12pm
Tags:
6 Views
no comments
 
C#
[TestFixture]
 public class EntityTests
 {
     #region Setup/Teardown
 
     [SetUp]
     public void SetUp()
     {
         _id1 = Guid.NewGuid();
         _id2 = Guid.NewGuid();
Today @ 8:20am
Tags:
9 Views
no comments
 
C#
[Serializable]
public abstract class Entity : ValueObject, IEntity
{
    public virtual Guid Id { get; protected set; }
    private int? _cachedHashCode;
 
    public virtual bool IsTransient()
    {
        return Id.Equals(null) || Id.Equals(Guid.Empty);
    }
Today @ 8:20am
Tags:
11 Views
no comments
 
C#
[Serializable]
public abstract class Entity : ValueObject, IEntity
{
    #region Fields & Properties
 
    public virtual Guid Id { get; protected set; }
    private int? _cachedHashCode;
 
    #endregion
Today @ 8:19am
Tags:
4 Views
no comments
 
C#
 [Serializable]
  public abstract class ValueObject : IEquatable<ValueObject>
  {
      public bool Equals(ValueObject other)
      {
          // is other null?
          if (ReferenceEquals(other, null))
              return false;
 
          // are they the same object?
Today @ 8:18am
Tags:
11 Views
no comments
 
C#
[Test]
       public void comparing_to_a_null_object_is_false_and_cannot_be_equal()
       {
           var phone = new Telephone(11111, 111111);
 
           Assert.That(phone.Equals(null), Is.False);
       }
 
       [Test]
       public void comparing_to_self_is_true_and_always_equal()
Today @ 8:17am
Tags:
9 Views
no comments
 
C#
[Test]
       public void comparing_to_a_null_object_is_false_and_cannot_be_equal()
       {
           var phone = new Telephone(11111, 111111);
 
           Assert.That(phone.Equals(null), Is.False);
       }
 
       [Test]
       public void comparing_to_self_is_true_and_always_equal()
Today @ 8:16am
Tags:
5 Views
no comments
 
C#
[Test]
       public void comparing_to_a_null_object_is_false_and_cannot_be_equal()
       {
           var phone = new Telephone(11111, 111111);
 
           Assert.That(phone.Equals(null), Is.False);
       }
 
       [Test]
       public void comparing_to_self_is_true_and_always_equal()
Today @ 8:16am
Tags:
5 Views
no comments
 
C#
The following extensions methods can help you in the situation below:
 
        public static TResult IfNotNull<TSource, TResult>(this TSource obj, Func<TSource, TResult> func)
        {
            return IfNotNull(obj, func, default(TResult));
        }
        public static TResult IfNotNull<TSource, TResult>(this TSource obj, Func<TSource, TResult> func, TResult defaultIfNull)
        {
            return obj == null ? defaultIfNull : func(obj);
        }
by Kevin   Yesterday @ 8:01am
Tags:
11 Views
no comments
 
C#
        public static TResult IfNotNull<TSource, TResult>(this TSource obj, Func<TSource, TResult> func)
        {
            return IfNotNull(obj, func, default(TResult));
        }
        public static TResult IfNotNull<TSource, TResult>(this TSource obj, Func<TSource, TResult> func, TResult defaultIfNull)
        {
            return obj == null ? defaultIfNull : func(obj);
        }
 
Yesterday @ 7:54am
Tags:
9 Views
no comments
 
C#
 /*
  * This is the "IRQ descriptor", which contains various information
  * about the irq, including what kind of hardware handling it has,
  * whether it is disabled etc etc.
  *
  * Pad this out to 32 bytes for cache and indexing reasons.
  */
typedef struct {
         unsigned int status;            /* IRQ status */
         hw_irq_controller *handler;
Yesterday @ 1:37am
Tags:
5 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace FinbonacciApp
{
    class Program
    {
        static void Main(string[] args)
Wednesday @ 3:34pm
Tags:
7 Views
no comments
 
C#
using System;
 
namespace Foo
{
  /// <summary>
  /// A dummy callback-like mechanism for our application logic.
  /// </summary>
  public interface IStatusProvider
  {
    /// <summary>
Wednesday @ 2:28pm
Tags:
5 Views
no comments
 
C#
 
   public class ServerRegistry : MassTransitRegistryBase
   {
      public ServerRegistry()
      {
         MsmqEndpointConfigurator.Defaults(x =>
         {
            x.CreateMissingQueues = true;
            x.CreateTransactionalQueues = true;
            //x.PurgeOnStartup = true;
Wednesday @ 10:47am
Tags:
6 Views
no comments
 
C#
interface IModel
{
    ...
}
 
class CVideoModel: IModel
{
 
}
Wednesday @ 5:35am
Tags:
14 Views
no comments
 
C#
public Bitmap ConvertToGrayscale(Bitmap source)
{
  Bitmap bm = new Bitmap(source.Width,source.Height);
  for(int y=0;y<bm.Height;y++)
  {
    for(int x=0;x<bm.Width;x++)
    {
      Color c=source.GetPixel(x,y);
      int luma = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);
      bm.SetPixel(x,y,Color.FromArgb(luma,luma,luma));
Wednesday @ 4:43am
Tags:
9 Views
no comments
 
C#
Get["/"] = x => {
    return "This is the root";
};
 
Get["/Greet"] = x => {
    return "Hello World";
};
 
Get["/Greet/{name}"] = x => {
    return "Hello " + x.name;
by TheCodeJunkie   Wednesday @ 1:23am
Tags:
9 Views
no comments
 
C#
public class UriBinder : HttpProcessor
{
    private static List<UriBinding> _bindings;
 
    static UriBinder()
    {
        _bindings = new List<UriBinding>();
    }
 
    public static void AddUriBinding<TModel>(string name, string matchRegex, Func<int, object> modelFactory)
by Glenn Block   Wednesday @ 1:19am
Tags:
43 Views
no comments
 
C#
//in startup
UriBinder.AddUriBinding<Contact>("contact", "contact/(.+)", 
    cid => ContactsHandler._contacts.Single(c => c.ContactID == cid));
 
//request is http://contactmanager/contact/1 
 
//the resource takes contact as a param
public class ContactHandler {
    public Contact Get(Contact contact)
    {
by Glenn Block   Wednesday @ 1:06am
Tags:
30 Views
no comments
 
C#
public class Crypt
{
  public static string OpenSslSign(string privateKeyFile, string content)
  {
    var pkey = new PrivateKey();
    pkey.LoadPemFile(privateKeyFile);
    string pkeyXml = pkey.GetXml();
    var rsa = new Rsa();
    bool success = rsa.UnlockComponent("30-day trial");
    if (success != true) {
by Mikael Henriksson   Tuesday @ 11:31pm
7 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
by BEN   Tuesday @ 9:52pm
Tags:
8 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
Tuesday @ 9:47pm
Tags:
8 Views
no comments
 
C#
protected void Button2_Click(object sender, EventArgs e)
        {
            string uri = "http://quality.osm.no";
            Uri weburi = new Uri(uri, false);
            StringBuilder sbuild = new StringBuilder();
            string temp = "";
            try
            {
                HttpWebRequest webrequest = (HttpWebRequest) WebRequest.Create(weburi);
                CredentialCache myCache = new CredentialCache();
by nobodybutca   Tuesday @ 9:05pm
9 Views
no comments
 
C#
#region License
/*
 **************************************************************
 *  Author: Rick Strahl 
 *          © West Wind Technologies, 2008 - 2009
 *          http://www.west-wind.com/
 *  
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
Tuesday @ 5:21pm
Tags:
13 Views
no comments
 
C#
[Test]
public void Idle_ServerDisconnects_NoUnhandeledException()
{
    bool unhandeledException = false;
    UnhandledExceptionEventHandler fail = (sender, args) => unhandeledException = true;
 
    try
    {
        AppDomain.CurrentDomain.UnhandledException += fail;
        WithLogin(client =>
by lesnikowski   Tuesday @ 7:40am
Tags:
43 Views
no comments
 
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate