【 How to: Create a C/C++ Union by Using Attributes (C#)】
1、you can create what is known as a union in C/C++ by using the StructLayout(LayoutKind.Explicit)
and FieldOffset
attributes.
2、Below t he two integer fields, i1
and i2
, share the same memory locations as lg
. This sort of control over struct layout is useful when using platform invocation.
参考:
【 Accessing Attributes by Using Reflection (C#)】
1、you can define custom attributes and place them in your source code. you can retrieve the information that was defined with custom attributes. The key method is GetCustomAttributes
, which returns an array of objects that are the run-time equivalents of the source code attributes.
The code is not executed until SampleClass
is queried for attributes. Calling GetCustomAttributes
on SampleClass
causes an Author
object to be constructed and initialized as above. If the class has other attributes, other attribute objects are constructed similarly. GetCustomAttributes
then returns the Author
object and any other attribute objectsin an array. You can then iterate overthis array, determine what attributes were applied based on the type of each array element, and extract information from the attribute objects.
2、下面是一个 Attribute 的定义,通过 System.AttributeUsage() 定义这个新 Attribute的用法。
参考:
Original: https://www.cnblogs.com/tekkaman/p/11213138.html
Author: Tekkaman
Title: How to: Create a C/C++ Union by Using Attributes (C#)
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/535814/
转载文章受原作者版权保护。转载请注明原作者出处!