Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition phần 5

Như vậy, cho rằng cấu trúc Point đã quá tải và các nhà khai thác, bạn có thể viết như sau: / / các nhà khai thác quá tải nhị phân kết quả trong một nhà điều hành viết tắt tiện ích miễn phí. | Simpo PDF Merge and Split Unregistered Version - http 532 CHAPTER 16 TYPE REFLECTION LATE BINDING AND ATTRIBUTE-BASED PROGRAMMING Displaying Various Odds and Ends Last but not least you have one final helper method that will simply display various statistics indicating whether the type is generic what the base class is whether the type is sealed and so forth regarding the incoming type Just for good measure. static void ListVariousStats Type t Various Statistics Base class is 0 Is type abstract 0 Is type sealed 0 Is type generic 0 Is type a class type 0 Implementing Main The Main method of the Program class prompts the user for the fully qualified name of a type. Once you obtain this string data you pass it into the method and send the extracted into each of your helper methods. This process repeats until the user enters Q to terminate the application static void Main string args Welcome to MyTypeViewer string typeName bool userIsDone false do nEnter a type name to evaluate or enter Q to quit Get name of type. typeName Does user want to quit if Q userIsDone true break Try to display type. try Type t typeName ListVariousStats t Simpo PDF Merge and Split Unregistered Version - http CHAPTER 16 TYPE REFLECTION LATE BINDING AND ATTRIBUTE-BASED PROGRAMMING 533 ListFields t ListProps t ListMethods t ListInterfaces t catch Sorry can t find type while userIsDone At this point is ready to take out for a test drive. For example run your application and enter the following fully qualified names be aware that the manner in which you invoked requires case-sensitive .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
157    81    1    22-05-2024
11    434    1    22-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.