Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Sunday, December 05, 2010

Snippet editor

In my work I'm often use snippets, but by old habit I created every time new snippet manual. Today found nice solutions to my  suffering -  Snippet Editor by BillMcC. Snippet editor ready to work with all version of Visual Studio, support C# and VB snippet, easy interface and big help to programmer.
Link to download.

Wednesday, January 06, 2010

Object Property as Key in Collection

A innovation of Dictionary got excellent solution in stocking data. After countless uses I decided to find alternative method in combination of key and object and now I offering KeyedCollection. Little example will present a using of aforementioned object:

Simple classes:

public class User
   {
       public int Id { get; set; }
       public string Name { get; set; }
       public Address Address { get; set; }
   }

   public class Address
   {
       public string Country { get; set; }
       public string City { get; set; }
       public string Zip { get; set; }
   }

Two object that inherits abstract KeyedCollections:

/// <summary>
///A key is ID of player
/// </summary>
public class UserCollection : KeyedCollection<int, User>
{
    //Implementing member
    protected override int GetKeyForItem(User item)
    {
        return item.Id;
    }
}

/// <summary>
/// A key is User Name
/// </summary>
public class UserCollection1 : KeyedCollection<string, User>
{
    //Implementing member
    protected override string GetKeyForItem(User item)
    {
        return item.Name;
    }
}

 

Little example to using:

public class Test
{
    public TestById()
    {
        var userCollection = new UserCollection();
        userCollection.Add(new User
                               {
                                   Id = 5,
                                   Name = "John Smith",
                                   Address = new Address
                                                 {
                                                     City = "NY",
                                                     Country = "USA",
                                                     Zip = "12345"
                                                 }
                               });

        userCollection.Add(new User
                               {
                                   Id = 17,
                                   Name = "James Brown",
                                   Address = new Address
                                                 {
                                                     City = "LA",
                                                     Country = "USA",
                                                     Zip = "54321"
                                                 }
                               });

        Console.Write(userCollection[6]);
    }
     public void  TestByName()
    {
        var userCollection = new UserCollection1();
        userCollection.Add(new User
                               {
                                   Id = 5,
                                   Name = "John Smith",
                                   Address = new Address
                                                 {
                                                     City = "NY",
                                                     Country = "USA",
                                                     Zip = "12345"
                                                 }
                               });

        userCollection.Add(new User
                               {
                                   Id = 17,
                                   Name = "James Brown",
                                   Address = new Address
                                                 {
                                                     City = "LA",
                                                     Country = "USA",
                                                     Zip = "54321"
                                                 }
                               });

        Console.Write(userCollection["John Smith"]);
    }
}

 

 

If a project in VS 2008 you can run in heritable object LINQ requests and more. Enjoy!

kick it on DotNetKicks.com

Sunday, October 25, 2009

SQL to LINQ Cheat Sheet

Excellent explanation how to covert SQL query to LINQ. Click HERE to article.

LINQ Syntax

Wednesday, June 17, 2009

Debug windows service

In the time, when you work on development a windows service not possible to debug it. A solution is a converting service to console application or creating additional service runner or anymore. I want to present very simple, effective and easy way how to resolve this. In debug mode will run application and in not debug mode will run service.

[RunInstaller(true)]
public partial class ServiceRunner : ServiceBase
{
[STAThread]
static void Main()
{
#if !DEBUG
//Run Windows Service
Run(new ServiceRunner());
#else
//Run Application
new YourServiceBody();
#endif
}
public ServiceRunner()
{
InitializeComponent();

}
protected override void OnStart(string[] args)
{
new YourServiceBody();
}

protected override void OnStop()
{}
}

Good luck!
kick it on DotNetKicks.com

Sunday, April 05, 2009

Clone an object in C# using reflection for system and generic types

