当前位置: 首页>>代码示例>>C#>>正文


C# Enum.ToString方法代码示例

本文整理汇总了C#中Enum.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Enum.ToString方法的具体用法?C# Enum.ToString怎么用?C# Enum.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Enum的用法示例。


在下文中一共展示了Enum.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEnumDescription

	/// <summary>
	/// Gets the Description of the given Enumeration value 
	/// </summary>
	/// <param name="value">The enumeration value</param>
	/// <returns>The Description from the DescriptionAttribute attached to the value, otherwise the enumeration value's name</returns>
	public static string GetEnumDescription (Enum value)
	{
		FieldInfo fi = value.GetType ().GetField (value.ToString ());
		DescriptionAttribute [] attributes =
			(DescriptionAttribute []) fi.GetCustomAttributes (typeof (DescriptionAttribute), false);
		if (attributes.Length > 0) {
			return attributes [0].Description;
		} else {
			return value.ToString ();
		}
	}
开发者ID:mono,项目名称:gert,代码行数:16,代码来源:EnumDescriptionConverter.cs

示例2: GetDescription

    public static string GetDescription(Enum en)
    {
        Type type = en.GetType();
        MemberInfo[] memInfo = type.GetMember(en.ToString());
        if (memInfo != null && memInfo.Length > 0)
        {
            object[] attrs = memInfo[0].GetCustomAttributes(typeof(Description),
                                                            false);
            if (attrs != null && attrs.Length > 0)
                return ((Description)attrs[0]).Text;
        }

        return en.ToString();
    }
开发者ID:Zelxin,项目名称:ninjatek,代码行数:14,代码来源:Global.cs

示例3: GetStringValue

    /// <summary>
    /// Gets a string value for a particular enum value.
    /// </summary>
    /// <param name="value">Value.</param>
    /// <returns>String Value associated via a <see cref="StringValueAttribute"/> attribute, or null if not found.</returns>
    public static string GetStringValue(Enum value)
    {
        string output = null;
            Type type = value.GetType();

            if (_stringValues.ContainsKey(value))
                output = (_stringValues[value] as StringValueAttribute).Value;
            else
            {
                //Look for our 'StringValueAttribute' in the field's custom attributes
                FieldInfo fi = type.GetField(value.ToString());
                StringValueAttribute[] attrs = fi.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[];
                if (attrs.Length > 0)
                {
                    try
                    {
                        _stringValues.Add(value, attrs[0]);
                    }
                    catch { }
                    output = attrs[0].Value;
                }

            }
            return output;
    }
开发者ID:asifashraf,项目名称:Radmade-Portable-Framework,代码行数:30,代码来源:StringEnum.cs

示例4: ApplyBuff

 float ApplyBuff(Enum statType, float value)
 {
     string strStatType = statType.ToString();
     float addSum = 0;
     float multiSum = 0;
     foreach (var buff in buffs)
     {
         if (buff.Value.statMod != null)
         {
             foreach (var buffStat in buff.Value.statMod)
             {
                 string strBuffStatType = buffStat.Key.ToString();
                 if (strBuffStatType == strStatType)
                 {
                     addSum += buffStat.Value;
                 }
                 else if (strBuffStatType != "GoldGetAmplifier" && strBuffStatType == strStatType + "Amplifier")
                 {
                     multiSum += buffStat.Value;
                 }
             }
         }
     }
     return (value + addSum) * (1 + multiSum);
 }
开发者ID:pb0,项目名称:ID0_Test,代码行数:25,代码来源:Stat.cs

示例5: Limp_Enter

    IEnumerator Limp_Enter(Enum prevState)
    {
        Debug.Log("Enter Limp " + prevState.ToString());
        yield return new WaitForSeconds(5);

        Debug.Log("Limp Entered");
    }
开发者ID:GisleSolv,项目名称:SEP,代码行数:7,代码来源:StateMachineTest.cs

