Coding For a Living

rss

A place to share and comment about coding for a living.


Possible Features of C#.6 and VB.12 Mike McIntyre

Below are some features that may be a part of C#.6 and VB.12.  For current information visit Language feature implementation status for Dev14

Feature status as of 10/3/2014:

Feature

Example

C#

VB

Primary constructors

class Point(int x, int y) { … }

No

No

Auto-property initializers

public int X { get; set; } = x;

Done

Exists

Getter-only auto-properties

public int Y { get; } = y;

Done

Done

Ctor assignment to getter-only autoprops

Y = 15

Done

Done

Parameterless struct ctors

Structure S : Sub New() : End Sub : End Structure

Done

Done

Using static members

using System.Console; … Write(4);

Done

Exists

Dictionary initializer

new JObject { ["x"] = 3, ["y"] = 7 }

Done

No

Indexed member initializer

new JObject { $x = 3, $y = 7 }

No

No

Indexed member access

c.$name = c.$first + " " + c.$last;

No

Exists

Declaration expressions

int.TryParse(s, out var x);

No

No

Await in catch/finally

try … catch { await … } finally { await … }

Done

Maybe

Exception filters

catch(E e) if (e.Count > 5) { … }

Done

Exists

Typecase

Select Case o : Case s As String : …

No

Maybe

Guarded cases

Select Case i : Case Is > 0 When i Mod 2 = 0

No

No

Partial modules

Partial Module M1

N/A

Done

Partial interfaces

Partial Interface I1

Exists

Done

Multiline string literals

"HelloWorld"

Exists

Done

Year-first date literals

Dim d = #2014-04-03#

N/A

Done

Binary literals

0b00000100

No

No

Digit separators

0xEF_FF_00_A0

No

No

Line continuation comments

Dim addrs = From c in Customers ' comment

N/A

Done

TypeOf IsNot

If TypeOf x IsNot Customer Then …

N/A

Done

Expression-bodied members

public double Dist => Sqrt(X * X + Y * Y);

Done

No

Event initializers

new Customer { Notify += MyHandler };

No

No

Null propagation

customer?.Orders?[5]?.$price

Done

Planned

Semicolon operator

(var x = Foo(); Write(x); x * x)

No

No

Private protected

private protected string GetId() { … }

No

No

Params IEnumerable

int Avg(params IEnumerable numbers) { … }

Maybe

Maybe

Constructor Inference

new Tuple(3, "three", true);

No

No

String interpolation

"\{p.First} \{p.Last} is \{p.Age} years old."

Planned

Planned

TryCast for nullable

Dim x = TryCast(u, Integer?)

Exists

No

Delegate combination with +

d1 += d2

Exists

No

Implicit implementation

Class C : Implicitly Implements I

Exists

No

nameof operator

string s = nameof(Console.Write);

Done

Planned

Strict modules

Strict Module M

Exists

No

Faster CInt

Dim x = CInt(Math.Truncate(d)) |

Exists

No

#pragma

#Disable Warning BC40008

Done

Done

Checked and Unchecked blocks

Checked : x += 1 : End Checked

Exists

No

Field targets on autoprops

Serializable> Property p As Integer

Maybe

Maybe

If(b,e1,e2) uses type context

Dim x As Integer? = If(b,1,Nothing)

N/A

No


What is the Microsoft .NET Compiler Platform? Mike McIntyre

