How do I toss. Net resx resource files? When there are enough resources in the computer, we should learn to borrow as much as possible.

Source: Internet
Author: User
Tags reflector

Resource files in. Net resx format are widely used in daily development. They are used to store common resources, such as bitmaps, text files, and any computer files. Let's take a look at its daily usage.

Paste a bitmap file directly here, and thenProgramCalling in this way is very concise and clear

Bitmap bitmap = resources. Button;

Before Knowing this method, I always use the embedded resource method,CodeAs follows:

 
Public StaticSystem. Drawing. Image getimage (StringFilename ){StringPath =String. Format ("Foundation. Common. Resource. _ {0}. {1 }", _ Language, filename); Assembly = assembly. getexecutingassembly (); stream picture = assembly. getmanifestresourcestream (PATH );ReturnImage. fromstream (picture);} Bitmap bitmap = getimage ("Button");

The previous method is simple, but not flexible. Embedded resources can be accessed by programming, which is quite flexible. For example, in a program that creates a multi-language environment, the zh_cn_button file must be loaded in simplified Chinese, and the en_us_button resource file must be loaded in English. In this case, we recommend that you use embedded resources.

When designing a Windows Forms component, you usually assign it an icon resource, and the code looks like this

[Toolboxbitmap (Typeof(Mycontrol ),"Button")]Public ClassMybuttoncontrol: Control {}

The specified resource file name is a button. Set the attribute to an embedded resource. In this way, in the vs toolbox, the icon is displayed as a button.

The code of the control toolbox is more concise, as shown below:

 
[Toolboxbitmap (Typeof(System. Windows. Forms. Button)]Public ClassMycontrol: Control {}

Using the built-in icons of windows. forms is simple and clear, but it drives me to use reflector to see what it actually does.

You may be wondering what kind of icons can be assigned to Windows controls and what rules should be met. As shown in, open the system.windows.forms.dll icon and click "butbutton.bmp". In Photoshop, you can view its attributes to find the answer.

After such a round, I also had a strong interest in the resources embedded into the. NET assembly. Continue to look at my practices.

Let's take a look at this figure. It shows the translation resource string in the Assembly.

Formal business procedures, its standardization is very good, so I want to borrow its string resources, but directly in. net reflector cannot be obtained, but can be saved. resources file .. When the author of net refector created it, he thought of processing the. Resources format. Therefore, it has completed. Net resourcer to read and write resource files in. Resources format, as shown in.

The. NET Framework has been updated in several versions, and the. NET resourcer that was originally saved on the hard disk is no longer running. However,. Net resourcer is enabled.Source codeYou can obtain its code and use Visual Studio to re-open and generate the code once, so that no runtime error will occur.

Using this program to edit the. resx file is quite comfortable. Green, small, and functional enough. However, after a period of time, I found a weakness, that is, the image resources in. resources cannot be saved locally. This is a small defect.

As shown in, I want to copy the image indicated by rejected_request_16, but I cannot find a solution. So I found this method again.

This is a program provided by a garden friend of the blog Park. resource file. in this way, open the converted. resx file. You can save the image file as a file to extract the image file. The code for converting the resource file format is also relatively simple. It is directly called by the API (resourcereader, resxresourcewriter ). ItsArticleThe name is "detailed explanation of how to decompile winform resource files". The author is Chen Guoli. Thank you for your work.

Try the open source code ilspy. It can only save the embedded resource file. resource, which is not the resx file I need.

Visual Studio command line has a utility that can directly convert the. Resource file to the resx format. The command is as follows:

Resgen.exe ERP. Resources ERP. resx

In this way, the. Resources format is also converted to the resx file format.

 

After mastering the skills mentioned above, it is equivalent to preparing a tool to mine the treasure. below, I will train my hands to see the baby resources that can be mined.

Code Smith has always been my favorite code generation tool, and I often make some extension applications on it. It does not rely on our familiar SMO or DMO to obtain the database's metadatabase. I have been skeptical about this, so I opened it with reflector, and the secrets are all here.

 
 

This figure also explains a lot of SQL Server metadata techniques. For example, if you want to obtain all the data tables of SQL Server 2005, you can see that the code written by code Smith is as follows:

Gettables2005 = select

Object_name (so. ID) as [object_name],

Schema_name (so. UID) as [user_name],

So. type as type,

So. crdate as date_created,

FG. file_group as file_group,

So. ID as [object_id]

From

DBO. sysobjects so

Left join (

Select

S. groupname as file_group,

I. ID as ID

From DBO. sysfilegroups s

Inner join DBO. sysindexes I

On I. groupid = S. groupid

Where I. indid <2
) As FG

On so. ID = FG. ID

Where

So. type = n'u'

And permissions (so. ID) & 4096 <> 0

And objectproperty (so. ID, n' ismsshipped ') = 0

And not exists (select * From SYS. extended_properties where major_id = So. ID and name = 'Microsoft _ database_tools_support 'and value = 1)

Order by Schema_name (so. UID), object_name (so. ID)

In this way, I no longer have to worry about getting SQL Server metadata, or Google's help. Here I need everything.

The corresponding MySQL can be found in schemaexplorer. mysqlschemaprovider. dll, and Oracle-related MySQL can be found in schemaexplorer. oracleschemaprovider. dll.

 

In addition to the method of getting resources, I also observed another method of programming. See

Solid framework is a popular PDF File Processing toolkit. I used to introduce how to program PDF Format documents in the data solution development diary 14th of the knowledge management system. For more information, see this article.

This section briefly describes how the framework works, as shown in. It compresses all programs and execution files to the solidframework. in the resource file of the DLL Assembly, after activating the (activate) PDF Processing Engine, it will decompress the relevant execution file and service program to a directory, then process the PDF document with the program in this directory. This strange method of using resource files has always surprised me and admired others. It has brought the use of resource files to the extreme.

 

There was a saying of stealing food on the QQ Farm. Someone later called it "pick up food", not "steal". I also learned how to use it as a civilized person. I hope it will help you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.