示例6: RemoveState

    public void RemoveState(Enum stateId) {
        FSMState state = GetState(stateId);

        if(state == null)
            throw new Exception("Could not find state " + stateId.ToString() + " for removal.");

        _states.Remove(state);
    }
开发者ID:jtuttle,项目名称:ritual,代码行数:8,代码来源:FiniteStateMachine.cs

示例7: GetDescription

        public static string GetDescription(Enum key)
        {
            FieldInfo fi = key.GetType().GetField(key.ToString());

            if (null != fi)
            {
                object[] attrs = fi.GetCustomAttributes(typeof(EnumDescriptionAttribute), true);
                if (attrs != null && attrs.Length > 0)
                    return ((EnumDescriptionAttribute)attrs[0]).Description;
            }

            return string.Empty;
        }
开发者ID:beerbubble,项目名称:BeerBubbleUtility,代码行数:13,代码来源:EnumHelper.cs

示例8: GetAnchorPosition

 /// <summary>
 /// Looks thought the list of all the UI anchors, then grabs it based on the enum
 /// </summary>
 /// <param name="anchorToGet">The Enum to get </param>
 /// <returns>The UI GameObject</returns>
 public Vector3 GetAnchorPosition(Enum.Anchors anchorToGet)
 {
     try
     {
         GameObject obj = Anchors.Where(x => x.gameObject.name == anchorToGet.ToString()).SingleOrDefault();
         if (obj == null)
             throw new System.Exception("Didn't find an object in list");
         return obj.transform.position;
     }
     catch (System.Exception ex)
     {
         Debug.LogError("[SELF] Couldn't find Anchor in List, Make sure the GameObject and Enum are name exactly the SAME, because it compares strings, error: " + ex.Message + " returning Vector3.Zero");
         return Vector3.zero;
     }
 }
开发者ID:Esildor,项目名称:TBD,代码行数:20,代码来源:Animations.cs

示例9: GetStringValue

    public static string GetStringValue(Enum value)
    {
        // Get the type
        Type type = value.GetType();

        // Get fieldinfo for this type
        FieldInfo fieldInfo = type.GetField(value.ToString());

        // Get the stringvalue attributes
        StringValueAttribute[] attribs = fieldInfo.GetCustomAttributes(
            typeof(StringValueAttribute), false) as StringValueAttribute[];

        // Return the first if there was a match.
        return attribs.Length > 0 ? attribs[0].StringValue : null;
    }
开发者ID:OscarRPR,项目名称:brick-breakout,代码行数:15,代码来源:StringUtils.cs

示例10: Get

    public static string Get(Enum value)
    {
        string output = string.Empty;
        Type type = value.GetType();

        //Look for our 'StringValueAttribute'
        //in the field's custom attributes
        FieldInfo fi = type.GetField(value.ToString());
        StringEnum[] attrs = fi.GetCustomAttributes(typeof(StringEnum), false) as StringEnum[];
        if (attrs.Length > 0)
        {
            output = attrs[0].Value;
        }

        return output;
    }
开发者ID:ReefSmacker,项目名称:MyMovies,代码行数:16,代码来源:StringEnum.cs

示例11: GetFsmEventEnumValue

//	// Update is called once per frame
//	void Update () {
//	
//	}
	
	public static string GetFsmEventEnumValue(Enum value)
    {
        string output = null;
        Type type = value.GetType();

        //Check first in our cached results...

        //Look for our 'NGuiPlayMakerDelegates Attribute' 

        //in the field's custom attributes

        FieldInfo fi = type.GetField(value.ToString());
        PlayMakerUtils_FsmEvent[] attrs = fi.GetCustomAttributes(typeof(PlayMakerUtils_FsmEvent),false) as PlayMakerUtils_FsmEvent[];
        if (attrs.Length > 0)
        {
            output = attrs[0].Value;
        }

        return output;
    }
开发者ID:JulyMars,项目名称:frozen_free_fall,代码行数:25,代码来源:NGuiPlayMakerProxy.cs

