My 2 cent because I work in a library. I am not attempting to make of judgement of the intentions because I was not there.
Even if he did have on underwear, he still would have a protrusion. So a man's penis protruding is considered more obscene than a woman's breast protruding - talked to the ladies at work about that one.
In our system, you would not have been handled that way. A staff member would have had the balls (pun intended) to tell you to ask you to cover up. Most major libraries have rights for their patrons and due process. Technically, unless it is a private library, you cannot be kicked out. If no one has spoken to you about this issue before then your rights may have been violated and that is serious.
The library has a right to address this issue because in most urban areas, we are responsible for the welfare of children. Due to the economy, it is harder and harder for us to watch out for kids because of the amount of people who come into urban libraries. Our system used to be sort of liberal about porn patrons looking at porn when there were not minors present or no one was offended. However, there were growing incidents of men exposing themselves and the policy changed over night.
The standard at our library is that if you would not do it in a school full of children then you cannot do it there.
If you want to fight it and you believe that you were being victimized by penis envy for your dress, then appeal to the director of the library and if that does not work then the Board of Directors.