public string AsString(TInt value, EnumFormat format) { var isInitialized = false; EnumMemberInternal <TInt, TIntProvider> member = null; return(FormatInternal(value, ref isInitialized, ref member, format)); }
public string AsString(EnumFormat format) { var isInitialized = true; var member = this; return(_enumCache.FormatInternal(Value, ref isInitialized, ref member, format)); }
public void CustomEnumFormat() { EnumFormat symbolFormat = Enums.RegisterCustomEnumFormat(member => member.Attributes.Get <SymbolAttribute>()?.Symbol); Assert.AreEqual(">", NumericOperator.GreaterThan.AsString(symbolFormat)); Assert.AreEqual(NumericOperator.LessThan, Enums.Parse <NumericOperator>("<", ignoreCase: false, symbolFormat)); }
public static void CustomEnumFormatTest() { EnumFormat symbolFormat = Enums.RegisterCustomEnumFormat(member => member.Attributes.Get <SymbolAttribute>()?.Symbol); Console.WriteLine(NumericOperator.GreaterThan.AsString(symbolFormat)); Console.WriteLine((NumericOperator.LessThan, Enums.Parse <NumericOperator>("<", ignoreCase: false, symbolFormat))); }
public EnumConverter(Type sourceEnum, EnumFormat format = EnumFormat.String) { if (sourceEnum.IsEnum == false) { throw new BadUsageException("The Input sourceType must be an Enum but is of type " + sourceEnum.Name); } mEnumType = sourceEnum; mFormat = format; }
public void should_return_option_without_description(EnumFormat enumMode, string value) { var options = GetOptions <EnumEmptyDescription>(x => x.EnumFormat = enumMode).Options; var option = options.Single(); option.Name.ShouldEqual("Option"); option.Value.ShouldEqual(value); option.Comments.ShouldBeNull(); }
/// <summary> /// Initializes a new instance of the <see cref="ElasticMapping"/> class. /// </summary> /// <param name="camelCaseFieldNames">Pass <c>true</c> to automatically camel-case field names (for <see cref="GetFieldName(Type, MemberInfo)"/>).</param> /// <param name="pluralizeTypeNames">Pass <c>true</c> to automatically pluralize type names (for <see cref="GetIndexType"/>).</param> /// <param name="lowerCaseAnalyzedFieldValues">Pass <c>true</c> to automatically convert field values to lower case (for <see cref="FormatValue"/>).</param> /// <param name="enumFormat">Pass <c>EnumFormat.String</c> to format enums as strings or <c>EnumFormat.Integer</c> to use integers (defaults to string).</param> /// <param name="conversionCulture">The culture to use for the lower-casing, camel-casing, and pluralization operations. If <c>null</c>, /// uses <see cref="CultureInfo.CurrentCulture"/>.</param> public ElasticMapping(bool camelCaseFieldNames = true, bool pluralizeTypeNames = true, bool lowerCaseAnalyzedFieldValues = true, EnumFormat enumFormat = EnumFormat.String, CultureInfo conversionCulture = null) { this._camelCaseFieldNames = camelCaseFieldNames; this._pluralizeTypeNames = pluralizeTypeNames; this._lowerCaseAnalyzedFieldValues = lowerCaseAnalyzedFieldValues; this._conversionCulture = conversionCulture ?? CultureInfo.CurrentCulture; this._enumFormat = enumFormat; }
public EnumMemberParser(EnumFormat format, EnumCache <TInt, TIntProvider> enumCache) { _formatValueMap = new Dictionary <string, EnumMemberInternal <TInt, TIntProvider> >(enumCache.GetEnumMemberCount(false), StringComparer.Ordinal); foreach (var member in enumCache.GetEnumMembers(false)) { var formattedValue = member.AsString(format); if (formattedValue != null) { _formatValueMap[formattedValue] = member; } } }
//----------------------------------------------------------------------------- // Mutators //----------------------------------------------------------------------------- /// <summary>Set the value of the property as an enum.</summary> public void SetEnum <TEnum>(TEnum value, EnumFormat format = EnumFormat.String) where TEnum : struct, IConvertible { if (format == EnumFormat.String) { this.value = value.ToString(); } else { this.value = ((int)(object)value).ToString(); } }
/// <summary> /// Initializes a new instance of the <see cref="ElasticMapping"/> class. /// </summary> /// <param name="camelCaseFieldNames">Pass <c>true</c> to automatically camel-case field names (for <see cref="GetFieldName(Type, MemberInfo)"/>).</param> /// <param name="camelCaseTypeNames">Pass <c>true</c> to automatically camel-case type names (for <see cref="GetDocumentType"/>).</param> /// <param name="pluralizeTypeNames">Pass <c>true</c> to automatically pluralize type names (for <see cref="GetDocumentType"/>).</param> /// <param name="lowerCaseAnalyzedFieldValues">Pass <c>true</c> to automatically convert field values to lower case (for <see cref="FormatValue"/>).</param> /// <param name="enumFormat">Pass <c>EnumFormat.String</c> to format enums as strings or <c>EnumFormat.Integer</c> to use integers (defaults to string).</param> /// <param name="conversionCulture">The culture to use for the lower-casing, camel-casing, and pluralization operations. If <c>null</c>, /// uses <see cref="CultureInfo.CurrentCulture"/>.</param> public ElasticMapping(bool camelCaseFieldNames = true, bool camelCaseTypeNames = true, bool pluralizeTypeNames = true, bool lowerCaseAnalyzedFieldValues = true, EnumFormat enumFormat = EnumFormat.String, CultureInfo conversionCulture = null) { this.camelCaseFieldNames = camelCaseFieldNames; this.camelCaseTypeNames = camelCaseTypeNames; this.pluralizeTypeNames = pluralizeTypeNames; this.lowerCaseAnalyzedFieldValues = lowerCaseAnalyzedFieldValues; this.conversionCulture = conversionCulture ?? CultureInfo.CurrentCulture; this.enumFormat = enumFormat; }
//----------------------------------------------------------------------------- // Get Accessors //----------------------------------------------------------------------------- /// <summary>Gets the value of the property as an enum.</summary> public TEnum GetEnum <TEnum>(EnumFormat format = EnumFormat.String) where TEnum : struct, IConvertible { if (format == EnumFormat.String) { TEnum result; Enum.TryParse(value, out result); return(result); } else { return((TEnum)Enum.ToObject(typeof(TEnum), GetInt())); } }
public EnumMemberParser(EnumFormat format, [NotNull] EnumCache <TInt, TIntProvider> enumCache) { _formatValueMap = new Dictionary <string, EnumMember <TInt, TIntProvider> >(enumCache.GetMemberCount(EnumMemberSelection.All), StringComparer.Ordinal); foreach (EnumMember <TInt, TIntProvider> member in enumCache.GetMembers(EnumMemberSelection.All)) { string formattedValue = member.AsString(format); if (formattedValue != null) { _formatValueMap[formattedValue] = member; } } }
/// <summary> /// Initializes a new instance of the <see cref="ElasticMapping"/> class. /// </summary> /// <param name="connection">The information on how to connect to the Elasticsearch server.</param> /// <param name="log">The object which logs information (optional, defaults to <see cref="NullLog"/>).</param> /// <param name="camelCaseFieldNames">Pass <c>true</c> to automatically camel-case field names (for <see cref="GetFieldName(Type, MemberInfo)"/>).</param> /// <param name="pluralizeTypeNames">Pass <c>true</c> to automatically pluralize type names (for <see cref="GetIndexType"/>).</param> /// <param name="lowerCaseAnalyzedFieldValues">Pass <c>true</c> to automatically convert field values to lower case (for <see cref="FormatValue"/>).</param> /// <param name="enumFormat">Pass <c>EnumFormat.String</c> to format enums as strings or <c>EnumFormat.Integer</c> to use integers (defaults to string).</param> /// <param name="conversionCulture">The culture to use for the lower-casing, camel-casing, and pluralization operations. If <c>null</c>, /// uses <see cref="CultureInfo.CurrentCulture"/>.</param> public ElasticMapping(IElasticConnection connection, ILog log, bool camelCaseFieldNames = true, bool pluralizeTypeNames = true, bool lowerCaseAnalyzedFieldValues = true, EnumFormat enumFormat = EnumFormat.String, CultureInfo conversionCulture = null) { this._camelCaseFieldNames = camelCaseFieldNames; this._pluralizeTypeNames = pluralizeTypeNames; this._lowerCaseAnalyzedFieldValues = lowerCaseAnalyzedFieldValues; this._conversionCulture = conversionCulture ?? CultureInfo.CurrentCulture; this._enumFormat = enumFormat; _elasticPropertyMappings = new Lazy <IDictionary <string, string> >(() => { return(connection.GetPropertiesMappings(log).Result); }); }
//----------------------------------------------------------------------------- // Try Get Accessors //----------------------------------------------------------------------------- /// <summary>Trys to get the value of the property as an enum.</summary> public bool TryGetEnum <TEnum>(out TEnum result, EnumFormat format = EnumFormat.String) where TEnum : struct, IConvertible { try { if (format == EnumFormat.String) { result = (TEnum)Enum.Parse(typeof(TEnum), value); } else { result = (TEnum)Enum.ToObject(typeof(TEnum), GetInt()); } return(true); } catch { result = Activator.CreateInstance <TEnum>(); return(false); } }
/// <summary> /// Formats the channel value, which is an enumeration. /// </summary> protected string FormatEnum(double cnlVal, int dataTypeID, EnumFormat format) { string GetEnumValue(int intVal) { return(format != null && 0 <= intVal && intVal < format.Values.Length ? format.Values[intVal] : intVal.ToString()); } switch (dataTypeID) { case DataTypeID.Double: return(GetEnumValue((int)cnlVal)); case DataTypeID.Int64: return(GetEnumValue((int)CnlDataConverter.DoubleToInt64(cnlVal))); default: return(FormatError); } }
private EnumMemberParser GetEnumMemberParser(EnumFormat format) { var index = format - EnumFormat.Name; var parsers = _enumMemberParsers; EnumMemberParser parser; if (index < 0 || parsers == null || index >= parsers.Length || (parser = parsers[index]) == null) { format.Validate(nameof(format)); parser = new EnumMemberParser(format, this); EnumMemberParser[] oldParsers; do { oldParsers = parsers; parsers = new EnumMemberParser[Math.Max(oldParsers?.Length ?? 0, index + 1)]; oldParsers?.CopyTo(parsers, 0); parsers[index] = parser; } while ((parsers = Interlocked.CompareExchange(ref _enumMemberParsers, parsers, oldParsers)) != oldParsers); } return(parser); }
/// <summary> /// 完成处理 /// </summary> /// <param name="repairId">报修记录id</param> /// <param name="mediaIdList">meidia Id列表</param> /// <param name="describe">文字描述</param> /// <param name="type">完成类型</param> /// <returns></returns> public Repair FinishHandlen(int repairId, IEnumerable <string> mediaIdList, string describe, RepairFinishType type) { var db = new ModelContext(); var rep = db.RepairSet.Include("Village").FirstOrDefault(item => item.RepairId == repairId); if (rep == null) { return(null); } rep.Status = RepairStatus.FinishHandle; rep.FinishHandlendDate = DateTime.Now; rep.FinishType = type; rep.Describe = describe; db.SaveChanges(); var cl = WechatImageHelper.AddNewImageForHandleRepair(rep.RepairId, mediaIdList).ToList(); cl.Clear(); //发送模板消息 string content = rep.Contenet.Replace("<br />", "").Length > 7 ? rep.Contenet.Replace("<br />", "").Substring(0, 6) + "..." : rep.Contenet.Replace("<br />", ""); var wuser = WechatHelper.CheckWechatUser(rep.UserId ?? 0); if (wuser != null && !string.IsNullOrEmpty(wuser.OpenId)) { string url = string.Format("http://mp.doshine.com/doshinemp/PhoneWeb/RepairDetails?repairid={0}", rep.RepairId); WechatHelper.SendModelMessage( wuser.OpenId, url, "bI7o_XjdW10WRf1gPvmEpddVmBahfh97Irgv4u-__Gc", string.Format("\"first\":{{\"value\":\"您好,您的报修申请已完成处理\",\"color\":\"#000000\"}},\"keyword1\":{{\"value\":\"{0}\",\"color\":\"#173177\"}},\"keyword2\":{{\"value\":\"{1}\",\"color\":\"#173177\"}},\"remark\":{{\"value\":\"保修内容:{3}\\n处理结果:{2}\",\"color\":\"#000000\"}}", rep.InnerNumber, rep.FinishHandlendDate.Value.ToLongDateString() + " " + rep.FinishHandlendDate.Value.ToShortTimeString(), EnumFormat.GetDescription(rep.FinishType), content)); } return(rep); }
public static string?AsString <TEnum>(TEnum value, EnumFormat format0, EnumFormat format1, EnumFormat format2) => Enums.AsStringUnsafe(value, format0, format1, format2);
internal string FormatInternal(TInt value, EnumMemberInternal <TInt, TIntProvider> member, EnumFormat format0, EnumFormat format1, EnumFormat format2) { var isInitialized = member != null; return(FormatInternal(value, ref isInitialized, ref member, format0) ?? FormatInternal(value, ref isInitialized, ref member, format1) ?? FormatInternal(value, ref isInitialized, ref member, format2)); }
internal string FormatInternal(TInt value, ref bool isInitialized, ref EnumMemberInternal <TInt, TIntProvider> member, EnumFormat format) { if (format == EnumFormat.DecimalValue) { return(value.ToString()); } if (format == EnumFormat.HexadecimalValue) { return(value.ToString(Provider.HexFormatString, null)); } if (!isInitialized) { member = GetEnumMember(value); isInitialized = true; } switch (format) { case EnumFormat.Name: return(member?.Name); case EnumFormat.Description: return(member?.GetAttribute <DescriptionAttribute>()?.Description); #if ENUM_MEMBER_ATTRIBUTE case EnumFormat.EnumMemberValue: return(member?.GetAttribute <EnumMemberAttribute>()?.Value); #endif default: format.Validate(nameof(format)); return(member != null?Enums.CustomEnumMemberFormat(member.EnumMember, format) : null); } }
/// <summary> /// Converts the specified <paramref name="value"/> to its string representation using the specified formats. /// </summary> /// <param name="enumType">The enum type.</param> /// <param name="value">The enum value.</param> /// <param name="format0">The first output format to use.</param> /// <param name="format1">The second output format to use if using the first resolves to <c>null</c>.</param> /// <param name="format2">The third output format to use if using the first and second both resolve to <c>null</c>.</param> /// <returns>A string representation of <paramref name="value"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="enumType"/> or <paramref name="value"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="enumType"/> is not an enum type /// -or- /// <paramref name="format0"/>, <paramref name="format1"/>, or <paramref name="format2"/> is an invalid value.</exception> public static string AsString(Type enumType, object value, EnumFormat format0, EnumFormat format1, EnumFormat format2) { var info = GetNonGenericEnumInfo(enumType); if (value == null && info.IsNullable) { return null; } return info.EnumInfo.AsString(value, format0, format1, format2); }
public string ToSocketString() { return($"{SocketToWMSFormat.Start}{EnumFormat.ToFormatted(SocketMsgType.SpMoveConfirmResponse)}{pctMvhId}{SocketToWMSFormat.End}"); }
public string ToSocketString() { return($"{SocketToWMSFormat.Start}{EnumFormat.ToFormatted(SocketMsgType.SpMoveFinish)}{taskId}{ToSubSocketString()}{SocketToWMSFormat.End}"); }
public NestElasticLinqMapping(EnumFormat enumFormat = EnumFormat.String, CultureInfo conversionCulture = null) : base(camelCaseFieldNames: true, camelCaseTypeNames: false, pluralizeTypeNames: false, lowerCaseAnalyzedFieldValues: true, enumFormat: enumFormat, conversionCulture: conversionCulture) { }
public static bool TryParse <TEnum>(string?value, out TEnum result, EnumFormat format0, EnumFormat format1) => Enums.TryParseUnsafe(value, out result, format0, format1);
public static TEnum Parse <TEnum>(string value, EnumFormat format0, EnumFormat format1) => Enums.ParseUnsafe <TEnum>(value, format0, format1);
public static EnumMember <TEnum>?GetMember <TEnum>(string value, EnumFormat format0, EnumFormat format1) => Enums.GetMemberUnsafe <TEnum>(value, format0, format1);
public static EnumMember <TEnum>?GetMember <TEnum>(string value, bool ignoreCase, EnumFormat format0, EnumFormat format1, EnumFormat format2) => Enums.GetMemberUnsafe <TEnum>(value, ignoreCase, format0, format1, format2);
public string AsString(TInt value, EnumFormat format0, EnumFormat format1, EnumFormat format2) => FormatInternal(value, null, format0, format1, format2);
public static TEnum Parse <TEnum>(string value, bool ignoreCase, EnumFormat format0, EnumFormat format1, EnumFormat format2) => Enums.ParseUnsafe <TEnum>(value, ignoreCase, format0, format1, format2);
public static string LtcGetDescription <TEnum>(this TEnum val, EnumFormat format = EnumFormat.Description, EnumFormat format2 = EnumFormat.DisplayName) where TEnum : struct, Enum { return(val.AsString(format, format2) ?? string.Empty); }
public static bool TryParse <TEnum>(string?value, bool ignoreCase, out TEnum result, EnumFormat format0, EnumFormat format1, EnumFormat format2) => Enums.TryParseUnsafe(value, ignoreCase, out result, format0, format1, format2);
public string ToSocketString() { return($"{SocketToWMSFormat.Start}{EnumFormat.ToFormatted(SocketMsgType.SpMoveRackArriveConfirm)}{taskId}{SocketToWMSFormat.End}"); }