lundi 16 janvier 2017

How to prevent .net compiler to strip out classes which are considered as unused?

I have an app both on Windows/WindowsPhone and iOS written in c# using xamarin. There are many helper classes for game levels, all descedants of one class, I instantiate them using reflection:

            string className = string.Format(CultureInfo.InvariantCulture, "myapp.helper{0:0000}", num);
            var t = Type.GetType(className);
            if (t != null)
                cmis = Activator.CreateInstance(t);

In Windows version of app it works ok, but in iOS version Type.GetType(className) returns null. If I instantiate object of another class, which is used directly in my app, it returns its type. But the problem is that there are several hundreds of such small classes and they are used only with reflection, so I suppose that xamarin version of .NET compiler strips out my classes even in DEBUG because it thinks they are totally unused.

"Optimize" check is off. Classes are in the same assembly but I tried to use assembly qualified name - no success. Is there a way to add some pragma or something to make compiler act the same way it works in Windows app? I want to keep only my "unused" classes with name template "helperXXXX", other unused may be stripped out.





Aucun commentaire:

Enregistrer un commentaire