示例12: GetSelectList

 public static IList<SelectListItem> GetSelectList(Type type, Enum value)
 {
     IList<SelectListItem> selectList = GetSelectList(type);
     Type type2 = (value == 0) ? null : value.GetType();
     if (((type2 != null) && (type2 != type)) && (type2 != Nullable.GetUnderlyingType(type)))
     {
         throw Error.Argument("value", MvcResources.EnumHelper_InvalidValueParameter, new object[] { type2.FullName, type.FullName });
     }
     if (((value == 0) && (selectList.Count != 0)) && string.IsNullOrEmpty(selectList[0].Value))
     {
         selectList[0].Selected = true;
         return selectList;
     }
     string str = (value == 0) ? "0" : value.ToString("d");
     bool flag = false;
     for (int i = selectList.Count - 1; !flag && (i >= 0); i--)
     {
         SelectListItem item = selectList[i];
         item.Selected = str == item.Value;
         flag |= item.Selected;
     }
     if (!flag)
     {
         if ((selectList.Count != 0) && string.IsNullOrEmpty(selectList[0].Value))
         {
             selectList[0].Selected = true;
             selectList[0].Value = str;
             return selectList;
         }
         SelectListItem item2 = new SelectListItem {
             Selected = true,
             Text = string.Empty,
             Value = str
         };
         selectList.Insert(0, item2);
     }
     return selectList;
 }
开发者ID:Rab815,项目名称:BBWebApi,代码行数:38,代码来源:EnumHelper.cs

示例13: RemoveMember

        /// <summary>
        /// Removes the given member.
        /// </summary>
        /// <param name="member">The member being removed.</param>
        public void RemoveMember(Enum member)
        {
            if (member == null)
            {
                throw Error.ArgumentNull("member");
            }

            if (member.GetType() != ClrType)
            {
                throw Error.Argument("member", SRResources.PropertyDoesNotBelongToType, member.ToString(), ClrType.FullName);
            }

            if (ExplicitMembers.ContainsKey(member))
            {
                ExplicitMembers.Remove(member);
            }

            if (!RemovedMembers.Contains(member))
            {
                RemovedMembers.Add(member);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:26,代码来源:EnumTypeConfiguration.cs

示例14: GetDescription

 // Credits: http://www.codeproject.com/KB/cs/enumwithdescription.aspx?msg=649306#xx649306xx
 private string GetDescription(Enum e)
 {
     FieldInfo fi = e.GetType().GetField(e.ToString());
     DescriptionAttribute[] da = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
     return (da.Length > 0) ? da[0].Description : e.ToString();
 }
开发者ID:jaytem,项目名称:minGit,代码行数:7,代码来源:Spacer.ascx.cs

示例15: AddMember

        /// <summary>
        /// Adds an enum member to this enum type.
        /// </summary>
        /// <param name="member">The member being added.</param>
        /// <returns>The <see cref="EnumMemberConfiguration"/> so that the member can be configured further.</returns>
        public EnumMemberConfiguration AddMember(Enum member)
        {
            if (member == null)
            {
                throw Error.ArgumentNull("member");
            }

            if (member.GetType() != ClrType)
            {
                throw Error.Argument("member", SRResources.PropertyDoesNotBelongToType, member.ToString(), ClrType.FullName);
            }

            // Remove from the ignored members
            if (RemovedMembers.Contains(member))
            {
                RemovedMembers.Remove(member);
            }

            EnumMemberConfiguration memberConfiguration;
            if (ExplicitMembers.ContainsKey(member))
            {
                memberConfiguration = ExplicitMembers[member];
            }
            else
            {
                memberConfiguration = new EnumMemberConfiguration(member, this);
                ExplicitMembers[member] = memberConfiguration;
            }

            return memberConfiguration;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:36,代码来源:EnumTypeConfiguration.cs


注:本文中的Enum.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。