日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Reflection,Regular Expression,Threading,IO,AppDomain,Web Service/Remoting Service,ORM

發布時間:2025/5/22 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Reflection,Regular Expression,Threading,IO,AppDomain,Web Service/Remoting Service,ORM 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Reflection,Regular Expression,Threading,IO,AppDomain,Web Service/Remoting Service,ORM
先開個頭,慢慢完善!

Reflection allows you to programmatically inspect and get information about an assembly, including all object types contained within it. This information includes the attributes you have added to those types. The reflection objects reside within the System.Reflection namespace.

In addition to reading the types defined within a given assembly, you can also generate (emit) your own assemblies and types using the services of System.Reflection.Emit or System.CodeDom. This topic is a little too hectic for a beginning book on C#, but if you are interested, then MSDN contains some information on emitting dynamic assemblies.

The first example in this section inspects an assembly and displays a list of all attributes defined on the assembly — this should produce a list similar to that shown earlier.

Note

In this chapter, I'm going to be a bit more relaxed about the format of the code examples, since if you've gotten to this point in the book you must be pretty confident of what you're doing! All of the code can be found in the Chapter27 folder of the code download — some examples in this chapter might show you only the most important parts of the code, so don't forget to look through the downloaded code to see the whole picture.

This first example can be found in the Chapter27\FindAttributes directory. The entire source file is reproduced here:

// Import types from the System and System. assemblies using System; using System.;namespace FindAttributes { class Program { /// <summary> /// Main .exe entry point /// </summary> /// <param name="args">Command line args - the name of an assembly</param> static void Main(string[] args) { // Output usage information if necessary. if (args.Length == 0) Usage(); else if ((args.Length == 1) && (args[0] == "/?")) Usage(); else { // Load the assembly. string assemblyName = null;// Loop through the arguments passed to the console application. // I'm doing this as if you // spaces you end up with several arguments - // them back together again to make one filename... foreach (string arg in args) { if (assemblyName == null) assemblyName = arg; else assemblyName = string.Format("{0} {1}", assemblyName, arg); }try { // Attempt to load the named assembly. Assembly a = Assembly.LoadFrom(assemblyName);// Now find the attributes on the assembly. // The parameter is ignored, so I chose true. object[] attributes = a.GetCustomAttributes(true);// If there were any attributes defined... if (attributes.Length > 0) { Console.WriteLine("Assembly attributes for assemblyName);// Dump them out... foreach (object o in attributes) Console.WriteLine(" {0}", o.ToString()); } else Console.WriteLine("Assembly {0} contains no Attributes.", assemblyName); } catch (Exception ex) { Console.WriteLine("Exception thrown loading assembly {0}...", assemblyName); Console.WriteLine(); Console.WriteLine(ex.ToString()); } } }/// <summary> /// Display usage information for the .exe. /// </summary> static void Usage() { Console.WriteLine("Usage:"); Console.WriteLine(" FindAttributes <Assembly>"); } } }

Now, build the executable in Visual Studio 2005, or if you prefer use the command-line compiler:

>csc FindAttributes.cs

This will compile the file and produce a console executable, which you can then call.

To run the FindAttributes application, you need to supply the name of an assembly to inspect. For now, you can use the FindAttributes.exe assembly itself, which is shown in Figure 27-3.


Figure 27-3

The example code first checks the parameters passed to the command line — if none are supplied, or if the user types FindAttributes /? then the Usage() method will be called, which will display a simple command usage summary:

if (args.Length == 0) Usage (); else if ((args.Length == 1) && (args[0] == "/?")) Usage ();

Next, reconstitute the command-line arguments into a single string. The reason for this is that it's common to have spaces in directory names, such as Program Files, and the space would cause it to be considered as two arguments. So, iterate through all the arguments, stitching them back into a single string, and use this as the name of the assembly to load:

foreach (string arg in args) { if (assemblyName == null) assemblyName = arg; else assemblyName = string.Format ("{0} {1}" , assemblyName , arg); }

Then attempt to load the assembly and retrieve all custom attributes defined on that assembly with the GetCustomAttributes() method:

Assembly a = Assembly.LoadFrom (assemblyName); // Now find the attributes on the assembly. object[] attributes = a.GetCustomAttributes(true);

Any attributes found are output to the console. When you tested the program against the FindAttributes.exe file, an attribute called DebuggableAttribute was displayed. Although you have not specified the DebuggableAttribute, it has been added by the C# compiler, and you will find that most of your executables have this attribute.

轉載于:https://www.cnblogs.com/microci/archive/2008/04/07/1141131.html

總結

以上是生活随笔為你收集整理的Reflection,Regular Expression,Threading,IO,AppDomain,Web Service/Remoting Service,ORM的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。