Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CustomAttribute.cs
Go to the documentation of this file.
2
4
5public readonly struct CustomAttribute
6{
7 private readonly MetadataReader _reader;
8
9 private readonly uint _treatmentAndRowId;
10
11 private int RowId => (int)(_treatmentAndRowId & 0xFFFFFF);
12
14
16
18
20
22 {
23 get
24 {
25 if (Treatment == MethodDefTreatment.None)
26 {
28 }
29 return GetProjectedValue();
30 }
31 }
32
33 internal CustomAttribute(MetadataReader reader, uint treatmentAndRowId)
34 {
35 _reader = reader;
36 _treatmentAndRowId = treatmentAndRowId;
37 }
38
43
45 {
47 if (customAttributeValueTreatment == CustomAttributeValueTreatment.None)
48 {
50 }
51 return GetProjectedValue(customAttributeValueTreatment);
52 }
53
55 {
56 BlobHandle.VirtualIndex virtualIndex;
57 bool flag;
58 switch (treatment)
59 {
60 case CustomAttributeValueTreatment.AttributeUsageVersionAttribute:
61 case CustomAttributeValueTreatment.AttributeUsageDeprecatedAttribute:
62 virtualIndex = BlobHandle.VirtualIndex.AttributeUsage_AllowMultiple;
63 flag = true;
64 break;
65 case CustomAttributeValueTreatment.AttributeUsageAllowMultiple:
66 virtualIndex = BlobHandle.VirtualIndex.AttributeUsage_AllowMultiple;
67 flag = false;
68 break;
69 case CustomAttributeValueTreatment.AttributeUsageAllowSingle:
70 virtualIndex = BlobHandle.VirtualIndex.AttributeUsage_AllowSingle;
71 flag = false;
72 break;
73 default:
74 return default(BlobHandle);
75 }
78 if (blobReader.Length != 8)
79 {
80 return value;
81 }
82 if (blobReader.ReadInt16() != 1)
83 {
84 return value;
85 }
86 AttributeTargets attributeTargets = ProjectAttributeTargetValue(blobReader.ReadUInt32());
87 if (flag)
88 {
89 attributeTargets |= AttributeTargets.Constructor | AttributeTargets.Property;
90 }
91 return BlobHandle.FromVirtualIndex(virtualIndex, (ushort)attributeTargets);
92 }
93
94 private static AttributeTargets ProjectAttributeTargetValue(uint rawValue)
95 {
96 if (rawValue == uint.MaxValue)
97 {
98 return AttributeTargets.All;
99 }
100 AttributeTargets attributeTargets = (AttributeTargets)0;
101 if ((rawValue & (true ? 1u : 0u)) != 0)
102 {
103 attributeTargets |= AttributeTargets.Delegate;
104 }
105 if ((rawValue & 2u) != 0)
106 {
107 attributeTargets |= AttributeTargets.Enum;
108 }
109 if ((rawValue & 4u) != 0)
110 {
111 attributeTargets |= AttributeTargets.Event;
112 }
113 if ((rawValue & 8u) != 0)
114 {
115 attributeTargets |= AttributeTargets.Field;
116 }
117 if ((rawValue & 0x10u) != 0)
118 {
119 attributeTargets |= AttributeTargets.Interface;
120 }
121 if ((rawValue & 0x40u) != 0)
122 {
123 attributeTargets |= AttributeTargets.Method;
124 }
125 if ((rawValue & 0x80u) != 0)
126 {
127 attributeTargets |= AttributeTargets.Parameter;
128 }
129 if ((rawValue & 0x100u) != 0)
130 {
131 attributeTargets |= AttributeTargets.Property;
132 }
133 if ((rawValue & 0x200u) != 0)
134 {
135 attributeTargets |= AttributeTargets.Class;
136 }
137 if ((rawValue & 0x400u) != 0)
138 {
139 attributeTargets |= AttributeTargets.Struct;
140 }
141 return attributeTargets;
142 }
143}
CustomAttributeTableReader CustomAttributeTable
BlobReader GetBlobReader(BlobHandle handle)
CustomAttributeValueTreatment CalculateCustomAttributeValueTreatment(CustomAttributeHandle handle)
static BlobHandle FromVirtualIndex(VirtualIndex virtualIndex, ushort virtualValue)
Definition BlobHandle.cs:39
static CustomAttributeHandle FromRowId(int rowId)
CustomAttribute(MetadataReader reader, uint treatmentAndRowId)
static AttributeTargets ProjectAttributeTargetValue(uint rawValue)
BlobHandle GetProjectedValue(CustomAttributeValueTreatment treatment)
CustomAttributeValue< TType > DecodeValue< TType >(ICustomAttributeTypeProvider< TType > provider)
CustomAttributeValue< TType > DecodeValue(EntityHandle constructor, BlobHandle value)