FieldAttributes Enumeráció
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Egy mező attribútumait leíró jelzőket ad meg.
Ez a felsorolás támogatja a tagértékek bitenkénti kombinációját.
public enum class FieldAttributes
[System.Flags]
public enum FieldAttributes
[System.Flags]
[System.Serializable]
public enum FieldAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum FieldAttributes
[<System.Flags>]
type FieldAttributes =
[<System.Flags>]
[<System.Serializable>]
type FieldAttributes =
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FieldAttributes =
Public Enum FieldAttributes
- Öröklődés
- Attribútumok
Mezők
| Name | Érték | Description |
|---|---|---|
| PrivateScope | 0 | Azt adja meg, hogy a mezőre nem lehet hivatkozni. |
| Private | 1 | Azt adja meg, hogy a mező csak a szülőtípussal érhető el. |
| FamANDAssem | 2 | Azt adja meg, hogy a mező csak a szerelvény altípusai számára érhető el. |
| Assembly | 3 | Megadja, hogy a mező elérhető legyen az egész szerelvényben. |
| Family | 4 | Azt adja meg, hogy a mező csak típus és altípusok szerint érhető el. |
| FamORAssem | 5 | Azt határozza meg, hogy a mező elérhető legyen altípusokkal bárhol, valamint az egész szerelvényben. |
| Public | 6 | Megadja, hogy a mező elérhető legyen minden olyan tag számára, akinek ez a hatókör látható. |
| FieldAccessMask | 7 | Egy adott mező hozzáférési szintjét adja meg. |
| Static | 16 | Azt adja meg, hogy a mező a megadott típust jelöli,vagy más néven példányonként. |
| InitOnly | 32 | Megadja, hogy a mező csak inicializálva legyen, és csak a konstruktor törzsében állítható be. |
| Literal | 64 | Azt adja meg, hogy a mező értéke fordítási idő (statikus vagy korai kötött) állandó. Minden kísérlet, hogy állítsa be dob egy FieldAccessException. |
| NotSerialized | 128 | Azt határozza meg, hogy a típus távoli használatakor a mezőt nem kell szerializálni. |
| HasFieldRVA | 256 | Megadja, hogy a mező relatív virtuális címmel (RVA) rendelkezik-e. Az RVA a metódus törzsének helye az aktuális képen, mint a képfájl elejéhez viszonyított cím, amelyben található. |
| SpecialName | 512 | Egy speciális metódust ad meg, amelynek neve leírja, hogyan különleges a metódus. |
| RTSpecialName | 1024 | Azt határozza meg, hogy a közös nyelvi futtatókörnyezetnek (metaadatok belső API-ii) ellenőriznie kell a névkódolást. |
| HasFieldMarshal | 4096 | Megadja, hogy a mező rendelkezik-e a marsallálási információkkal. |
| PinvokeImpl | 8192 | Jövőbeli használatra fenntartva. |
| HasDefault | 32768 | Megadja, hogy a mező alapértelmezett értékkel rendelkezik-e. |
| ReservedMask | 38144 | Fenntartott |
Példák
Ebben a példában három mező épül fel, és megjelennek az FieldAttributes értékek. Egy FieldAttributes érték több attribútumot is tartalmazhat, például mindkettőt Public és Literal, ahogy a harmadik mezőben is látható.
using System;
using System.Reflection;
public class Demo
{
// Make three fields:
// The first field is private.
private string m_field = "String A";
// The second field is public.
public string Field = "String B";
// The third field is public const (hence also literal and static),
// with a default value.
public const string FieldC = "String C";
}
public class Myfieldattributes
{
public static void Main()
{
Console.WriteLine ("\nReflection.FieldAttributes");
Demo d = new Demo();
// Get a Type object for Demo, and a FieldInfo for each of
// the three fields. Use the FieldInfo to display field
// name, value for the Demo object in d, and attributes.
//
Type myType = typeof(Demo);
FieldInfo fiPrivate = myType.GetField("m_field",
BindingFlags.NonPublic | BindingFlags.Instance);
DisplayField(d, fiPrivate);
FieldInfo fiPublic = myType.GetField("Field",
BindingFlags.Public | BindingFlags.Instance);
DisplayField(d, fiPublic);
FieldInfo fiConstant = myType.GetField("FieldC",
BindingFlags.Public | BindingFlags.Static);
DisplayField(d, fiConstant);
}
static void DisplayField(Object obj, FieldInfo f)
{
// Display the field name, value, and attributes.
//
Console.WriteLine("{0} = \"{1}\"; attributes: {2}",
f.Name, f.GetValue(obj), f.Attributes);
}
}
/* This code example produces the following output:
Reflection.FieldAttributes
m_field = "String A"; attributes: Private
Field = "String B"; attributes: Public
FieldC = "String C"; attributes: Public, Static, Literal, HasDefault
*/
Imports System.Reflection
Public Class Demo
' Declare three fields.
' The first field is private.
Private m_field As String = "String A"
'The second field is public.
Public Field As String = "String B"
' The third field is public and const, hence also static
' and literal with a default value.
Public Const FieldC As String = "String C"
End Class
Module Module1
Sub Main()
' Create an instance of the Demo class.
Dim d As New Demo()
Console.WriteLine(vbCrLf & "Reflection.FieldAttributes")
' Get a Type object for Demo, and a FieldInfo for each of
' the three fields. Use the FieldInfo to display field
' name, value for the Demo object in d, and attributes.
'
Dim myType As Type = GetType(Demo)
Dim fiPrivate As FieldInfo = myType.GetField("m_field", _
BindingFlags.NonPublic Or BindingFlags.Instance)
DisplayField(d, fiPrivate)
Dim fiPublic As FieldInfo = myType.GetField("Field", _
BindingFlags.Public Or BindingFlags.Instance)
DisplayField(d, fiPublic)
Dim fiConstant As FieldInfo = myType.GetField("FieldC", _
BindingFlags.Public Or BindingFlags.Static)
DisplayField(d, fiConstant)
End Sub
Sub DisplayField(ByVal obj As Object, ByVal f As FieldInfo)
' Display the field name, value, and attributes.
'
Console.WriteLine("{0} = ""{1}""; attributes: {2}", _
f.Name, f.GetValue(obj), f.Attributes)
End Sub
End Module
' This code example produces the following output:
'
'm_field = "String A"; attributes: Private
'Field = "String B"; attributes: Public
'FieldC = "String C"; attributes: Public, Static, Literal, HasDefault
Megjegyzések
FieldAttributes A forrás FieldAccessMask értéket használja, hogy csak az attribútum értékének az akadálymentességhez kapcsolódó részeit maszkolja le. Az alábbi kód például azt határozza meg, hogy a nyilvános bit van-e Attributes beállítva.
FieldInfo fi = obj.GetType().GetField("field1");
if ((fi.Attributes & FieldAttributes.FieldAccessMask) ==
FieldAttributes.Public)
{
Console.WriteLine("{0:s} is public. Value: {1:d}", fi.Name, fi.GetValue(obj));
}
Dim fi As FieldInfo = obj.GetType().GetField("field1")
If (fi.Attributes And FieldAttributes.FieldAccessMask) = _
FieldAttributes.Public Then
Console.WriteLine("{0:s} is public. Value: {1:d}", fi.Name, fi.GetValue(obj))
End If
A lekéréshez FieldAttributeselőször szerezze be az osztályt Type.
TypeA helyről szerezze be a FieldInfo.
FieldInfoA helyről szerezze be a Attributes.
Az enumerált érték egy szám, amely a mezőn megvalósított attribútumok bitenkénti VAGY értékének megfelelő szám.