Sunday, July 14, 2013

Generic Method To get values of an Enum


Recently I got a requirement of creating a generic method to pass an Enum Name & get all the Enum Names & Values.

Method will return a collection of following class objects.

public class EnumValueDto  {

      public string Id { get; set; }

      public string Value { get; set; }

private IList<EnumValueDto  > GetEnumValueList<T>()
        IList<EnumValueDto  > enumValueList = new List<EnumValueDto  >();

        var values = Enum.GetValues(typeof(T)).Cast<T>();
        var enumerable = values as T[] ?? values.ToArray();

        for (int i = 0; i < enumerable.Count(); i++)
            enumValueList.Add(new EnumValueDto  {

Id =((int)Enum.Parse(typeof (T), enumerable.ElementAt(i).ToString())).ToString(),

Value = enumerable.ElementAt(i).ToString() });


        return enumValueList;

Hope this will be helpful.

Happy Coding !!!!!

Sunday, July 7, 2013

Modeling Applications in VS 2012

Designing Systems with a stable architecture is always challenging. But it is one of the most interesting tasks personally I find as a developer, it is where we can improve both technical knowledge & analytical skills.

VS 2012 has come with some new rich tools for modeling the applications to make sure , it meets the user requirements. This tools can be used to visualize the code to understand its structure, relationships, and behavior in a more effective manner. It provides us the facility of create models in different levels :-

  • Track requirements
  • Track Tasks
  • Test cases
  • bugs


Types of Models


1. Dependency Graph

This diagrams shows how your code is been organized & it’s dependencies. This is very useful to identify the code base without going through code lines. You can create a dependency graph for the whole solution & then dig in to the small levels of the assemblies as follows.



2. Layer Diagram

Layer diagram let us to create logical grouping of the Visual studio solutions items. ( projects, classes). Using the layer diagrams you can group you solutions also can visualize the dependencies between the objects in different layers.


You can validate you architecture using layer diagram & generate a report so you can see the failing points. following diagram shows a sample validation report.


3. UML Model

Now you can use visual studio to create UML Diagrams so that you can clarify, understand & communicate your code design & user requirements.

  • Class Diagram
  • Use Cases
  • Activity Diagram
  • Sequence Diagram
  • Component Diagrams


4.Code-Based sequence Diagram

There are situations where we are assigned to projects which has been developed for several months & we are asked to do some modifications. It is always challenging & time consuming to understand the code & understand he flow of it by going through the code lines. Using visual studio you can generate sequence diagrams of a existing code so that you can easily visualize the flow of the method calls.

5. Domain-specific language (DSL)

A domain-specific language is a notation, usually graphical, that is designed to be used for a particular purpose. By contrast, languages such as UML are general-purpose. In a DSL, you can define the types of model element and their relationships, and how they are presented on the screen.

For more Information :


I will describe about this tools in more detail in my next posts.

Happy Modeling !!!!!