background preloader

C#

Facebook Twitter

Library

Threading. Functional. Threads. Query. Review. C# ViewState Management/Storage - Four Locations! - The Code Pro. Download StaticAppGlobalsAppGlobals.zip - 3.4 KB Introduction From an SEO standpoint, page size matters, as well as the location of text on your page. When creating a site with VS .Net, we end up with a ViewState variable, which in some cases, can take up a whole lot of space near the top of the page. This could, in fact, dilute the contents' importance on a given web page. In terms of page size, some search engines only cache the first 120kb of data. This project was an attempt at finding another location to store the ViewState. In this case, I made four locations available for storage: SessionApplication AppGlobalsCache This can be easily implemented in any C# project by creating a base class, referencing it in all classes, and selecting the storage location in an appSettings key in the Web.config. Before fully diving into the code, I'd like to first discuss why it's important, and how the PageStatePersister, really didn't help.

Background ASP.Net ViewState Management Test results below: Implementing the Singleton Pattern in C# This article is now hosted on csharpindepth.com I'm gradually moving all my C# articles to the web site for my book, C# in Depth. This article has already moved. I'm leaving the content here so that existing links still work, but I won't be updating this page. Please visit the new location for this article. The singleton pattern is one of the best-known patterns in software engineering. Essentially, a singleton is a class which only allows a single instance of itself to be created, and usually gives simple access to that instance. Most commonly, singletons don't allow any parameters to be specified when creating the instance - as otherwise a second request for an instance but with a different parameter could be problematic!

There are various different ways of implementing the singleton pattern in C#. All these implementations share four common characteristics, however: A single constructor, which is private and parameterless. First version - not thread-safe It doesn't work in Java. The Server Software Company Bridging Web and Local Networks. Test Run: Using Combinations to Improve Your Software Test Case. Test Run Using Combinations to Improve Your Software Test Case Generation Dr. James McCaffrey Code download available at:TestRun0407.exe(132 KB) Testing has always been a vital part of the software development process, but three recent factors have caused it to take an even more central role.

This month I'll begin with the role of combinations in software testing. String[] deck = new string[] { "Ac", "Ad", "Ah", "As", "Kc", (...) }; Combination c = new Combination(52,5); // 52 cards, 5 at a time string[] pokerHand = new string[5]; while (c ! The number of test automation scenarios in which combinations are useful is astonishing once you learn to recognize them. Notice that you must select 10 characters and each character must come from one of 20 categories. Here I will build a Combination class in C# and show you how to use combinations to improve your testing effort.

Figure 1 Combinations Demo The best way to show you where I'm headed is with a screen shot. Combinations A Combination Class. Strong Coders Generic Data Access Library - Rolog. Automating Undo/Redo with .NET Generics - The Code Project - C# Introduction This article introduces a reusable library that can equip any action in your application with the undo/redo feature. You may use complex data structures and complex algorithms with no care about how they will be rolled back on user demand or after an error. Background If you've ever developed a graphic editor or designer for complex data, you've encountered the daunting task of implementing an undo/redo feature supported throughout the application. Implementing the mirror methods Do and Undo for each operation is a boring and very bug-prone process when you are building something more exquisite than a calculator. After my experiments then, I researched a way to make undo/redo support transparent for business logic.

To achieve it, we will use the magic of generics. This project has been published on CodePlex so that everybody can contribute to it and gain from it. Using the Code There are two points of good news. UndoRedoManager.Undo(); UndoRedoManager.Redo(); Implementation Memory. Tamir Gal | SharpSSH - A Secure Shell (SSH) library for .NET. Steve Heberts dotMath Library - Home. The following page is focused on understanding how to use dotMath in your application and get up and running in the shortest amount of time. If you are using the compiled assembly library, be sure to create a reference to the .Math library and include the library DLL in your distribution package. Scenario 1: Evaluating an Expression In order to take an expression without variables stored in a string – sExpression – and evaluate its value we need the following set of code. sExpression = “4+3”; EqCompiler oCompiler = new EqCompiler( sExpression, true); oCompiler.Compile(); double dValue = oCompiler.Calculate(); If you do not perform the ‘.Compile()’ step, it will be executed automatically the first time you perform ‘.Calculate();’.

Scenario 2: Evaluating an Expression with Variables Taking advantage of expressions with variables involves discovering the variables and setting them before performing the .Calculate() step. Scenario 3: Adding user-defined functions to the compiler’s syntax. A Library for Writing/Building Scripts in C#. Free source code a. Download source (version 1.0.1) - 2 MB Introduction ClockWork Script Builder is a .NET library (2.0) to make the building of scripts more readable and structured.

