Ejemplo n.º 1
0
    public Peer GetPeer(Type clr_type)
    {
        Peer peer;

        if (Peer.CLRIsValueType(clr_type))
        {
            peer = this[clr_type];
            if (peer != null)
            {
                return(peer);
            }

            if (Peer.CLRIsEnum(clr_type))
            {
                peer = this[Peer.CLRUnderlyingType(clr_type)];
                if (peer != null)
                {
                    return(peer);
                }

                throw new ArgumentException("Could not find peer or underlying peer for enum " + clr_type);
            }
            else
            {
                throw new ArgumentException("Could not find peer for value type " + clr_type);
            }
        }
        else
        {
            Type type = clr_type;
            while (type != null)
            {
                peer = this[type];
                if (peer != null)
                {
                    return(peer);
                }

                type = type.BaseType;
            }

            throw new ArgumentException("Could not find peer for class " + clr_type);
        }
    }