Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

problem with interface conversion .. help please

$
0
0
summary

I'm trying to retrive a type from the assembly ( the playertype parameter is an enum which has names of the types the user can choose from) the type.tostring is called to store the value of the enum as a string(which is the name of the type in string) this string (playertype name) which holds the type name is passed to the GetAssembly() to return the assembly this type is in. I then call the createinstance() method and pass in the name in the type which returns an object and then cast the object to a IplayerType interface. The method should return an Iplayer interface. all the types in the assembly implements the iplayertype interface.

problem

the result of this code is that its returning a null, when I wanted it to return an Iplayer, as all the type in my assembly implement this interface.

I trying o solve this for hours, would preciate any help.

any ideas?


   public IplayerType GetPlayerType(playerType type)
        {
            string playerTypeName = type.ToString();

            
            return Assembly.GetAssembly(type.GetType()).CreateInstance(playerTypeName) as IplayerType;            
                   

        }



thanks in advance

ray

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>