I am looking for an approach for finding the code between the base class identifier colon and the opening curly brace of a class that's been that's been stored into a string literal.
By this I mean that I have a class
public class Class : BaseClass
{
}
That's been stored as a string
string classString = "public class Class : BaseClass{}\r\n"
The class will most certainly be more detailed with the potential for strongly-typed, fully qualified base class and interfaces, but I need an approach for sniffing out the code between the colon and opening curly bracket.
Assuming that the class is not a generic that defines derivation constraint i.e.
public class LinkedList<K,T> : BaseClass
**where K : IComparable**
{
}
Then it might be safe to assume that there would on be one colon in the class definition and it would fairly easy to find the derivation colon and the opening curly brace.
If that's the case I could do
string baseClassString = classString.Substring(derivationColonIndex + 1, (openCurlyBraceIndex - (derivationColonIndex + 1)))
Can anyone think of a better approach that would GUARANTEE the I get a string for the baseClass and any interfaces that might exist between the colon and opening curly brace.
Background for why I'm needing this : Classes are being generated base on data coming from a database, if the certain data in the db changes, then potentially, I have the need to change the inheritance in the class string. Thus, I would replace the existing substring of the base class and interfaces.