I have found myself countless times reorganizing our solution (72 + projects), in efforts to reduce code. A lot of times it involves pulling out common types/libraries and moving them around.
It always involves a reptitive compiler error so i am having to fix the same compiler error in a lot of different places. I am looking for a guide to the VS api so i can do some code generation/automated fixing.
Even if you dont have the exact solution, can you please point me to where i should look? Is there a compiler api? refactor api? Any suggestions on how i can do either one?
Use Cases:
So first question (easiest of the two):
Automated fixing when i move a file from one project to another. This process would be to find the error
"The type or namespace name 'MovedClass' could not be found.
Then remove the old namespace, add the new, and add the project reference.
Case Two... refactoring to a pattern.
Example:
Original Base VO Class:
public class BaseVO{
public AuditInfo { get;set;}
}
public class BaseKey{
}
All of our Business Objects(each in individual class).
public class ExampleBusinessVO : BaseVO{
public AuditInfo { get;set;}
public ExampleBusinessKey BusinessKey { get;set;}
}
public class ExampleBusinessKey{
}
Now assume we want to add an explicit link between BaseVO and Base Key, and force all to implement Equals/HashCode
New Base VO Class:
public abstract class BaseVO<TKey>{
TKey BusinessKey{get;set;}
public abstract override bool Equals(object obj);
public abstract override int GetHashCode();
}
public class BaseKey{
}
All then i must cascade these changes to all VOs. (ouch )
//Add generic
public class ExampleBusinessVO : BaseVO<ExampleBusinessKey>{
//Remove old business key
//Implement methods
public override bool Equals(object obj){
}
}
public class ExampleBusinessKey: BaseKey{
}
Now i recognize i can't fix all of the errors, but it would be nice to be able to write something to check a class for the compile errors. Then i could develop a pragmatic solution:
For each of the VOs if error: "Using the generic type ... requires 1 type argument", then read the class file and find the class that implements BaseKey, and then add it to the template method.
Please note i am looking for an automated solution not a refactoring tool