Compile code if a specific script exists

Hello everyone

I was wondering if there is a solution to this…
Let’s say, I have a ScriptA which checks if ScriptB exists in the project and then ScriptA creates a new ScriptB(), otherwise it doesn’t try to create it, so the compiler doesn’t throw an error that “The type or namespace name `ScriptB’ could not be found.”
I got to the point to check if ScriptB exists in the project, like so:

System.Type myType = System.Type.GetType("ScriptB");
if (myTpe) print("ScriptB not found"); else ScriptB scriptB;

But the second line obviously throws a compiler error, if ScriptB doesn’t exist. How can I solve this to compile in absence of ScriptB?

Thanks in advance!

using System.Linq;

void DoCheck(){
var o = (from assembly in System.AppDomain.CurrentDomain.GetAssemblies()
    		            from type in assembly.GetTypes ()
    		            where type.Name == "YourClassName"
    		            select type).FirstOrDefault ();
    
    		if(o != null){
    			Debug.Log (o);
    		}else{
    			Debug.Log ("Nope");
    		}
}