本文介绍了无法将类型'string'隐式转换为'Kaizen.Framework.FileType'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

Hi Everyone,

I have a Filetype as enum.
namespace Kaizen.Framework
{
    [Serializable]
    [DataContract]
    public enum FileType
    {
        [EnumMember]
        None = 0,
        [EnumMember]
        DsrGsm = 1,
        [EnumMember]
        ZteNbh = 2,
        [EnumMember]
        ZteCfr = 3,
        [EnumMember]
        NsnNbh = 4,
        [EnumMember]
        NsnCfr = 5,
        [EnumMember]
        HuaweiNbh = 6,
        [EnumMember]
        HuaweiCfr = 7,
        [EnumMember]
        ZteBbh = 8,
        [EnumMember]
        NsnBbh = 9,
        [EnumMember]
        HuaweiBbh = 10,
        [EnumMember]
        ZteDbh = 11,
        [EnumMember]
        NsnDbh = 12,
        [EnumMember]
        HuaweiDbh = 13,
        [EnumMember]
        ZteDbbh = 14,
        [EnumMember]
        NsnDbbh = 15,
        [EnumMember]
        HuaweiDbbh = 16,
        [EnumMember]
        ZteEdap = 17,
        [EnumMember]
        NsnEdap = 18,
        [EnumMember]
        HuaweiEdap = 19,
        [EnumMember]
        ZtePcu = 20,
        [EnumMember]
        NsnPcu = 21,
        [EnumMember]
        HuaweiPcu = 22,
        [EnumMember]
        ZteTops = 23,
        [EnumMember]
        NsnTops = 24,
        [EnumMember]
        HuaweiTops = 25,
        [EnumMember]
        NocNqi2G = 26,
        [EnumMember]
        DsrCdma = 27,
        [EnumMember]
        GsmVlr = 28,
        [EnumMember]
        ICR = 29,
        [EnumMember]
        NR = 30,
    }


I am getting the Data from Entity.
fileLog.FileType = dataReader[KaizenConstants.FILETYPE].ObjectToString();

In Datamanager class it gives me error
Error	18	Cannot implicitly convert type 'string' to 'Kaizen.Framework.FileType'	
What is the way to convert it?

Please kindly revert.

推荐答案

public static T ParseEnum<T>( string value )
{
    return (T) Enum.Parse( typeof( T ), value, true );
}


这篇关于无法将类型'string'隐式转换为'Kaizen.Framework.FileType'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 19:00