예제 #1
0
        //--------------------------------------------------------------------------------

        /// <summary>
        /// Gets an <c>Enum</c> object by class and name.
        /// </summary>
        ///
        /// <param name="enumClass">the class of the Enum to get, must notbe <c>null</c></param>
        /// <param name="name">the name of the <c>Enum</c> to get,may be <c>null</c></param>
        /// <returns>the enum object, or <c>null</c> if the enum does not exist</returns>
        /// <exception cref="IllegalArgumentException if the enum classis <c>null</c>"/>
        protected static internal Enum GetEnum(Type enumClass, String name)
        {
            Enum.Entry entry = GetEntry(enumClass);
            if (entry == null)
            {
                return(null);
            }
            return((Enum)ILOG.J2CsMapping.Collections.Collections.Get(entry.map, name));
        }
예제 #2
0
 /// <summary>
 /// Gets the <c>Map</c> of <c>Enum</c> objects by
 /// name using the <c>Enum</c> class.
 /// If the requested class has no enum objects an empty
 /// <c>Map</c> is returned.
 /// </summary>
 ///
 /// <param name="enumClass">the class of the <c>Enum</c> to get,must not be <c>null</c></param>
 /// <returns>the enum object Map</returns>
 /// <exception cref="IllegalArgumentException if the enum class is <c>null</c>"/>
 /// <exception cref="IllegalArgumentException if the enum class is not a subclass of Enum"/>
 protected static internal IDictionary GetEnumMap(Type enumClass)
 {
     Enum.Entry entry = GetEntry(enumClass);
     if (entry == null)
     {
         return(EMPTY_MAP);
     }
     return(entry.unmodifiableMap);
 }
예제 #3
0
 /// <summary>
 /// Handle the deserialization of the class to ensure that multiple
 /// copies are not wastefully created, or illegal enum types created.
 /// </summary>
 ///
 /// <returns>the resolved object</returns>
 protected internal Object ReadResolve()
 {
     Enum.Entry entry = (Enum.Entry)ILOG.J2CsMapping.Collections.Collections.Get(cEnumClasses, EnumClass);
     if (entry == null)
     {
         return(null);
     }
     return(ILOG.J2CsMapping.Collections.Collections.Get(entry.map, Name));
 }
예제 #4
0
 //-----------------------------------------------------------------------
 /// <summary>
 /// Gets an <c>Entry</c> from the map of Enums.
 /// </summary>
 ///
 /// <param name="enumClass">the class of the <c>Enum</c> to get</param>
 /// <returns>the enum entry</returns>
 private static Enum.Entry GetEntry(Type enumClass)
 {
     if (enumClass == null)
     {
         throw new ArgumentException("The Enum Class must not be null");
     }
     if (typeof(Enum).IsAssignableFrom(enumClass) == false)
     {
         throw new ArgumentException("The Class must be a subclass of Enum");
     }
     if (!cEnumClasses.Contains(enumClass))
     {
         ForciblyLoadClass(enumClass);
     }
     Enum.Entry entry = (Enum.Entry)ILOG.J2CsMapping.Collections.Collections.Get(cEnumClasses, enumClass);
     return(entry);
 }
예제 #5
0
        /// <summary>
        /// Creates an <c>Entry</c> for storing the Enums.
        /// This accounts for subclassed Enums.
        /// </summary>
        ///
        /// <param name="enumClass">the class of the <c>Enum</c> to get</param>
        /// <returns>the enum entry</returns>
        private static Enum.Entry CreateEntry(Type enumClass)
        {
            Enum.Entry entry = new Enum.Entry();
            Type       cls   = enumClass.BaseType;

            while (cls != null && (Object)cls != (Object)typeof(Enum))
            {
                Enum.Entry loopEntry = (Enum.Entry)ILOG.J2CsMapping.Collections.Collections.Get(cEnumClasses, cls);
                if (loopEntry != null)
                {
                    ILOG.J2CsMapping.Collections.Collections.AddAll(loopEntry.list, entry.list);
                    ILOG.J2CsMapping.Collections.Collections.PutAll(entry.map, loopEntry.map);
                    break;                     // stop here, as this will already have had superclasses added
                }
                cls = cls.BaseType;
            }
            return(entry);
        }