Adam's Lair Forum

game development and casual madness
It is currently 2018/07/17, 07:27

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: 2017/08/29, 16:22 
Junior Member
Junior Member

Joined: 2016/01/09, 22:52
Posts: 35
Role: Hobbyist
I will change Wire to iterate over loaded assemblies. I looked in my Plugins folder, there was a copy of Duality as well as a few other .dll's that are also in the main duality folder, I removed those files. I do not know how that would have happened. Thanks for your help Adam and SirePi!


Top
 Profile  
 
PostPosted: 2017/08/30, 07:02 
Junior Member
Junior Member

Joined: 2016/01/09, 22:52
Posts: 35
Role: Hobbyist
I changed Wire to accept a function to resolve Types from type names then changed all usages of Type.GetType to use that. In my Duality project I passed a function which mostly wraps Duality's ResolveType method. Duality was unable to find the type. After some digging I noticed the type was being passed as a sort of partially qualified type name, like the following.
Code:
"DualitySync.Synchronization.SceneChangeInfo, GamePlugin.core"
I guess Type.GetType can parse a type name like this but Duality's type resolver only works with the FullName of a type.

I tried Type.GetType within my Duality plugin and it worked! Maybe it doesn't load an assembly if it is called from inside the right assembly? I am not sure. This might work for now and I could continue work on my project from here but it is not a good solution.

I would like to parse out the FullName from this string and then pass that to Duality but I am not sure how, the type name syntax is very complicated. I will probably look around to see if I can find a way of parsing out the information I need.

Any ideas would be appreciated but this post is mostly just to let interested people know where I have gotten with this problem.


Top
 Profile  
 
PostPosted: 2017/08/30, 08:04 
Junior Member
Junior Member

Joined: 2016/01/09, 22:52
Posts: 35
Role: Hobbyist
I have made some progress, sort of. I wrote the following function to find the FullName from the strange type name Wire was giving me.
Code:
private static string GetFullTypeName(string name)
        {
            int bCount = 0;
            int index = -1;
            for(int i = 0; i < name.Length; i++)
            {
                if(name[i] == '[')
                {
                    bCount++;
                }
                else if(name[i] == ']')
                {
                    bCount--;
                }
                else if(bCount == 0 && name[i] == ',')
                {
                    index = i;
                    break;
                }
            }
            if(index == -1)
            {
                return name;
            }
            else
            {
                return name.Substring(0, index).Trim();
            }
        }

This helped when deserializing the type in question, SceneChangeInfo. Unfortunately serializing a List<SceneChangeInfo> would break the parsing as SceneChangeInfo would be a generic argument of the List. I tried making Wire return a fully qualified type name but Duality's type reflection couldn't figure that out. Probably a combination of parsing out the generic parameters and Assembly.GetType not working with fully qualified types.

I am not sure where to go from here, maybe just remove assembly information from Wire's serialization process so it will work with Duality's parsing? I could also try making a more flexible parser and remove the assembly information on my end. The following code might also work for most scenarios.
Code:
var type = Duality.ReflectionHelper.ResolveType(name) ??
                        Duality.ReflectionHelper.ResolveType(GetFullTypeName(name)) ??
                        Type.GetType(name, throwError);

I think I will probably go with that code segment for now and come back to this later. Type.GetType seems to work without loading assemblies when I call it from my code, it even worked with a type defined by Duality.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group