Is Target always an entity or can it be an EntityReference?

I found that in some of my code I have the following syntax protecting the plugin from FUBARing. I can’t love God, I don’t remember why I put a conditional expression for EntityReference.

Is Context.InputParameters ["Target"] each EntityReference?

bool goodToGo = Context.InputParameters.Contains("Target") && Context.PrimaryEntityName == "email"; && ( Context.InputParameters["Target"] is Entity || Context.InputParameters["Target"] is EntityReference); 

Is it ever anything other than Entity?

+4
source share
1 answer

The target may also be an EntityReference, from MSDN:

Please note that not all requests contain the Target property, which is of type Entity, so you need to look at each individual request or response. For example, DeleteRequest has the Target property, but its type is EntityReference.

Understand the data context passed to the plugin

So, depending on the logic of your plugin, you may also need to check the type of the property for EntityReference.

+10
source

All Articles