public object Convert(string member, string value) { Type type = typeof(T).GetProperty(member).PropertyType; var converter = TypeDescriptor.GetConverter(type); return converter.ConvertFromString(value); }
Casting or Parsing a variable in generic type member variable in C#
Wednesday, December 18, 2013
Microsoft .Net already has a bunch of great string conversion routines you can use! A TypeConverter can do most of the heavy lifting for you. Then you don't have to worry providing your own parsing implementations for built-in types. Note that there are locale-aware versions of the APIs on TypeConverter that could be used if you need to handle parsing values expressed in different cultures. The following code will parse values using the default culture:
The best way to compare two objects by value in C#
To compare to object by value we can use the following code snippet.
This method compare the types of two object and then check their value.
private static bool CompareValue(object o1, object o2)
{
return o1.GetType() == o2.GetType() && Object.Equals(o1, o2);
}
This method compare the types of two object and then check their value.
Whats New in ASP.NET and Web Tools for Visual Studio 2013
Tuesday, December 10, 2013
Microsoft recently released the new version of Visual Studio 2013 and web tools. Here are the summary of the new features for the web developers in Visual Studio 2013.
- New release focuses on One ASP.NET, which steps toward to unifying the ASP.NET technologies so core features can and web tools work the same across the platforms (e.g. adding ASP.NET MVC controllers to a Web Forms application).
- Enhance Authentication and Identity feature.
- New version of ASP.NET, which includes ASP.NET MVC 5, Web API 2, Razor 3, Entity Framework 6 and SignalR 2.0
- New Browser link feature that lets you to connect multiple browsers to Visual Studio and refresh them all by clicking a button in the toolbar.
- New core features include new templates based on Bootstrap, a new scaffolding system.
- Awesome editor for web tools, including HTML5, CSS3, JavaScript, jQuery, AngularJS, Ember, LESS, CofeeScript etc.
- New Project Readme.html page.
- New and enhance Web publish features like easily automate Web.config file encryption, automate taking an application offline during deployment.
- Visual Studio 2013 released with a new NuGet 2.7 for package management.
SPDY: Let's make the web faster
Introduction
SPDY (Pronounced as "SPeeDY") is an open networking protocol similar to HTTP, with particular goals of reducing web page load latency and improving web security. SPDY achieves reduced latency through compression, multiplexing, and prioritization.
Background: web protocols and web latency
Today, HTTP and TCP are the protocols of the web. TCP is the generic, reliable transport protocol, providing guaranteed delivery, duplicate suppression, in-order delivery, flow control, congestion avoidance and other transport features. On the other hand, HTTP is the application level protocol providing basic request/response semantics.Get property value from C# dynamic object by string using reflection
In Generic Class, it is quite common to get the value for a specific property dynamically. C# refection provides ways to get the Property value dynamically. If the IDynamicMetaObjectProvider can provide the dynamic member names, you can get them. See GetMemberNames implementation in the apache licensed ImpromptuInterface (which can be found in nuget), it works for ExpandoObjects and DynamicObjects that implement GetDynamicMemberNames and any other IDynamicMetaObjectProvider who provides a meta object with an implementation of GetDynamicMemberNames without custom testing beyond is IDynamicMetaObjectProvider.
Resolve the Visual Studio 2012 issue after updating or installing Visual Studio 2013
Sunday, November 17, 2013
If you have already installed VS2012 and at a later Update to new a Service Pack or Installing VS2013, when you load any project, you may get the following error:
--------------------------- Microsoft Visual Studio --------------------------- The 'ProviderPackage' package did not load correctly. The problem may have been caused by a configuration change or by the installation of another extension. You can get more information by examining the file 'C:\Users\username\AppData\Roaming\Microsoft\VisualStudio\11.0\ActivityLog.xml'. Continue to show this error message? --------------------------- Yes No ---------------------------
Change Local Path after download files from Source Control
If you want to change the local path for the working directory of the Team Foundation Server (TFS), you should follow the following steps:
- Go to File -> Source Control -> Advanced->Workspaces,
Attach a Database File to The SQL Server
Wednesday, November 13, 2013
You can attach a database file to an instance of SQL Server by using the SQL Server Management Studio tool. For example, if you have existing database files from an old installation of SQL Server, you can attach these files to a new installation or another instance of SQL Server. Likewise, if you want to restore a corrupt database from a backed-up copy, you can attach the backed-up database file.This topic describes how to attach a database in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL. You can use this feature to copy, move, or upgrade a SQL Server database.
Prerequisites
- When you attach a database, all data files (MDF and NDF files) must be available. If any data file has a different path from when the database was first created or last attached, you must specify the current path of the file.
Add Custom Message to Unit Test Result
If you are using MS test for the Unit test of your code you may need to print some output on the Output window. You can use
To output whatever you'd like. It will show up in the full results of the test runner.
System.Diagnostics.Trace.WriteLine("Hello World!!!!!");
To output whatever you'd like. It will show up in the full results of the test runner.
What is the difference between a Library and a Framework?
Tuesday, November 12, 2013
It is quite a common question in all of the software developers mind, what is the difference between a Library and a Framework? The two concepts are important but sometimes confusing.
A library is just a collection of class definitions. The reason behind is simple, i.e. get the code that has already been written by other developers. The classes and methods normally define specific operations in a certain area. Your code is in charge and it calls into the library when it sees fit. E.g., jQuery.
A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.
Key Difference and Definition of Library and Framework
The most important difference, and in fact the defining difference between a library and a framework is Inversion of Control(IoC). When you call a method in a library, you are in control. But with a framework, the control is inverted: the framework calls you. This is pretty much the difference and definition of a framework. In the framework, all the control flow is already there, and there’s just a bunch of predefined white spots that you should fill out with your code.A library is just a collection of class definitions. The reason behind is simple, i.e. get the code that has already been written by other developers. The classes and methods normally define specific operations in a certain area. Your code is in charge and it calls into the library when it sees fit. E.g., jQuery.
A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.
Subscribe to:
Posts (Atom)

