Пример #1
0
        /// <summary>
        /// Dereferences the target so an update to it will not cause an update to the actual target and result in a crm update post plugin execution
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private static T DereferenceTarget <T>(IPluginExecutionContext context) where T : Entity
        {
            var entity = Activator.CreateInstance <T>();
            var target = context.GetTarget <T>();

            if (target != null)
            {
                entity.Id          = target.Id;
                entity.LogicalName = target.LogicalName;
                foreach (var attribute in target.Attributes)
                {
                    entity[attribute.Key] = attribute.Value;
                }
            }
            return(entity);
        }
Пример #2
0
        /// <summary>
        /// Dereferences the target so an update to it will not cause an update to the actual target and result in a crm update post plugin execution
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private static T DereferenceTarget <T>(IPluginExecutionContext context) where T : Entity
        {
            var target = context.GetTarget <T>();

            return(target?.Clone() ?? Activator.CreateInstance <T>());
        }