UserScopedSettingAttribute Kelas

Definisi

Menentukan bahwa grup pengaturan aplikasi atau properti berisi nilai yang berbeda untuk setiap pengguna aplikasi. Kelas ini tidak dapat diwariskan.

public ref class UserScopedSettingAttribute sealed : System::Configuration::SettingAttribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class UserScopedSettingAttribute : System.Configuration.SettingAttribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type UserScopedSettingAttribute = class
    inherit SettingAttribute
Public NotInheritable Class UserScopedSettingAttribute
Inherits SettingAttribute
Warisan
UserScopedSettingAttribute
Atribut

Contoh

Contoh kode berikut menunjukkan penggunaan UserScopedSettingAttribute yang diterapkan ke keempat properti FormSettings kelas pembungkus, yang berasal dari ApplicationSettingsBase kelas . Kelas ini digunakan untuk mempertahankan lokasi, ukuran, warna latar belakang, dan teks formulir. Contoh kode lengkap tercantum dalam gambaran ApplicationSettingsBase umum kelas.

//Application settings wrapper class
ref class FormSettings sealed: public ApplicationSettingsBase
{
public:
    [UserScopedSettingAttribute()]
    property String^ FormText
    {
        String^ get()
        {
            return (String^)this["FormText"];
        }
        void set( String^ value )
        {
            this["FormText"] = value;
        }
    }

public:
    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("0, 0")]
    property Point FormLocation
    {
        Point get()
        {
            return (Point)(this["FormLocation"]);
        }
        void set( Point value )
        {
            this["FormLocation"] = value;
        }
    }

public:
    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("225, 200")]
    property Size FormSize
    {
        Size get()
        {
            return (Size)this["FormSize"];
        }
        void set( Size value )
        {
            this["FormSize"] = value;
        }
    }

public:
    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("LightGray")]
    property Color FormBackColor
    {
        Color get()
        {
            return (Color)this["FormBackColor"];
        }
        void set(Color value)
        {
            this["FormBackColor"] = value;
        }
    }

};
//Application settings wrapper class
sealed class FormSettings : ApplicationSettingsBase
{
    [UserScopedSettingAttribute()]
    public String FormText
    {
        get { return (String)this["FormText"]; }
        set { this["FormText"] = value; }
    }

    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("0, 0")]
    public Point FormLocation
    {
        get { return (Point)(this["FormLocation"]); }
        set { this["FormLocation"] = value; }
    }

    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("225, 200")]
    public Size FormSize
    {
        get { return (Size)this["FormSize"]; }
        set { this["FormSize"] = value; }
    }

    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("LightGray")]
    public Color FormBackColor
    {
        get { return (Color)this["FormBackColor"]; }
        set { this["FormBackColor"] = value; }
    }
}
'Application settings wrapper class. This class defines the settings we intend to use in our application.
NotInheritable Class FormSettings
    Inherits ApplicationSettingsBase

    <UserScopedSettingAttribute()> _
    Public Property FormText() As String
        Get
            Return CStr(Me("FormText"))
        End Get
        Set(ByVal value As String)
            Me("FormText") = value
        End Set
    End Property

    <UserScopedSettingAttribute(), DefaultSettingValueAttribute("0, 0")> _
    Public Property FormLocation() As Point
        Get
            Return CType(Me("FormLocation"), Point)
        End Get
        Set(ByVal value As Point)
            Me("FormLocation") = value
        End Set
    End Property

    <UserScopedSettingAttribute(), DefaultSettingValueAttribute("225, 200")> _
    Public Property FormSize() As Size
        Get
            Return CType(Me("FormSize"), Size)
        End Get
        Set(ByVal value As Size)
            Me("FormSize") = value
        End Set
    End Property

    <UserScopedSettingAttribute(), DefaultSettingValueAttribute("LightGray")> _
    Public Property FormBackColor() As Color
        Get
            Return CType(Me("FormBackColor"), Color)
        End Get
        Set(ByVal value As Color)
            Me("FormBackColor") = value
        End Set
    End Property
End Class

Keterangan

Properti pengaturan aplikasi memiliki cakupan yang didasarkan pada aplikasi atau tingkat pengguna. Sebagai kategori menyiratkan, properti cakupan aplikasi menyajikan nilai seragam untuk semua pengguna aplikasi, sedangkan properti yang dilingkup pengguna memiliki nilai khusus untuk setiap pengguna aplikasi.

UserScopedSettingAttribute menunjukkan bahwa properti harus dianggap sebagai pengaturan tingkat pengguna, dan bahwa keputusan penyimpanan yang sesuai harus dibuat oleh penyedia pengaturan.

Atribut cakupan diperlukan untuk setiap properti pengaturan aplikasi. Jika properti tidak diterapkan dengan ApplicationScopedSettingAttribute atau UserScopedSettingAttribute, properti diabaikan oleh penyedia pengaturan - properti tidak diserialisasikan. Namun, ini tidak valid untuk menerapkan kedua atribut ke properti pengaturan yang sama. Upaya seperti itu akan menyebabkan dilemparkan ConfigurationErrorsException .

Konstruktor

UserScopedSettingAttribute()

Menginisialisasi instans baru kelas UserScopedSettingAttribute.

Properti

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)

Metode

Equals(Object)

Mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
GetHashCode()

Mengembalikan kode hash untuk instans ini.

(Diperoleh dari Attribute)
GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga