コード例 #1
0
        /// <summary>
        /// Creates the target object and appropriate interception when one of the Injector's Create methods is called.
        /// </summary>
        /// <remarks>Implementors can override this method if they need to control creation of the target object.
        /// The base class implementation calls
        /// <see cref="System.Activator.CreateInstance(Type, object[])"/> and then defers the interception
        /// to <see cref="PolicyInjector.DoWrap(object, Type, PolicySet)"/>.</remarks>
        /// <param name="typeToCreate"><see cref="System.Type"/> of target object to create.</param>
        /// <param name="typeToReturn">Type of the reference to return.</param>
        /// <param name="policiesForThisType">Policy set specific to typeToReturn.</param>
        /// <param name="arguments">Constructor parameters.</param>
        /// <returns>The new target object.</returns>
        protected virtual object DoCreate(Type typeToCreate, Type typeToReturn, PolicySet policiesForThisType, object[] arguments)
        {
            object target = Activator.CreateInstance(typeToCreate, arguments);

            return(DoWrap(target, typeToReturn, policiesForThisType));
        }
コード例 #2
0
 /// <summary>
 /// Wraps the given instance in a proxy with interception hooked up if it
 /// is required by policy. If not required, returns the unwrapped instance.
 /// </summary>
 /// <param name="instance">object to wrap.</param>
 /// <param name="typeToReturn">Type of the reference to return.</param>
 /// <param name="policiesForThisType">Policy set specific to typeToReturn.</param>
 /// <returns>The object with policy added.</returns>
 protected abstract object DoWrap(object instance, Type typeToReturn, PolicySet policiesForThisType);
コード例 #3
0
 /// <summary>
 /// Creates a new <see cref="RemotingPolicyInjector" /> with the
 /// given <see cref="PolicySet"/>.
 /// </summary>
 /// <param name="policies"><see cref="PolicySet"/> to use when
 /// creating object or wrapping existing ones.</param>
 public PolicyInjector(PolicySet policies)
 {
     this.policies = policies;
 }
コード例 #4
0
 /// <summary>
 /// Creates a new <see cref="RemotingPolicyInjector" /> with an
 /// empty <see cref="PolicySet" />.
 /// </summary>
 public PolicyInjector()
 {
     policies = new PolicySet();
 }
コード例 #5
0
 /// <summary>
 /// Checks to see if the given policy set requires interception on targets that it is applied to.
 /// </summary>
 /// <param name="policies">Policy set to check.</param>
 /// <returns>True if policy set contains anything, false if not.</returns>
 protected static bool PolicyRequiresInterception(PolicySet policies)
 {
     return(policies.Count > 0);
 }
コード例 #6
0
 private PolicyInjector CreateDefaultInjectorWithGivenPolicySet(PolicySet policies)
 {
     return(new RemotingPolicyInjector(policies));
 }