/** provides a unique instance of this class.
         *
         * This function returns null if the specified type is no polymorphic struct.
         *
         * @param type
         * the type of the polymorphic struct. For example, created by
         * <code>typeof(unoidl.com.sun.star.beans.Defaulted)</code>
         * @param name
         * the full name of the struct (including the type list).
         * @return
         * null - the argument type is no valid polymorphic struct or <br>
         * an instance of this class.
         * @exception System.ArgumentNullException
         * The argument was null.
         */
        public static PolymorphicType GetType(Type type, string name)
        {
            if (name == null || type == null)
            {
                throw new ArgumentNullException(
                          "cli-uno: uno.PolymorphicType.GetType was called with a null argument");
            }
            //check if the type is either a array of structs or a polymorphic struct.
            if (type.IsArray)
            {
                Type elementType = type;
                while ((elementType = elementType.GetElementType()).IsArray)
                {
                    ;
                }
                //unfortunately we cannot check if it is a real polymorphic struct here.
                if (!elementType.IsClass)
                {
                    return(null);
                }
            }
            else if (Attribute.GetCustomAttribute(type, typeof(uno.TypeParametersAttribute))
                     == null)
            {
                return(null);
            }

            lock (m_ht_types.SyncRoot)
            {
                PolymorphicType t = (PolymorphicType)m_ht_types[name];
                if (t == null)
                {
                    t = new PolymorphicType(type, name);
                    m_ht_types.Add(name, t);
                }
                return(t);
            }
        }
Exemple #2
0
    /** provides a unique instance of this class.
      
       This function returns null if the specified type is no polymorphic struct.
       
       @param type
       the type of the polymorphic struct. For example, created by
       <code>typeof(unoidl.com.sun.star.beans.Defaulted)</code>
       @param name
       the full name of the struct (including the type list).
       @return
       null - the argument type is no valid polymorphic struct or <br>
       an instance of this class.
       @exception System.ArgumentNullException
       The argument was null.
     */
    public static PolymorphicType GetType(Type type, string name)
    {
        if (name == null || type == null)
            throw new ArgumentNullException(
                "cli-uno: uno.PolymorphicType.GetType was called with a null argument");
        //check if the type is either a array of structs or a polymorphic struct.
        if (type.IsArray)
        {
            Type elementType = type;
            while ((elementType = elementType.GetElementType()).IsArray);
			//unfortunately we cannot check if it is a real polymorphic struct here.
			if ( ! elementType.IsClass)
				return null;
                   
            
        }
        else if (Attribute.GetCustomAttribute(type, typeof(uno.TypeParametersAttribute))
            == null)
        {
            return null;
        }

        lock (m_ht_types.SyncRoot)
        {
            PolymorphicType t = (PolymorphicType) m_ht_types[name];
            if (t == null)
            {
                t = new PolymorphicType(type, name);
                m_ht_types.Add(name, t);
            }
            return t;
        }
    }