// // // static char StringCharAt(string str, int idx) { ThrowHelper.ThrowIfNull(str); if ((uint)idx >= (uint)str.Length) { throw new System.ArgumentOutOfRangeException(); } return(str[idx]); }
// // HasFlag // public bool HasFlag(Enum flag) { ThrowHelper.ThrowIfNull(flag); if (!this.GetType().IsEquivalentTo(flag.GetType())) { throw new System.ArgumentException(); } var v = flag.GetLong(); return((GetLong() & v) == v); }
// // ToObject // public static object ToObject(System.Type enumType, long value) { ThrowHelper.ThrowIfNull(enumType); if (!enumType.IsEnum) { throw new System.ArgumentException(); } var enumRuntimeType = enumType as RuntimeType; if (enumRuntimeType == null) { throw new System.ArgumentException(); } return(Box(value, enumRuntimeType.JavaClassForArray())); }
// // Constructor // public Uri(Uri baseUri, Uri relativeUri) { ThrowHelper.ThrowIfNull(baseUri); if (!baseUri.IsAbsoluteUri) { throw new ArgumentOutOfRangeException(); } try { JavaURI = baseUri.JavaURI.resolve(relativeUri.JavaURI); } catch (java.net.URISyntaxException e) { throw new UriFormatException(e.getMessage(), e); } }
// // Constructor // public Uri(string uriString, bool dontEscape, UriKind uriKind) { ThrowHelper.ThrowIfNull(uriString); if (uriString == "") { throw new UriFormatException("empty URI"); } if (!dontEscape) { if (uriKind != UriKind.Relative) { uriString = java.net.URLEncoder.encode(uriString, "UTF-8"); } } try { JavaURI = new java.net.URI(uriString); } catch (java.net.URISyntaxException e) { throw new UriFormatException(e.getMessage(), e); } if (uriKind == UriKind.Absolute) { if (!JavaURI.isAbsolute()) { throw new UriFormatException("relative URI for " + uriKind); } } else if (uriKind == UriKind.Relative) { if (JavaURI.isAbsolute()) { throw new UriFormatException("absolute URI for " + uriKind); } } else if (uriKind != UriKind.RelativeOrAbsolute) { throw new ArgumentException(); } }
public static string Format(System.Type enumType, object value, string format) { ThrowHelper.ThrowIfNull(enumType); if (!enumType.IsEnum) { throw new System.ArgumentException(); } ThrowHelper.ThrowIfNull(value, format); if (enumType is RuntimeType enumRuntimeType) { var enumUnderlyingType = GetUnderlyingType(enumType); var enumCls = enumRuntimeType.JavaClassForArray(); var valueType = value.GetType(); if (value is Enum valueEnum) { var valueUnderlyingType = GetUnderlyingType(valueType); if (object.ReferenceEquals(enumUnderlyingType, valueUnderlyingType)) { return(Format(format, valueEnum.GetLong(), enumCls)); } } else if (object.ReferenceEquals(enumUnderlyingType, valueType)) { switch (value) { case byte byteValue: return(Format(format, (long)byteValue, enumCls)); case char charValue: return(Format(format, (long)charValue, enumCls)); case short shortValue: return(Format(format, (long)shortValue, enumCls)); case int intValue: return(Format(format, (long)intValue, enumCls)); case long longValue: return(Format(format, longValue, enumCls)); } } } throw new System.ArgumentException(); }
public static System.Array GetValues(System.Type enumType) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumValues()); }
public static string[] GetNames(System.Type enumType) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumNames()); }
public static string GetName(System.Type enumType, object value) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumName(value)); }
public static bool IsDefined(System.Type enumType, object value) { ThrowHelper.ThrowIfNull(enumType); return(enumType.IsEnumDefined(value)); }
// // implemented via System.Type: GetUnderlyingType, GetTypeCode, // IsDefined, GetName, GetNames, GetValues // public static System.Type GetUnderlyingType(System.Type enumType) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumUnderlyingType()); }