Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Wednesday, June 6, 2012

Getting list of Enum in C#

Here is the code to get the list of all the Enum values in a Enum

public static List<T> GetEnumValues<T>()
        {
            var type = typeof(T);
            if (!type.IsEnum)
                throw new ArgumentException("Type '" + type.Name + "' is not an enum");

            return (
              from field in type.GetFields(BindingFlags.Public | BindingFlags.Static)
              where field.IsLiteral
              select (T)field.GetValue(null)
            ).ToList();
        }


Lets say you enum is like this

public enum CustomerType
{
        Master,
        Normal,
        Existing
}

To get the list that contains all the CustomerType like (Master,Normal,Existing)

You need to write code like this
GetEnumValues<CustomerType>() and you get the list of CustomerType enum values.

Your comments/questions/suggestions are appreciated.

Cheers!
Vinod

Sunday, June 3, 2012

Listbox in Silverlight horizontally

If you want to show items horizontally using Listbox its quite easy and straightforward. What you all need to do is all

<ListBox>
           <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
</ListBox>


And you will see the list now horizontally :)

Cheers!
Vinod

Pivot Viewer using Silverlight

You can create your own pivotViewer with all the customization. What you need is to generate CXML from your data and pass it to pivotcontrol. It will generate a wonderful chart for you. Once you are done with this thing you will face some issue while deploying on server. Becoz normally IIS doesn't allow CXML request so you need to allow .cxml in MIME type of IIS. If you have any question regarding pivotViewer control write to me.

Regards
Vinod

Tuesday, April 3, 2012

Use of Template and where in C#

public abstract class BaseDA where T : BaseEntity
{

}

where T:BaseEntity defines it should be of type BaseEntity only otherwise it would give runtime exceptions