<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using PostSharp.Aspects;
using PostSharp.Extensibility;

namespace PostSharp.Samples.Authorization.Framework
{
  /// <summary>
  ///   Base class for <see cref="RequiresPermissionAttribute" />. This abstraction does not make any assumption regarding
  ///   the implementation of the <see cref="IPermission" />, i.e. it does not assume that a permission is simply a named
  ///   object.
  ///   It could be used to implementation for instance parametric permissions.
  /// </summary>
  [Serializable]
  [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
  public abstract class RequiresPermissionBaseAttribute : Attribute, IPermissionFactory, IAspectProvider
  {
    /// <summary>
    ///   Invoked at build time to get the list of aspects required to implement the current custom attribute.
    /// </summary>
    /// <param name="targetElement">Declaration on which the attribute has been applied.</param>
    /// <returns>A collection of aspect instances.</returns>
    public virtual IEnumerable<AspectInstance> ProvideAspects(object targetElement)
    {
      var aspectRepositoryService =
        PostSharpEnvironment.CurrentProject.GetService<IAspectRepositoryService>();

      var aspects = aspectRepositoryService.GetAspectInstances(targetElement) ?? new IAspectInstance[0];


      var aspect = (AuthorizationAspect) aspects.Where(i => i != null) // TODO: Fix bug in PostSharp and remove this.
        .Select(i => i.Aspect).SingleOrDefault(i => i is AuthorizationAspect);

      if (aspect == null)
      {
        if (targetElement is MethodBase)
          aspect = new MethodAuthorizationAspect();
        else if (targetElement is PropertyInfo || targetElement is FieldInfo)
          aspect = new LocationAuthorizationAspect();
        else if (targetElement is ParameterInfo)<commit_msg>Fixed incorrect bug workaround in PostSharp.Samples.Authorization.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using PostSharp.Aspects;
using PostSharp.Extensibility;

namespace PostSharp.Samples.Authorization.Framework
{
  /// <summary>
  ///   Base class for <see cref="RequiresPermissionAttribute" />. This abstraction does not make any assumption regarding
  ///   the implementation of the <see cref="IPermission" />, i.e. it does not assume that a permission is simply a named
  ///   object.
  ///   It could be used to implementation for instance parametric permissions.
  /// </summary>
  [Serializable]
  [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
  public abstract class RequiresPermissionBaseAttribute : Attribute, IPermissionFactory, IAspectProvider
  {
    /// <summary>
    ///   Invoked at build time to get the list of aspects required to implement the current custom attribute.
    /// </summary>
    /// <param name="targetElement">Declaration on which the attribute has been applied.</param>
    /// <returns>A collection of aspect instances.</returns>
    public virtual IEnumerable<AspectInstance> ProvideAspects(object targetElement)
    {
      var aspectRepositoryService =
        PostSharpEnvironment.CurrentProject.GetService<IAspectRepositoryService>();

      var aspects = aspectRepositoryService.GetAspectInstances(targetElement) ?? new IAspectInstance[0];


      var aspect = (AuthorizationAspect) aspects.Select(i => i.Aspect).SingleOrDefault(i => i is AuthorizationAspect);

      if (aspect == null)
      {
        if (targetElement is MethodBase)
          aspect = new MethodAuthorizationAspect();
        else if (targetElement is PropertyInfo || targetElement is FieldInfo)
          aspect = new LocationAuthorizationAspect();
        else if (targetElement is ParameterInfo)
{'fraction_non_alphanumeric': 0.09102466310704296, 'fraction_numerical': 0.0005085176709890668, 'mean_word_length': 3.8151774785801713, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263279', 'n_tokens_mistral': 992, 'n_tokens_neox': 977, 'n_words': 317}