FieldAttributes Sabit listesi
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bir alanın özniteliklerini açıklayan bayrakları belirtir.
Bu sabit listesi, üyeleri için bit düzeyinde karşılaştırmayı destekler.
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
- Devralma
- Öznitelikler
Alanlar
| Name | Değer | Description |
|---|---|---|
| PrivateScope | 0 | Alana başvurulamadığını belirtir. |
| Private | 1 | Alana yalnızca üst tür tarafından erişilebildiğini belirtir. |
| FamANDAssem | 2 | Alana yalnızca bu derlemedeki alt türlerle erişilebildiğini belirtir. |
| Assembly | 3 | Alanına bütünleştirilmiş kod boyunca erişilebilir olduğunu belirtir. |
| Family | 4 | Alana yalnızca tür ve alt türlere göre erişilebildiğini belirtir. |
| FamORAssem | 5 | Alanın her yerde alt türlerle ve bu derlemenin tamamında erişilebilir olduğunu belirtir. |
| Public | 6 | Alana, bu kapsamın görünür olduğu herhangi bir üye tarafından erişilebildiğini belirtir. |
| FieldAccessMask | 7 | Belirli bir alanın erişim düzeyini belirtir. |
| Static | 16 | Alanın tanımlı türü temsil ettiğini veya örnek başına olduğunu belirtir. |
| InitOnly | 32 | Alanın yalnızca başlatıldığını ve yalnızca bir oluşturucunun gövdesinde ayarlanabileceğini belirtir. |
| Literal | 64 | Alanın değerinin bir derleme zamanı (statik veya erken sınır) sabiti olduğunu belirtir. Ayarlama girişimleri bir FieldAccessExceptionoluşturur. |
| NotSerialized | 128 | Tür uzak olduğunda alanın seri hale getirilmemesi gerekmediğini belirtir. |
| HasFieldRVA | 256 | Alanın göreli bir sanal adresi (RVA) olduğunu belirtir. RVA, içinde bulunduğu görüntü dosyasının başlangıcına göre bir adres olarak geçerli görüntüdeki yöntem gövdesinin konumudur. |
| SpecialName | 512 | Yöntemin nasıl özel olduğunu açıklayan adıyla özel bir yöntem belirtir. |
| RTSpecialName | 1024 | Ortak dil çalışma zamanının (meta veri iç API'leri) ad kodlamasını denetlemesi gerektiğini belirtir. |
| HasFieldMarshal | 4096 | Alanın hazırlama bilgilerine sahip olduğunu belirtir. |
| PinvokeImpl | 8192 | Gelecekte kullanım için ayrılmıştır. |
| HasDefault | 32768 | Alanın varsayılan bir değere sahip olduğunu belirtir. |
| ReservedMask | 38144 | Rezerve edilmiş. |
Örnekler
Bu örnekte üç alan oluşturulur ve FieldAttributes değerler görüntülenir. Bir FieldAttributes değer, üçüncü alanda gösterildiği gibi hem hem Publicde Literal gibi birden fazla öznitelik içerebilir.
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
Açıklamalar
FieldAttributes değerini FieldAccessMask kullanarak öznitelik değerinin yalnızca erişilebilirlikle ilgili bölümlerini maskeler. Örneğin, aşağıdaki kod ortak bit kümesinin olup olmadığını Attributes belirler.
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
almak FieldAttributesiçin önce sınıfını Typealın. ' Typeden öğesini alın FieldInfo. ' FieldInfoden öğesini alın Attributes.
Numaralandırılmış değer, alanda uygulanan özniteliklerin bit düzeyinde OR değerini temsil eden bir sayıdır.