C# - Convert String to Class Object

后端 未结 3 1926
野的像风
野的像风 2021-01-19 10:47

I am working with someone else\'s code and trying to make some modifications. So what I\'m needing to do is take the following:

RemoteFileDP remoteFile = ne         


        
3条回答
  •  攒了一身酷
    2021-01-19 11:33

    If you don't wish to modify the source project that RemoteFileDP lives in (or can't) you could write an extension method such as below:

    public static RemoteFileDP ConvertToRemoteFileDP(this string location)
    {
        // Somehow create a RemoteFileDP object with your 
        // location string and return it
    }
    

    That way you could run the line of code you want:

    RemoteFileDP remoteFile = locationDirectory;
    

    With a slight modification as follows:

    RemoteFileDP remoteFile = locationDirectory.ConvertToRemoteFileDP();
    

    Would this allow you to solve your problem?

提交回复
热议问题