Unused classes

hello all,

I have the feature enabled where Resharper will tell me about unused classes.  the problem I see is that it marks classes as unused even though they may appear as type arguments in generic methods.  This is a particular issue when using IOC containers like Unity where the class is constructed in code.  Is there a way around this or can this be a feature request?

thanks

cliff

4 comments

Hello clifton,

Could you please provide an example? I tried the following and it works as
expected:

public interface IService // not marked as unused
{
}

public static class Factory
{
public static T Create() where T : class { return null; } } public static class Consumer { private static void Consume() { var t = Factory.Create(); } } However, I must admit, IoC and DI and related technologies are not very well supported by ReSharper yet. Sincerely, Ilya Ryzhenkov JetBrains, Inc http://www.jetbrains.com "Develop with pleasure!" cv> hello all, cv> cv> I have the feature enabled where Resharper will tell me about unused cv> classes. the problem I see is that it marks classes as unused even cv> though they may appear as type arguments in generic methods. This cv> is a particular issue when using IOC containers like Unity where the cv> class is constructed in cod cv> cv> e. Is there a way around this or can this be a feature request? cv> cv> thanks cv> cv> cliff cv> cv> --- cv> Original message URL: cv>]]> http://www.jetbrains.net/devnet/message/5241007#5241007


0

Ilya,

your example doesn't show very well, but here's mine:

public interface IFoo
    {
      
    }
    public class Foo:IFoo //marked as never used
    {
      
    }

    public class Bar
    {
        public Foo Create()
        {
            return new Blah().Create<Foo>();
        }
    }
    public class Blah
    {
        private UnityContainer _container=new UnityContainer();
        public Blah()
        {
            _container.RegisterType<IFoo, Foo>();
          
        }
        public  T Create<T>()
        {
            return _container.Resolve<T>(  );
        }
    }

0

Hello clifton,

Do you mean it is never instantiated? Never used and never instantiated are
different warnings. Consider:

class Foo // used, but never instantiated, i.e. never found in "new Foo"
expression.
{
public static void Bar() {}
}

class Zoo
{
void Moo() { Foo.Bar(); }
}

We are currently working on final feature set for ReSharper 5, and we consider
support for IoC/DI.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


cv> Ilya,
cv>
cv> your example doesn't show very well, but here's mine:
cv>
cv> public interface IFoo
cv> {
cv> }
cv> public class Foo:IFoo //marked as never used
cv> {
cv> }
cv>
cv> public class Bar
cv> {
cv> public Foo Create()
cv> {
cv> return new Blah().Create(); cv> } cv> } cv> public class Blah cv> { cv> private UnityContainer _container; cv> public void Init() cv> { cv> _container.RegisterType(); cv> } cv> public T Create() cv> { cv> return _container.Resolve( ); cv> } cv> } cv> --- cv> Original message URL: cv>]]> http://www.jetbrains.net/devnet/message/5241052#5241052


0

I guess it would be "never instantiated".

0

Please sign in to leave a comment.