예제 #1
0
        //
        //
        //

        static char StringCharAt(string str, int idx)
        {
            ThrowHelper.ThrowIfNull(str);
            if ((uint)idx >= (uint)str.Length)
            {
                throw new System.ArgumentOutOfRangeException();
            }
            return(str[idx]);
        }
예제 #2
0
        //
        // 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);
        }
예제 #3
0
        //
        // 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()));
        }
예제 #4
0
        //
        // 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);
            }
        }
예제 #5
0
        //
        // 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();
            }
        }
예제 #6
0
        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();
        }
예제 #7
0
 public static System.Array GetValues(System.Type enumType)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.GetEnumValues());
 }
예제 #8
0
 public static string[] GetNames(System.Type enumType)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.GetEnumNames());
 }
예제 #9
0
 public static string GetName(System.Type enumType, object value)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.GetEnumName(value));
 }
예제 #10
0
 public static bool IsDefined(System.Type enumType, object value)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.IsEnumDefined(value));
 }
예제 #11
0
        //
        // implemented via System.Type:  GetUnderlyingType, GetTypeCode,
        // IsDefined, GetName, GetNames, GetValues
        //

        public static System.Type GetUnderlyingType(System.Type enumType)
        {
            ThrowHelper.ThrowIfNull(enumType);
            return(enumType.GetEnumUnderlyingType());
        }