ispiro
ispiro

Reputation: 27703

How to extract a method to a separate class

I have a method which accesses many fields, so it’s hard coded into its class. I would like to make it reusable by other classes.

Is there any way of getting a list of all fields and methods (within the same class) that a method accesses?

I’m using VS2010.

Upvotes: 0

Views: 234

Answers (2)

UnhandledExcepSean
UnhandledExcepSean

Reputation: 12804

The Reflection namespace can do just about anything you'd need in this regard. Specifically, I think you'll want to check out System.Reflection.PropertyInfo and System.Reflection.MemberInfo.

Upvotes: 0

user405725
user405725

Reputation:

Sure, take that method out of the class and put it into an empty class and try to compile. Compiler will complain about a list of fields that this method wants to access but could not find.

Upvotes: 1

Related Questions