An extendible architecture lets developers add script building blocks (Script Items) for languages such as the ones provided in the download for JavaScript (Js) and XML (Xs). Background Recently I started playing with ExtJs and I ended up needing to build large chunks of JavaScript from .NET code. I've never found a nice way to construct scripts in C# so this time I decided to write a library to help.

Using the Code (CHM documentation is available from Tony's Wibbles.) In its simplest form, it is a way to join a bunch of strings together so that each is written on a new line: Script script = Sb.Script( "line 1;", "line 2;", "line 3;" ); string result = script.Render(); Console.WriteLine(result); It results in the following output: line 1; line 2; line 3; However there's a lot more to it. This results in the following output: ScriptLayout.

Implementing INotifyPropertyChanged with DynamicProxy2. 22:30 and still working on various bits and bobs, so I thought I'd take a well deserved break to tell you about one nice way to implement INotifyPropertyChanged, the one and only interface any class that will be bound in WPF should be implemented. I used to (circa .net 2) not see a bit issue in this kind of code. public class MyClass : INotifyPropertyChanged private string _myValue; public event PropertyChangedEventHandler PropertyChanged; public string MyValue get return _myValue; set _myValue = value; RaisePropertyChanged("MyValue"); protected void RaisePropertyChanged(string propertyName) if (PropertyChanged !

PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); But I've been badly spoiled by automatic properties in C# 3.0, and this all sounds like a lot of noise. Public class MyDreamClass : INotifyPropertyChanged public string MyValue { get; set; } Definitly much cleaner. The process is quite simple. First, let's clear up our class. Public class MyBetterClass : INotifyPropertyChanged.

C# Object Clone Wars : C# 411. Cloning C# objects is one of those things that appears easy but is actually quite complicated with many “gotchas.” This article describes the most common ways to clone a C# object. Shallow vs. Deep Cloning There are two types of object cloning: shallow and deep. Hence, a reference in the original object and the same reference in a shallow-cloned object both point to the same object. ICloneable Interface The ICloneable interface contains a single Clone method, which is used to create a copy of the current object. public interface ICloneable { object Clone(); } The problem with ICloneable is that the Clone method does not explicitly specify whether it is performing a shallow or deep copy, so callers can never be sure.

The ICloneable interface contains one member, Clone, which is intended to support cloning beyond that supplied by MemberWiseClone… The MemberwiseClone method creates a shallow copy… Type-Safe Clone One way to avoid the cast is to provide your own type-safe Clone method. 1. 2. 3. The Guidlines for Overriding Equals Method On Custom Classes or.

Cs-coding-standard-idesign.pdf (application/pdf Object) Deadlock Detection in Existing Code - The Code Project - .NET. Introduction Deadlocks are common problems in multi-threaded programming. When it comes to multithreading development, the most common problem developers are facing is critical sections. It is not uncommon to use more than a single lock, but if one does not pay attention to the order of the locks, or to the context in which they are being called (e.g., from within a callback), deadlocks will form. (There are many reasons for deadlocks to occur other than the obvious critical section, e.g., two threads that are waiting for each other to signal an event, but we will not discuss them here).

As with anything that is related to threads, timing is everything. The most problematic deadlocks are those which occur rarely, they have this amazing nature of occurring at your client's site... What if we could make the rare case the normal case? The attached ZIP file contains a DLL that does exactly that. Using the code Analyzing the stacks (slockimp based) Points of interest. .NET Type Internals - From a Microsoft CLR Perspective - The Cod. This article contains technical information about implementation of different categories of types (Value Types, Reference Types, Delegates, etc) in Microsoft CLR 2.0 (hereafter called as CLR). The concepts that are presented in this article are based on my analysis and study of type behavior in .NET using Son Of Strike (SOS) debugging extensions for VS.NET 2005 and the C# compiler. These concepts are also discussed in different MSDN blogs, MSDN articles and books.

However, these forms are often in the context of a broader topic where finer and important points are not easily visible. I created this article to provide a single point of reference for these finer and important points about the inner workings of CLR with regards to types. This article assumes that the readers have a working knowledge on a different category of types in .NET.

Value Types are allocated on stack. This is done to primarily reduce the contention on GC heap for types that simply represent basic data items. The C# Language.