Tuesday, 19 July 2016

how to use enum for storing string constants


               Stored String value in ENUM



Code

public enum Modes
        {
            [Description("Value1")]
            Pocket,
            [Description("Value2")]
            Scaning,
            [Description("Value3")]
            Pulse,
           
        }


Get the value
Modes eModes = Modes.Pocket;
String val1= eModes.GetDescription()


Modes eModes = Modes.Scaning;
String val2= eModes.GetDescription()


Modes eModes = Modes.Pulse;
String val3= eModes.GetDescription()


Output

Value1
Value2
Value3

Wednesday, 13 July 2016

What is new (Features) in visual studio 2012?



Asp.Net-C#
1.         Write asynchronous code in an easy and intuitive way.
By using the Async feature, you can call asynchronous methods without defining continuations or splitting your code across multiple methods or lambda expressions. For more information, see Asynchronous Programming with Async and Await (C# and Visual Basic).
// Three things to note in the signature: 
//  - The method has an async modifier.  
//  - The return type is Task or Task<T>. (See "Return Types" section.)
//    Here, it is Task<int> because the return statement returns an integer. 
//  - The method name ends in "Async."
async Task<int> AccessTheWebAsync()
{
    // You need to add a reference to System.Net.Http to declare client.
    HttpClient client = new HttpClient();

    // GetStringAsync returns a Task<string>. That means that when you await the 
    // task you'll get a string (urlContents).
    Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");

    // You can do work here that doesn't rely on the string from GetStringAsync.
    DoIndependentWork();

    // The await operator suspends AccessTheWebAsync. 
    //  - AccessTheWebAsync can't continue until getStringTask is complete. 
    //  - Meanwhile, control returns to the caller of AccessTheWebAsync. 
    //  - Control resumes here when getStringTask is complete.  
    //  - The await operator then retrieves the string result from getStringTask. 
    string urlContents = await getStringTask;

    // The return statement specifies an integer result. 
    // Any methods that are awaiting AccessTheWebAsync retrieve the length value. 
    return urlContents.Length;
}


· 2.       Obtain caller information that assists with tracing and debugging.
You can obtain the source code file path, source code line number, and member name of the caller to a method. For more information, see Caller Information (C# and Visual Basic).

// using System.Runtime.CompilerServices 
// using System.Diagnostics; 

public void DoProcessing()
{
    TraceMessage("Something happened.");
}

public void TraceMessage(string message,
        [CallerMemberName] string memberName = "",
        [CallerFilePath] string sourceFilePath = "",
        [CallerLineNumber] int sourceLineNumber = 0)
{
    Trace.WriteLine("message: " + message);
    Trace.WriteLine("member name: " + memberName);
    Trace.WriteLine("source file path: " + sourceFilePath);
    Trace.WriteLine("source line number: " + sourceLineNumber);
}

// Sample Output: 
//  message: Something happened. 
//  member name: DoProcessing 
//  source file path: c:\Users\username\Documents\Visual Studio 2012\Projects\CallerInfoCS\CallerInfoCS\Form1.cs 
//  source line number: 31



Asp.Net Web Forms

Strongly Typed Data Controls
The next release of ASP.NET provides the ability to enable strongly-typed data templates.  Specifically, we've added the ability to declare what type of data a control is going to be bound to, by way of a new "ModelType" property on data controls.  Setting this property will cause two new typed variables to be generated in the scope of the data-bound template expressions: Item and BindItem.
Developers can use these variables in data-binding expressions and get full Intellisense and compile-time checking support.  For example, below we've set the ModelType on an <asp:repeater> control to be a "Customer" object.  Once we do this we can switch from using Eval("FirstName") to instead use Item.FirstName to reference the property. 
We get full Visual Studio code intellisense when we do so:
For 2-way data-binding expressions, we can also now use the BindItem variable and get the same strongly-typed benefits:





·         Easily build and consume HTTP services that reach a broad range of clients.
Services can be consumed by browsers, mobile applications, tablets, and other devices. Built-in support for content negotiation enables clients and servers to mutually determine the right format for data.
·         Directly access and manipulate HTTP requests and responses by using a modern HTTP programming model.
Use a clean, strongly typed HTTP object programming model that’s supported both on the server and on the client. The new HttpClient API can call web APIs from any .NET Framework application.
·         Easily extract data from an HTTP request.
Model binders make it easier to extract data from various parts of an HTTP request. The message parts become .NET objects that Web API actions can use. The ASP.NET Web API supports the same model binding and validation infrastructure as ASP.NET MVC.
·         Enjoy a full set of routing capabilities.
ASP.NET Web APIs support the full set of routing capabilities in ASP.NET MVC and ASP.NET, including route parameters and constraints.
For more information, see Getting Started with ASP.NET Web API and ASP.NET Web API (Part 1).


Url: http://weblogs.asp.net/scottgu/asp-net-web-api-part-1

WCF Side

·         Develop and maintain WCF applications more easily.
·         Improve the scalability of WCF applications.
 
Enable asynchronous streaming of messages to multiple clients. For more information, see WCF Simplication Features
url: http://go.microsoft.com/fwlink/?LinkID=246803