locked
Load embedded resource file to access comments RRS feed

  • Question

  • Hello

    We wanted to programmatically access the "Comment" section used in the resource file editor of visual Studio. There is a sample here http://msdn.microsoft.com/en-us/library/system.resources.resxdatanode.asp using the ResXResourceReader. In contrast to this sample I have not a file on the harddisk but an embedded resource file (Resx file with "Build" property set to "Embedded Resource").

    With an embedded resource the sample does not work and

    > IDictionaryEnumerator dict = rr.GetEnumerator();

    throws an exception because it is confronted with binary data

    So I tried to extract the resx file first and look at it. I found so far no way to access the file as XML. The data I get contains the strings of the resource file but looks like a binary (compiled) file.

    And I also found no working sample to gain access to the comment section using ResourceManager class. Everyone seems to be satisfied with Key/Value collections (at least this is the dominant theme in discussions I found on the web) omitting access to the comment section.

    I would be happy with a solution which extracts first the decoded XML out of the embedded resource file and parse that xml. If there is a simpler version using an already defined class with a "Comment" property I would be happy too

    Help would be appreciated.

    Thanks


    Monday, April 15, 2013 9:19 AM

Answers

  • "The data I get contains the strings of the resource file but looks like a binary (compiled) file."

    Well, it IS a binary file.

    "And I also found no working sample to gain access to the comment section using ResourceManager class. Everyone seems to be satisfied with Key/Value collections (at least this is the dominant theme in discussions I found on the web) omitting access to the comment section."

    Because the whole purpose of resources is to store key value pairs. Comments are a source code thing and you cannot extract comments from resources much like you cannot get C# comments from a compiled dll by using reflection. The comments are removed during compilation.

    • Marked as answer by zuiopl Monday, April 15, 2013 10:30 AM
    Monday, April 15, 2013 9:41 AM

All replies

  • "The data I get contains the strings of the resource file but looks like a binary (compiled) file."

    Well, it IS a binary file.

    "And I also found no working sample to gain access to the comment section using ResourceManager class. Everyone seems to be satisfied with Key/Value collections (at least this is the dominant theme in discussions I found on the web) omitting access to the comment section."

    Because the whole purpose of resources is to store key value pairs. Comments are a source code thing and you cannot extract comments from resources much like you cannot get C# comments from a compiled dll by using reflection. The comments are removed during compilation.

    • Marked as answer by zuiopl Monday, April 15, 2013 10:30 AM
    Monday, April 15, 2013 9:41 AM
  • Thanks for the clarifications. Sounds like I need another concept....;-)

    Thanks


    • Edited by zuiopl Monday, April 15, 2013 10:31 AM
    Monday, April 15, 2013 10:30 AM