MethodInvocationContext

目录

1 MethodInvocationContext

1.1 Contains basic information about a method action

2 ServiceFilterAttribute

2.1 A filter that finds another filter in an .

  1. MethodInvocationContext

using System.Collections.Generic;

using System.ComponentModel;

using System.Reflection;

namespace Flatwhite.Core

{

/// 

    1.  Contains basic information about a method action

/// 

public abstract class MethodInvocationContext

{

/// 

/// The MethodInfo of the executing method

/// 

public MethodInfo MethodInfo { get; internal set; }

/// 

/// The invocation context of the executing method

/// 

public IDictionary<string, object> InvocationContext { get; internal set; }

/// 

/// The result of the method being filtered. Set value to stop the chain

/// 

public object Result {get;set;}

/// 

/// The Invocation data

/// 

[EditorBrowsable(EditorBrowsableState.Never)]

public IInvocation Invocation { get; internal set; }

}

}

  1. ServiceFilterAttribute 

using System;

using System.Diagnostics;

using Microsoft.Extensions.DependencyInjection;

namespace Flatwhite.Core

{

/// 

/// https://github.com/aspnet/Mvc/blob/65af12f1f575fdaee893e0232416df29bb83d7fa/src/Microsoft.AspNetCore.Mvc.Core/ServiceFilterAttribute.cs

    1.   A filter that finds another filter in an IServiceProvider"/>.

    /// 

    /// 

    /// 

    /// Similar to the TypeFilterAttribute"/> in that both use constructor injection. Use

    /// TypeFilterAttribute"/> instead if the filter is not itself a service.

    /// 

    /// 

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]

    [DebuggerDisplay("ServiceFilter: Type={ServiceType} Order={Order}")]

    public class ServiceFilterAttribute : Attribute, IFilterFactory

    {

        /// 

        /// Instantiates a new ServiceFilterAttribute"/> instance.

        /// 

        /// type">The Type"/> of filter to find.

        public ServiceFilterAttribute(Type type)

        {

ServiceType = type ?? throw new ArgumentNullException(nameof(type));

        }

    /// 

    /// Gets or sets the order in which the action filters are executed.

    /// 

        public int Order { get; set; }

        /// 

        /// Gets the Type"/> of filter to find.

        /// 

        public Type ServiceType { get; }

        /// 

        public MethodFilterAttribute CreateInstance(IServiceProvider serviceProvider)

        {

            if (serviceProvider == null)

            {

                throw new ArgumentNullException(nameof(serviceProvider));

            }

            var filter = (MethodFilterAttribute)serviceProvider.GetRequiredService(ServiceType);

            if (filter is IFilterFactory filterFactory)

            {

                // Unwrap filter factories

                filter = filterFactory.CreateInstance(serviceProvider);

            }

filter.Order = Order;

            return filter;

        }

    }

}

你可能感兴趣的:(Flatwhite,javascript)