Enum.GetValues方法

Enum.GetValues方法:

检索指定枚举中常数值的数组。

反编译代码:

[ComVisible]

public static Array GetValues(Type enumType)

{

    if(enumType==null)

    {

        throw new ArgumentNullException("enumType");

    }

    return enumType.GetEnumValues();

}

 

[DllImport("QCall",CharSet=CharSet.Unicode)]

private static extern void GetEnumValued(RuntimeTypeHandle enumType,ObjectHandleOnStack values,ObjectHandleOnStack names);

 

 

实践使用:

public class ArrayUtility

{

    public static void FillTo<TKey,TValue>(Dictionary<TKey,TValue> dist,TValue defaultValue)

    {

        TKey[] keys=(TKey)Enum.GetValues(typeof(TKey));

        foreach(TKey key in keys)

       {

            dist.Add(key,defaultValue);

        }

    }

}

 

public static void FillTo<TKey,TValue>(Dictionary<TKey,TValue> dist,TValue[] source)

{

    TKey[] keys=(TKey[])Enum.GetValues(typeof(TKey));

   

}

 

posted @ 2012-05-18 22:03  szjdw  阅读(3121)  评论(0编辑  收藏  举报