Attributes and Reflection

Attributes are a simple technique for adding metadata information and behavior to code within applications. You use the reflection technique to pick the attribute related information at runtime. This chapter introduces attributes and reflection and the functions they perform in C# applications. This chapter discusses attribute syntax, and how to use some of the predefined attributes. This chapter discusses also discusses how to create customized user-defined attributes. In addition, this chapter discusses reflection and how to use it to extract attribute related information. . | Attributes and Reflection Chapter 13 Attributes are a simple technique for adding metadata information and behavior to code within applications. You use the reflection technique to pick the attribute related information at runtime. This chapter introduces attributes and reflection and the functions they perform in C applications. This chapter discusses attribute syntax and how to use some of the predefined attributes. This chapter discusses also discusses how to create customized user-defined attributes. In addition this chapter discusses reflection and how to use it to extract attribute related information. Objectives In this chapter you will learn to fl Describe attributes fl Retrieve metadata using reflection Introducing Attributes An object is described by the values of its attributes. For example a car can be described by its make model or color. Similarly a C program has certain attributes which depict and influence its behavior for example compiler instructions. An attribute is a declarative tag that is used to convey information to runtime about the behavior of programmatic elements such as classes enumerators and assemblies. A declarative tag is depicted by square brackets placed above the definition of an element such as a class or a method. Attributes are used for adding metadata such as compiler instructions and other information such as comments description methods and classes to a program. The .NET Framework is equipped with a number of predefined attributes. The code to examine the predefined attributes and act upon the values they contain is also incorporated as a part of the runtime and .NET Framework Software Development Kit SDK . Applying Attributes Attributes are applied to different elements of the code. These elements include assemblies modules classes structs enums constructors methods properties fields events interfaces parameters return values and delegates. Information about attributes is stored with the metadata of the elements they are .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.