EnumHelper.ToDescription C# (CSharp) Méthode

ToDescription() public static méthode

public static ToDescription ( Enum value ) : string
value Enum
Résultat string
        public static string ToDescription(Enum value)
        {
            if (value == null)
            {
                return string.Empty;
            }
            if (!Enum.IsDefined(value.GetType(), value))
            {
                return string.Empty;
            }
            FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
            if (fieldInfo != null)
            {
                DescriptionAttribute[] attributes =
                    fieldInfo.GetCustomAttributes(typeof (DescriptionAttribute), false) as DescriptionAttribute[];
                if (attributes != null && attributes.Length > 0)
                {
                    return attributes[0].Description;
                }
            }
            return StringHelper.ToFriendlyName(value.ToString());
        }
    }

Usage Example

Exemple #1
0
 /// <summary>
 /// 生成流水信息,并更新付款单的最新流水信息号
 /// </summary>
 public void GenerateFlowOrders()
 {
     try
     {
         #region 生成流水信息
         T_Pay_Info_DetailsEntity payDetailsEntity = new T_Pay_Info_DetailsEntity()
         {
             Amount                    = this.operationAmount,
             Createtime                = DateTime.Now,
             PayInfoDetailsCode        = CodeNumber,
             Details_Name              = EnumHelper.ToDescription(PayDetailsTypeEnum.Consumption),
             Details_Type              = (int)PayDetailsTypeEnum.Consumption,
             EcommerceGroupID          = inputPayEntity.EcommerceGroupID,
             EcommerceGroupName        = this.EcommerceProjectMoneyCapacity.EcommerceGroupName,
             Electricity_Supplier_Code = inputPayEntity.Electricity_Supplier_Code,
             Electricity_Supplier_Id   = inputPayEntity.EcommerceID,
             Electricity_Supplier_Name = inputPayEntity.Electricity_Supplier_Name,
             Pay_Info_Code             = inputPayEntity.Pay_Info_Code,
             Pay_Info_Details_ID       = Guid.NewGuid().ToString(),
             Pay_Info_ID               = inputPayEntity.Pay_Info_Id,
             Project_Code              = inputPayEntity.Project_Code,
             Project_ID                = inputPayEntity.Project_Id,
             Project_Name              = inputPayEntity.Project_Name,
         };
         Transdb.Insert(payDetailsEntity);
         inputPayEntity.LastPayInfoDetailsCode = CodeNumber;
         Transdb.Update(inputPayEntity);
         #endregion
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
All Usage Examples Of EnumHelper::ToDescription