title: Getting custom properties of a generic object
body: <p>I've got a method that returns a list of objects.</p>
  
  <pre><code>List&lt;object&gt; messageList = queueQuery.GetMessageCollection();
  
  foreach (object message in messageList)
  {
      string contentType = message.ContentType
  }
  </code></pre>
  
  <p>It doesn't really matter, but the type of these objects happens to be (for now anyway) Microsoft.ServiceBus.Messaging.BrokeredMessage.  However, in the class where I'm working, I don't want it to be dependent on Microsoft.ServiceBus. Separation of concerns.  </p>
  
  <p>The class which houses queueQuery.GetMessageCollection() IS dependent on Microsoft.ServiceBus, but in case we ever want to use another message queue system, I want it so that the worker class which processes the messages is unaware of what type of message it is.</p>
  
  <p>That being said, I need access to some of the properties of these objects.  This screen shot is from the worker class that will process the messages.  I need to get the ContentType.  But, of course, when I try this:</p>
  
  <pre><code>string contentType = message.ContentType
  </code></pre>
  
  <p>I get: 'object' does not contain a definition for 'ContentType'. It IS there. I can see it in the watch.  But.. How do I access this property?</p>
  
  <p><a href="https://i.stack.imgur.com/b7Old.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b7Old.png" alt="enter image description here"></a></p>