ImplicitUseKindFlags.Assign question

I am using MVC with Autofac to do dependency injection into Controller properties. Eg,

   public class MyController : Controller {
      public IInjected Injected { get; set; }


      public ActionResult Index() {
         return View(Injected.GetSomething());
      }
   }
               




By default Reshaper warns that "Auto-implemented propery accessor is never used".

I have fixed this by creating an attribute as:

   [MeansImplicitUse(ImplicitUseKindFlags.Assign, ImplicitUseTargetFlags.WithMembers)]
   public class IsMvcControllerAttribute : Attribute { }

which also flags that the Index method is used...



However, ImplicitUseKindFlags.Assign seems to also flag that the property is also accessed, which means when I have this:

   [IsMvcController]
   public class MyController : Controller {
      public IInjected Injected { get; set; }
      public IAnother NotActuallyUsed { get; set; }


      public ActionResult Index() {
         return View(Injected.GetSomething());
      }
   }



I don't get a warning that "NotActuallyUsed" isn't used, as the ImplicitUse attribute seems to be flagging it as Assign and Access.

Is there any way to create the attribute so that I will get a warning for "NotActuallyUsed" but "Injected" will not?
1 comment

Hello Steven,

The only way is to apply the attribute separately for each property separately:


public IsMvcControllerProperty : Attribute {}

public class MyController : Controller {
     
      public IInjected Injected { get; set; }

      public IAnother NotActuallyUsed { get; set; }

      public ActionResult Index() {
         return View(Injected.GetSomething());
      }
   }

Thank you!


Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I am using MVC with Autofac to do dependency injection into Controller
properties. Eg,
public class MyController : Controller {
public IInjected Injected { get; set; }
public ActionResult Index() {
return View(Injected.GetSomething());
}
}
By default Reshaper warns that "Auto-implemented propery accessor is
never used".

I have fixed this by creating an attribute as:
[MeansImplicitUse(ImplicitUseKindFlags.Assign,
ImplicitUseTargetFlags.WithMembers)]
public class IsMvcControllerAttribute : Attribute { }
which also flags that the Index method is used...

However, ImplicitUseKindFlags.Assign seems to also flag that the
property is also accessed, which means when I have this:

public class MyController : Controller {
public IInjected Injected { get; set; }
public IAnother NotActuallyUsed { get; set; }
public ActionResult Index() {
return View(Injected.GetSomething());
}
}
I don't get a warning that "NotActuallyUsed" isn't used, as the
ImplicitUse attribute seems to be flagging it as Assign and Access.

Is there any way to create the attribute so that I will get a warning
for "NotActuallyUsed" but "Injected" will not?

---
Original message URL:
http://devnet.jetbrains.net/message/5297906#5297906



0

Please sign in to leave a comment.