public object Clone()
{
object newObject = Activator.CreateInstance(GetType());
PropertyInfo[] propertyInfos = GetType().GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
if (propertyInfo.PropertyType.IsGenericType)
{
if (propertyInfo.PropertyType.GetInterface("IList", true) != null)
{
IList oldList = propertyInfo.GetValue(this, null) as IList;
if (oldList != null && oldList.Count > 0 &&
oldList[0].GetType().GetInterface("ICloneable", true) != null)
{
IList newList = (IList)propertyInfo.GetValue(newObject, null);
foreach (object obj in oldList)
{
ICloneable clone = (ICloneable)obj;
newList.Add(clone.Clone());
}
}
else
{
propertyInfo.SetValue(newObject, oldList, null);
}
}
if (propertyInfo.PropertyType.GetInterface("IDictionary", true) != null)
{
IDictionary oldDic =
propertyInfo.GetValue(this, null) as IDictionary;
if (oldDic != null && oldDic.Count > 0 &&
oldDic[0].GetType().GetInterface("ICloneable", true) != null)
{
IDictionary newDic =
(IDictionary)propertyInfo.GetValue(newObject, null);
foreach (DictionaryEntry entry in oldDic)
{
ICloneable clone = (ICloneable)entry.Value;
newDic[entry.Key] = clone.Clone();
}
}
else
{
propertyInfo.SetValue(newObject, oldDic, null);
}
}
}
else
{
//Clone IClonable object
if (propertyInfo.GetType().GetInterface("ICloneable", true) != null)
{
ICloneable clone = (ICloneable)propertyInfo.GetValue(this, null);
propertyInfo.SetValue(newObject, clone.Clone(), null);
}
else
{
propertyInfo.SetValue(
newObject, propertyInfo.GetValue(this, null), null);
}
}
}
return newObject;
}



Thursday, September 25, 2008

Snippet Designer for Visual Studio 2008

The Snippet Designer is a plugin which enhances the Visual Studio IDE to allow a richer and more productive code snippet experience.

Home Page

Wednesday, May 14, 2008

Sys.WebForms.PageRequestManagerParserError in MS AJAX

Thanks to Al Pascual to solution.

On top of the webform add:

enableEventValidation="false"



To full article lick Here

Tuesday, April 08, 2008

VS 2005 Intellisense in web.config files stop work

Now one annoying gotcha:

There is one gotcha to be aware of, though, that can sometimes cause intellisense for the web.config file to stop working in the IDE. This happens when a default namespace is added to the root <configuration> element. For example, like so:

<configuration xmlns=
"http://schemas.microsoft.com/.NetConfiguration/v2.0">





This doesn’t cause any runtime problems – but it does stop intellisense completion happening for the built-in .NET XML elements in the web.config file.

The bad news is that the built-in web admin tool (launched via the WebSite->ASP.NET Configuration menu item in VS 2005 and Visual Web Developer) always adds this xmlns namespace when it launches – so if you use this tool to manage users/roles you’ll end up having it added to your web.config file for you.

How to fix this gotcha:

To get intellisense back when you are editing the web.config file in the IDE, just delete the xmlns reference and have the root configuration element look like so:

<configuration>



Everything will then work fine again.


via


Monday, February 18, 2008

Enum Utilities

In this article I will discuss some classes I've written to simplify working with enumerations. The primary thrust of these classes is added functionality, but in some cases there are performance improvements as well.

Click here

Download source

The zip file contains:
EnumDefaultValueAttribute.cs
EnumTransmogrifier.cs
LibEnum.cs
build.bat
csc.rsp
EnumDemo1.cs
EnumDemo2.cs
EnumDump.cs
MonthEnum.cs
PolyglotAttribute.cs
WeekdayEnum.cs

Once you extract the files to a directory you should be able to execute build.bat to compile the demo programs. (They are console applications.)

To use the methods in your own projects, simply add the appropriate files.

Sunday, February 17, 2008

Directives in Asp.Net

Directives are used to pass optional settings to the ASP.NET pages and compilers.

Click here to read article.

Tuesday, February 05, 2008

101 Design Patterns & Tips for Developers

Full guide for developer how to create your application in the using   a "design patterns", that include next parts:

  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns
  • Composing Methods of Refactoring
  • Moving Features Between Objects
  • Organizing Data
  • Simplifying Conditional Expressions
  • Making Method Calls Simpler
  • Dealing with Generalization
  • Big Refactorings

Click here to read.

Thursday, January 17, 2008

Example & Tutorial of Rhino Mocks

In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A computer programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to test the behavior of a car during an accident.

 Wikipedia 

To full guide in code examples about Rhino Mocks Click Here

Full guide how to configuring VS 2008 for debugging .NET Framework Source Code

Click here to read a article.