Skip to content

IPluginExecutionContext Extensions

Artem Grunin edited this page Mar 21, 2019 · 2 revisions

IPluginExecutionContext Extensions

Set of extension methods for Microsoft.Xrm.Sdk.IPluginExecutionContext base class. Most of this helpers are shortcuts for existing properties but provides additional checks or type casts. Unlike Entity class extensions most of the following extensions are not exception safe! It is done so because you most likely want to get an error if plugin is registered for a wrong message or you have a typo in parameter name.

GetOrganization

Return OrganizationId and OrganizationName fields as single EntityReference.

public EntityReference GetOrganization();

GetPrimaryEntity

Return PrimaryEntityId and PrimaryEntityName fields as single EntityReference.

public EntityReference GetPrimaryEntity();

GetUser

Return UserId field as EntityReference.

public EntityReference GetUser();

GetInitiatingUser

Return InitiatingUserId field as EntityReference.

public EntityReference GetInitiatingUser();

GetBusinessUnit

Return BusinessUnitId field as EntityReference.

public EntityReference GetBusinessUnit();

GetInputParameter<T>

Gets input paramer as the specified type.

public T GetInputParameter<T>(String name) where;

GetOutputParameter<T>

Gets output paramer as the specified type.

public T GetOutputParameter<T>(String name);

GetPreImage

Gets pre image.

public Entity GetPreImage(String name);

GetPreImage<T>

Gets pre image as the specified type.

public T GetPreImage<T>(String name) where T : Entity;

GetPostImage

Gets post image.

public Entity GetPostImage(String name);

GetPostImage<T>

Gets post image as the specified type.

public T GetPostImage<T>(String name) where T : Entity;

GetTarget

Shortcut for getting "Target" input parameter of type Entity.

public Entity GetTarget();

GetTarget<T>

Shortcut for getting "Target" input parameter as the specified type.

public T GetTarget<T>() where T : Entity;

GetPreTarget<T>

Get "Target" entity parameter merged with specified pre image.

public T GetPreTarget<T>(String name) where T : Entity;

GetPostTarget<T>

Get "Target" entity parameter merged with specified post image.

public T GetPostTarget<T>(String name) where T : Entity;

GetSharedVariable<T>

Gets shared Variable.

public T GetSharedVariable<T>(String name);

GetRelatedEntitiesByTarget

Simplifies handling of Associate and Disassociate messages. This messages can't be filtered by entity type, furthermore two options possible: when "A" entity is associated with array of "B", or "B" is associated with array of "A". This method generates universal dictionary of arguments which is suitable in all cases.

public Dictionary<EntityReference, EntityReferenceCollection> GetRelatedEntitiesByTarget(String keyEntity, String valueEntity);