Is there an easy way to refactor a field/property of type T to be a Lazy, and replace all useages of that field to use FieldName.Value instead?
I have a controller with a bunch of dependencies that are stored in private backing fields, but only a few of the dependencies are need on any given function call. In order to speed up construction of this controller, I'd like to make all the dependencies Lazy, but its just an irritating amount of work to do by hand. Any advice?
Tools
> Create GUID
Resharper
> Refactor
> Rename
Foo => Foo_299E4ADB-5770-458C-B030-E40E19B0FFAF
Edit
> Find and Replace
> Replace in Files
_299E4ADB-5770-458C-B030-E40E19B0FFAF => .Value
if previously you had,
public class LazyClass
{
// initialized in constructor etc.
public MyType MyTypeProperty { get; set; }
}
then you can make it lazy loaded, without affecting the callers as follows:
public class LazyClass
{
private Lazy<MyType> myType = new Lazy<MyType>(() => new MyType());
public MyType MyTypeProperty
{
get { return this.myType.Value; }
}
}
i doubt if Resharper has this re-factoring built in. anyways, you don't want all callers to know it is Lazy and refer to it as LazyType.Value
. don't expose the Lazy type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With