none
How can i programmatically get AssemblyQualifiedName of specified version of type (ex. System.Drawing.Bitmap) RRS feed

  • Question

  • I'm not so sure where i should post my question, if it's not rigth place to post it, please move it the right place. Thanks.

    We have a very special application, we developed a wizard that can help our customer to generate a skeleton of program. The traget Framework version of generated program will be changed according to the selection in the New Project Dialog of Visual Studio 2010 (As we know we can select Framework version in the New Project Dialog before we run any template). Our wizard is developed with Framework 4.0, in our wizard we allow our customers to add any Icons or Images into the project that is going to be generated. From customer's point of view they only need to select rigth Icons or Images, but behind the scene we have to create a Resources folder in project and add these selected Icons or Images in to project (under Resources folder), more than that we also have to write these Icons or Images information into Resources.resx. No only we have to write these information but also we have to write AssemblyQualifiedName of the types (System.Drawing.Icon or System.Drawing.Image) that represents these Icons or Images, we use Type.AssemblyQualifiedName to get the AssemblyQualifiedName, because our wizard uses Framework 4.0, so alway get Version 4.0.0.0 of System.Drawing.Icon or System.Drawing.Image. But our customer might choose Framework 3.5 as the traget Framework of generated project, then they will get compile error. So I 'm wondering if there is anyway we can get specified version of System.Drwaing.Icon's AssemblyQualifiedName no matter what Framework version of current process running on?

    Thanks.

    Saturday, January 14, 2012 2:12 AM

Answers

  • > we developed a wizard that can help our customer to generate a skeleton of program [...] in our wizard we allow our customers to add any Icons or Images into the project [...] our customer might choose Framework 3.5
     
     
    if i understood correctly you can provider the compiler version via the CSharpCodeProvider Constructor or CodeDomProvider.CreateProvider
     
    var options = new Dictionary<string, string>() { { "CompilerVersion", "v2.0" } };
    var p = CodeDomProvider.CreateProvider("CSharp", options);
    


    also you can embed resources. take a look at the CompilerParameters.EmbeddedResources Property
     
     
    • Edited by Malobukv Sunday, January 15, 2012 6:07 PM
    • Marked as answer by Paul Zhou Monday, January 23, 2012 8:18 AM
    Sunday, January 15, 2012 6:04 PM

All replies

  • > we developed a wizard that can help our customer to generate a skeleton of program [...] in our wizard we allow our customers to add any Icons or Images into the project [...] our customer might choose Framework 3.5
     
     
    if i understood correctly you can provider the compiler version via the CSharpCodeProvider Constructor or CodeDomProvider.CreateProvider
     
    var options = new Dictionary<string, string>() { { "CompilerVersion", "v2.0" } };
    var p = CodeDomProvider.CreateProvider("CSharp", options);
    


    also you can embed resources. take a look at the CompilerParameters.EmbeddedResources Property
     
     
    • Edited by Malobukv Sunday, January 15, 2012 6:07 PM
    • Marked as answer by Paul Zhou Monday, January 23, 2012 8:18 AM
    Sunday, January 15, 2012 6:04 PM
  • Hi,

    You can use the method as shown below:

    private static string GetAssemblyQualifiedName(string asmName)
            {
                string retVal = "";
                if (!string.IsNullOrEmpty(asmName))
                {
                    Type type = Type.GetType(asmName);
                    if (type != null)
                        retVal = type.FullName;
                }
                return retVal;
            }
    

    And call it that  method as

     string s = GetAssemblyQualifiedName("System.Int32");
    



     


    Kiran Saravade [MCP,MCTS]
    Monday, January 16, 2012 8:17 AM