MonoBehaviour using the 'new' keyword

How can I disable this warning in my code?

You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all

I know the reason for this message, but I just need to access the property
public override System.Type Type => typeof(Sprite);

I have the path to the script file and I can read it as text and find the type name, but this solution will be more cumbersome.

After reading some of the comments you added , i think (correct me if i’m wrong) but pretty much you have a MyMonoBehaviour that exposes a Type getter that’s pretty much metadata bound to the MyMonoBehaviour type , and somewhere in your code you’re need to get access to the metadata so you call new MyMonoBehavior().Type to get the type.

I think that approach is wrong for many reasons, but i do get the utility.
One way you can do this is to have a “Storage” class where you bake all your data on startup or editor time once , then you’ll be able to access it later.

For stuff like this i like using custom attributes since i find them perfect for type decoration and “type-data-association” kinda things, and also for how flexible they are, something like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

public class TypeMetadata : Attribute
{
    public Type Type { get; private set; }
    public TypeMetadata(Type type)
    {
        this.Type = type;
    }
}
    
public static class MetadataProvider<T>
{
    private static Type type;
    public static Type Get()
    {
        return type;
    }
}
    
// for example, this can be the type that you wanna associate the "string" type with
[TypeMetadata(typeof(string))]
public class MyClass {}

public class Program 
{   
    private static void InitializeMetadata()
    {
        Type genericType = typeof(MetadataProvider<>);
        List<Tuple<Type,Type>> typeAndMetadataPairs = Assembly
            .GetAssembly(typeof(MyClass))
            .GetTypes()
            .Where( t => t.GetCustomAttribute<TypeMetadata>() != null)
            .Select( t => new Tuple<Type,Type>(t , t.GetCustomAttribute<TypeMetadata>().Type))
            .ToList();
        
        
        foreach( var t in typeAndMetadataPairs)
        {
            Type constructGenericType = genericType.MakeGenericType(t.Item1);
            FieldInfo f = constructGenericType.GetField( "type" , BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy );
            f.SetValue(null , t.Item2);
        }
    }
    static void Main(string[] args)
    {
        // call this at whatever you consider "startup" in your application/program
        InitializeMetadata();
        
        // test to see if it works
        Console.WriteLine($"Type : {typeof(MyClass)} - MetadataType : {MetadataProvider<MyClass>.Get().Name}");
    }
}