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: 1550 | Anzahl registrierter User: 1841 | Besucher online: 7
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)

Prüfen, ob Teil des .NET Frameworks


Autor: Marcel Kloubert
Sprache: C#
Bewertung:
noch nicht bewertet
Anzahl der Aufrufe: 3315
  
Kick it on dotnet-kicks.de  

Beschreibung:

Prüft, ob ein Typ ein Teil des .NET Frameworks ist oder nicht.


Abgelegt unter: .net, type, check, isdotnet, dotnet.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;

public static class DotNetTools
{
    /// <summary>
    /// Checks if a type is part of the Microsoft .NET framework
    /// </summary>
    /// <param name="type">Type</param>
    /// <returns>Is part of the .NET framework (true) or not (false)</returns>
    public static bool IsDotNetType(Type type)
    {
        if (null == type)
        {
            throw new ArgumentNullException("type");
        }

        // prepare list of known .NET-Assemblies
        List<Assembly> asms = new List<Assembly>();
        // System
        asms.Add(Assembly.GetAssembly(typeof(object)));
        // System.Data
        asms.Add(Assembly.GetAssembly(typeof(System.Data.IDbConnection)));
        // System.Drawing
        asms.Add(Assembly.GetAssembly(typeof(System.Drawing.Size)));
        // System.Text.RegularExpressions                
        asms.Add(Assembly.GetAssembly(typeof(System.Text.RegularExpressions.Regex)));
        // System.Web
        asms.Add(Assembly.GetAssembly(typeof(System.Web.HttpUtility)));
        // System.Windows.Forms
        asms.Add(Assembly.GetAssembly(typeof(System.Windows.Forms.Control)));
        // System.Xml
        asms.Add(Assembly.GetAssembly(typeof(System.Xml.XmlNode)));
        // System.Xml.Linq (.NET 3.0)
        asms.Add(Assembly.GetAssembly(typeof(System.Xml.Linq.XObject)));

        bool isDotNet = false;

        // search list
        foreach (Assembly asm in asms)
        {
            if (asm.GetType(type.FullName, false, false) is Type)
            {
                // Names are OK => check if same assemblies
                isDotNet = asm.Equals(type.Assembly);

                if (isDotNet)
                {
                    break;
                }
                // Assemblies are not the same
            }
        }

        return isDotNet;
    }
}
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.)

Marcel Kloubert schrieb am:  30.10.2009 18:44:39

System.Text.RegularExpressions.Regex scheint im eigenen Assembly zu sein, daher Verweis hinzugefügt


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