public static Object FromJsValue(this JsValue val) { switch (val.Type) { case Types.Boolean: return val.AsBoolean(); case Types.Number: return val.AsNumber(); case Types.String: return val.AsString(); case Types.Object: var obj = val.AsObject(); var node = obj as DomNodeInstance; if (node != null) return node.Value; return obj; case Types.Undefined: return "undefined"; case Types.Null: return null; } return val.ToObject(); }
/// <summary> /// 기간안에 대상 시각이 포함되는지 여부 /// </summary> /// <param name="period">기간</param> /// <param name="target">대상 일자</param> /// <returns>기간에 포함 여부</returns> public static bool HasInside(this ITimePeriod period, DateTime target) { var hasInside = target >= period.Start && target <= period.End; if(IsDebugEnabled) log.Debug("기간[{0}] 에 일자[{1}]가 포함되는지 여부를 알아봅니다... HasInside=[{2}]", period.AsString(), target.ToSortableString(), hasInside); return hasInside; }
internal static Guid FromNative(this NativeGuid guid) { #if __ANDROID__ return Guid.Parse(guid.ToString()); #elif __IOS__ return Guid.Parse(guid.AsString()); #elif WINDOWS_PHONE_APP return guid; #endif }
/// <summary> /// Invokes <see cref="MessagePackObject.AsString()"/> in deserializaton manner. /// </summary> /// <param name="source"><see cref="MessagePackObject"/>.</param> /// <returns>A deserialized value.</returns> /// <exception cref="SerializationException"><paramref name="source"/> is not expected type.</exception> public static string DeserializeAsString( this MessagePackObject source ) { try { return source.AsString(); } catch ( InvalidOperationException ex ) { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "The unpacked value is not expected type. {0}", ex.Message ), ex ); } }
public static string ContentBeforeLastNewLine(this IEnumerable<SyntaxTrivia> trivia) { var leading = trivia.AsString(); int lastNewLinePos = leading.LastIndexOf(NewLine, StringComparison.Ordinal); if (lastNewLinePos == -1) { return string.Empty; } return leading.Substring(0, lastNewLinePos); }
public static string GetRewriteValue(this Rewrite rewrite, int n) { switch (rewrite) { case Rewrite.top_terms_boost_n: return "top_terms_boost_" + n; case Rewrite.top_terms_n: return "top_terms_" + n; } return rewrite.AsString(); }
public static string ConvertToString(this CBORObject cborObject) { switch (cborObject.Type) { case CBORType.ByteString: return Encoding.UTF8.GetString(cborObject.GetByteString()); case CBORType.TextString: return cborObject.AsString(); default: return cborObject.ToString(); } }
public static DateTime AsDateTime(this object o) { if (o == null || o == DBNull.Value) { return DateTime.MinValue; } try { return DateTime.Parse(o.AsString()); } catch { return DateTime.MinValue; } }
public static object Uncast(this JsValue value) { if (value.IsBoolean()) { return value.AsBoolean(); } if (value.IsNumber()) { return value.AsNumber(); } if (value.IsObject()) { return value.AsObject(); } if (value.IsString()) { return value.AsString(); } return null; }
public static ICreateTableColumnOptionOrWithColumnSyntax AsMaxString(this ICreateTableColumnAsTypeSyntax createTableColumnAsTypeSyntax) { return createTableColumnAsTypeSyntax.AsString(Int32.MaxValue); }
public static IAlterTableColumnOptionOrAddColumnOrAlterColumnSyntax AsMaxString(this IAlterTableColumnAsTypeSyntax createTableColumnAsTypeSyntax) { return createTableColumnAsTypeSyntax.AsString(Int32.MaxValue); }
// The As*** functions never return null -- if the supplied type does not have the appropriate shape, an encoding of a bad type is returned. #region AsPrimitive, AsCollection, AsStructured, ... /// <summary> /// If this reference is of a primitive type, this will return a valid primitive type reference to the type definition. Otherwise, it will return a bad primitive type reference. /// </summary> /// <param name="type">Reference to the calling object.</param> /// <returns>A valid primitive type reference if the definition of the reference is of a primitive type. Otherwise a bad primitive type reference.</returns> public static IEdmPrimitiveTypeReference AsPrimitive(this IEdmTypeReference type) { EdmUtil.CheckArgumentNull(type, "type"); IEdmPrimitiveTypeReference reference = type as IEdmPrimitiveTypeReference; if (reference != null) { return reference; } IEdmType typeDefinition = type.Definition; if (typeDefinition.TypeKind == EdmTypeKind.Primitive) { var primitiveDefinition = typeDefinition as IEdmPrimitiveType; if (primitiveDefinition != null) { switch (primitiveDefinition.PrimitiveKind) { case EdmPrimitiveTypeKind.Boolean: case EdmPrimitiveTypeKind.Byte: case EdmPrimitiveTypeKind.Date: case EdmPrimitiveTypeKind.Double: case EdmPrimitiveTypeKind.Guid: case EdmPrimitiveTypeKind.Int16: case EdmPrimitiveTypeKind.Int32: case EdmPrimitiveTypeKind.Int64: case EdmPrimitiveTypeKind.SByte: case EdmPrimitiveTypeKind.Single: case EdmPrimitiveTypeKind.Stream: return new EdmPrimitiveTypeReference(primitiveDefinition, type.IsNullable); case EdmPrimitiveTypeKind.Binary: return type.AsBinary(); case EdmPrimitiveTypeKind.Decimal: return type.AsDecimal(); case EdmPrimitiveTypeKind.String: return type.AsString(); case EdmPrimitiveTypeKind.Duration: case EdmPrimitiveTypeKind.DateTimeOffset: case EdmPrimitiveTypeKind.TimeOfDay: return type.AsTemporal(); case EdmPrimitiveTypeKind.Geography: case EdmPrimitiveTypeKind.GeographyPoint: case EdmPrimitiveTypeKind.GeographyLineString: case EdmPrimitiveTypeKind.GeographyPolygon: case EdmPrimitiveTypeKind.GeographyCollection: case EdmPrimitiveTypeKind.GeographyMultiPolygon: case EdmPrimitiveTypeKind.GeographyMultiLineString: case EdmPrimitiveTypeKind.GeographyMultiPoint: case EdmPrimitiveTypeKind.Geometry: case EdmPrimitiveTypeKind.GeometryPoint: case EdmPrimitiveTypeKind.GeometryLineString: case EdmPrimitiveTypeKind.GeometryPolygon: case EdmPrimitiveTypeKind.GeometryCollection: case EdmPrimitiveTypeKind.GeometryMultiPolygon: case EdmPrimitiveTypeKind.GeometryMultiLineString: case EdmPrimitiveTypeKind.GeometryMultiPoint: return type.AsSpatial(); case EdmPrimitiveTypeKind.None: break; } } } else if (typeDefinition.TypeKind == EdmTypeKind.TypeDefinition) { return new EdmPrimitiveTypeReference(typeDefinition.UnderlyingType(), type.IsNullable); } string typeFullName = type.FullName(); List<EdmError> errors = new List<EdmError>(type.Errors()); if (errors.Count == 0) { errors.AddRange(ConversionError(type.Location(), typeFullName, EdmConstants.Type_Primitive)); } return new BadPrimitiveTypeReference(typeFullName, type.IsNullable, errors); }
/// <summary> /// Converts time string time span /// </summary> /// <param name="o"></param> /// <returns></returns> public static TimeSpan? TimeToNullableTimespan(this object o) { string sTime = o.AsString(); var arrSplittedTime = sTime.Split(new char[] {' '}); if (arrSplittedTime.Length != 2) { return null; } var amOrPm = arrSplittedTime[1].ToLower(); if (amOrPm != "am" && amOrPm != "pm") { return null; } arrSplittedTime = arrSplittedTime[0].Split(new char[] {':'}); if (arrSplittedTime.Length != 2) { return null; } var hours = arrSplittedTime[0].AsInteger(); var minutes = arrSplittedTime[1].AsInteger(); if (hours == 12 && amOrPm == "am") hours = 0; else hours = hours + (amOrPm == "pm" ? 12 : 0); return new TimeSpan(hours, minutes, 0); }
/// <summary> /// Converts a Polyhedron to a string /// </summary> /// <param name="value"></param> /// <returns></returns> public static string AsPolyhedron(this Polyhedron value) { return value.AsString(); }
public static bool TryConvert(this IJsonValue value, out object propertyValue) { propertyValue = null; if (!value.IsNull()) { switch (value.ValueType) { case JsonValueType.Boolean: propertyValue = value.AsBool().Value; break; case JsonValueType.Number: propertyValue = value.AsNumber().Value; break; case JsonValueType.String: propertyValue = value.AsString(); break; case JsonValueType.Null: break; case JsonValueType.Object: case JsonValueType.Array: default: return false; } } return true; }
public static ICreateTableColumnOptionOrWithColumnSyntax AsText(this ICreateTableColumnAsTypeSyntax that) { return that.AsString(int.MaxValue); }
/// <summary> /// Compares two strings ignoring case according current culture. /// </summary> /// <param name="str1">First string - can be null</param> /// <param name="str2">Second string - can be null</param> public static bool SameText(this string str1, string str2) { return str1.AsString().Equals(str2.AsString(), StringComparison.CurrentCultureIgnoreCase); }
public static dynamic AsJson(this BrowserResponseBodyWrapper bodyWrapper) { return JObject.Parse(bodyWrapper.AsString()); }
/// <summary> /// Try to convert a value to a CLR object. /// </summary> /// <param name="value">The value to convert.</param> /// <param name="propertyValue">The converted value.</param> /// <returns> /// A value indicating whether the conversion was successful. /// </returns> public static bool TryConvert(this JToken value, out object propertyValue) { propertyValue = null; if (!value.IsNull()) { switch (value.Type) { case JTokenType.Boolean: propertyValue = value.AsBool().Value; break; case JTokenType.Float: case JTokenType.Integer: propertyValue = value.AsNumber().Value; break; case JTokenType.String: propertyValue = value.AsString(); break; case JTokenType.Date: propertyValue = value.ToObject<DateTime>(); // AsDateTime() doesn't make sense since DateTime is a reference not object type. (Can't use 'as' operator) break; case JTokenType.Null: break; case JTokenType.Object: case JTokenType.Array: default: return false; } } return true; }
public static string AsSafeSqlString(this string str) { return str.AsString().Replace("'", "''"); }
public static string AsHtml(this string str) { return str.AsString().Replace(" ", " ").Replace("\n", "<BR />"); }
/// <summary> /// Try to convert a value to a CLR object. /// </summary> /// <param name="value">The value to convert.</param> /// <param name="propertyValue">The converted value.</param> /// <returns> /// A value indicating whether the conversion was successful. /// </returns> public static bool TryConvert(this JToken value, out object propertyValue) { propertyValue = null; if (!value.IsNull()) { switch (value.Type) { case JTokenType.Boolean: propertyValue = value.AsBool().Value; break; case JTokenType.Float: case JTokenType.Integer: propertyValue = value.AsNumber().Value; break; case JTokenType.String: propertyValue = value.AsString(); break; case JTokenType.Date: propertyValue = value.ToObject<DateTime>().ToRoundtripDateString(); //win8 store json data serialization doesn't have Date type, and is always returning string type, we should do the same break; case JTokenType.Null: break; case JTokenType.Object: case JTokenType.Array: default: return false; } } return true; }
public static ICreateTableColumnOptionOrWithColumnSyntax AsText(this ICreateTableColumnAsTypeSyntax createTableColumnAsTypeSyntax) { return createTableColumnAsTypeSyntax.AsString(1073741823); }
public static void ShowInConsole(this HbmMapping mapping) { Console.WriteLine(mapping.AsString()); }
public static DateTime AsUtcDateTime(this object o, int offsetHours, int offsetMinutes) { if (o == null || o == DBNull.Value) { return DateTime.MinValue; } try { var dt = DateTime.Parse(o.AsString()); dt = dt.AddHours(offsetHours); if (offsetHours > 0) { offsetMinutes = -offsetMinutes; } dt = dt.AddMinutes(offsetMinutes); return dt; } catch { return DateTime.MinValue; } }
public static bool IsUuidEqual(this NSUuid firstUuid, NSUuid secondUuid) { return firstUuid.AsString().Equals(secondUuid.AsString(), StringComparison.OrdinalIgnoreCase); }
public static bool IsNullOrEmpty(this object o) { return string.IsNullOrEmpty(o.AsString()); }
public static bool AsBoolean(this IAstNodePropertyCollection properties, string name) { return Convert.ToBoolean(properties.AsString(name)); }
/// <summary> /// Converts RectF to a string /// </summary> /// <param name="value"></param> /// <returns></returns> public static string AsString(this RectF value) { return value.AsString(); }
public static bool IsNullOrWhiteSpace(this object o) { return string.IsNullOrWhiteSpace(o.AsString()); }