Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1549 | Anzahl registrierter User: 1833 | Besucher online: 1983
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Property auf Attribute prüfen Property.HasAttribute


Autor: Boas Enkler
Sprache: C#
Bewertung: 3,4
(1 Bewertung)
Anzahl der Aufrufe: 3748
  
Kick it on dotnet-kicks.de  

Beschreibung:

Prüft ob ein Property mit dem angegebenen Attribut markiert ist.

Abgelegt unter: Attribut, System.Attribute, Prüfen, Check, Has.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    /// Determines whether the specified property has given attribute.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property">The property.</param>
        /// <param name="inherit">if set to <c>true</c> baseclasses will be also scanned.</param>
        /// <returns>
        /// 	<c>true</c> if the specified property has the attribute; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasAttribute<T>(this PropertyInfo property, bool inherit) where T : System.Attribute
        {
            Contract.Requires<ArgumentException>(property != null);

            bool exists = false;

            object[] list = property.GetCustomAttributes(typeof(T), inherit);
            exists = list != null && list.Length > 0;


            return exists;
        }

Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.