Coding For a Living

rss

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


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;
        }
    }
}

Roslyn Update Mike McIntyre

Roslyn is Microsoft's effort is about re-architecting the C# and VB compliers so others can use them to create compiler services.

At Build 2014 this month Microsoft previewed language integration and made Roslyn an open source project.

Business rules engines, dynamic scripting, macros, and code refactoring are just a few of the ways Roslyn can be used.

Learn more by reading ‘Taking a tour of Rosylyn’.