The Microsoft .NET Compiler Platform, better known as Roslyn, consists of two compilers (one for C# and one for Visual Basic) with rich code analysis APIs.

Roslyn provides compilers as services which can be used to create code focused tools and applications. This creates opportunities for innovation in areas such as meta-programming, code generation and transformation, scripting, interactive use of the C# and VB languages, and embedding of C# and VB in domain specific languages.

Roslyn exposes the C# and Visual Basic compiler’s code analysis to you as a consumer by providing an API layer that mirrors a traditional compiler pipeline.

image

Each phase of this pipeline is now a separate component. First the parse phase, where source is tokenized and parsed into syntax that follows the language grammar. Second the declaration phase, where declarations from source and imported metadata are analyzed to form named symbols. Next the bind phase, where identifiers in the code are matched to symbols. Finally, the emit phase, where all the information built up by the compiler is emitted as an assembly.

In April 2014 Roslyn went open source.

Get started with Roslyn


Way Back Machine– Microsoft Announces C# Mike McIntyre

Way back in 2000 Microsoft announced C#, and the rest is history.

Excerpt:image

REDMOND, Wash., June 26, 2000 — Microsoft Corp. today announced Microsoft® image ( "C sharp" ), a modern, object-oriented programming language built from the ground up to exploit the power of XML-based Web services on the .NET platform, which was announced last week at Forum 2000. With its Visual C++® development system heritage, C # will enable millions of C and C++ developers to use existing skills to rapidly build sophisticated XML-based .NET applications. To simplify integration and interoperability, Microsoft is working with ECMA, an international standards body, to create a standard for C # , enabling multiple vendors to deliver the language and supporting tools.

Read the entire announcement


Flexible ActionResult Type Mike McIntyre

Below is a class and enum that together provide a flexible way to return an action result to a caller.

It can be used to return error or success results.

It contains multiple constructors that give the flexibility of instantiating the ActionResult object in the context of the called method and possible actions that will take place.

Instantiate before making a call to pass it into a method call or instantiate within a method.

namespace aZSoftware
{
    public enum ActionResultEnum
    {
        Unknown = 0, Success = 1, Failure = 2
    }
    public class ActionResult
    {
        public ActionResultEnum ActionResultEnum { get; set; }

        public string Message { get; set; }
        public object ResultObject { get; set; }
        public string ErrorLog { get; set; }

        public ActionResult(ActionResultEnum actionResult)
        {
            this.ActionResultEnum = actionResult;
            Message = string.Empty;
            ResultObject = null;
            ErrorLog = string.Empty;
        }

        public ActionResult(ActionResultEnum actionResult,string message)
        {
            this.ActionResultEnum = actionResult;
            Message = message;
            ResultObject = null;
            ErrorLog = string.Empty;
        }

        public ActionResult(ActionResultEnum actionResult, string message,object resultObject)
        {
            this.ActionResultEnum = actionResult;
            Message = message;
            ResultObject = resultObject;
            ErrorLog = string.Empty;
        }

        public ActionResult(ActionResultEnum actionResult, string message, object resultObject,string errorLog)
        {
            this.ActionResultEnum = actionResult;
            Message = message;
            ResultObject = resultObject;
            ErrorLog = errorLog;
        }
    }
}

Windows Store apps Dev Center 2013 Mike McIntyre

Have you checked out the Windows Store apps Dev Center lately?

It’s been filled with excellent resources for learning about and developing Windows Store apps. From code, to design guidelines, it’s chuck full of what you need to develop Windows Store Apps.

Windows 8.1

Windows 8.1

Feature guide

Product guide

Getting started

Support forums

Design

Design

Design downloads

Our design principles

Index UX guidelines

iPad to Windows Store app

Migrate

Migrate

iOS

Android

Windows 8

WPF/Silverlight

Develop

Develop

Samples

API reference

Downloads

Certification requirements


What can you do with Roslyn? Scripting Mike McIntyre

With Microsoft Roslyn you can write applications that evaluate code at runtime.

While it’s been possible to implement scripting since the release of .Net it’s not been easy. Check out Brian Rasmussen’s blog on scripting:

     Learn about the Roslyn scripting API


DB Schema Design–Rethinking ‘Type’ Tables Pt 1 Mike McIntyre

If you are a typical business application developer you probably work with a database which is cluttered with ‘type’ tables e.g. InvoiceType, CustomerType, PaymentType, CreditCartType, OrderType, ItemType, ProductType – which all have a schemas similar to these:

     image

There are the same number of columns in each type table above. 

The data type of the columns are the same in all the tables. 

Some column names are the same in all the tables. 

Columns names that are not the same in all tables do follow the same naming rule in each table e.g. ItemTypeId, OrderTypeId, ListTypeId which all end with ‘Id’.

Given how similar these tables are, why not use 2-3 tables for all standard ‘type’ data, maybe something like this?

 

     image

More to follow in part 2 of ‘DB Schema Design–Rethinking ‘Type’ Tables’


Opening the black box with Microsoft® Roslyn Mike McIntyre

image 

Until now the VB and C# compilers have been black boxes, un accessible to Microsoft.Net developers.

Enter Microsoft Roslyn, “a set of APIs for exposing the Microsoft C# and Visual Basic .NET compilers as services available at runtime.”

This software is currently available as a community technology preview (CTP).

Roslyn can be imagined as a “compiler as a Windows service” which VB and C# developers can access through the new Roslyn APIs.

It allows the entire compile-execute process to be invoked from within .Net applications to, for example, give VB and C# a dynamic languages ability to generate and invoke code at runtime.

Or, how about incorporating Roslyn into a .NET application that accepts user input then uses Roslyn APIs to process the input (remember how good old class VB could evaluate a string?)

Roslyn is powerful but you won’t know how powerful it is until you try it out yourself.

Download it today!