问题
I discovered that in some of my code I have the following syntax guarding the plugin from FUBARing. I can't for the love of god not remember why I put the disjuction conditional for EntityReference.
Is Context.InputParameters["Target"] every 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?
回答1:
Target can be also an EntityReference, from MSDN:
Note that not all requests contain a Target property that is of type Entity, so you do have to look at each individual request or response. For example, DeleteRequest does have a Target property but its type is EntityReference.
Understand the Data Context Passed to a Plug-In
So depending on the logic of your plugin you may need to check the property type also for EntityReference.
来源:https://stackoverflow.com/questions/15613026/is-target-always-an-entity-or-can-it-be-entityreference