views:

41

answers:

1

I want to do some stuff to WebParts based on the type of WebPart is being passed to a method. I'm finding that I'm doing:

if(obj is Microsoft.SharePoint.WebPartPages.ContentEditorWebPart)
...
else if (obj is SummaryLinkWebPart)

It smells funny to keep doing this for all WebParts. Is there a design pattern that I should be using instead?

A: 

If you need to access members specific to a certain type then there really isn't any superclean way of doing so. If you want, you can use the as operator to achieve the same effect as above:

wp = obj as Microsoft.SharePoint.WebPartPages.ContentEditorWebPart;
if(wp != null)
   ...
zincorp