Application.CompanyName - WPF



  • Hi,
    ich verwende zum ersten mal WPF
    vorher in meinen WindowsForms- Anwendungen habe ich
    folgenden Code verwendet, um meinen ProgramData-Ordner
    zu finden.

    string tPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);     
    tPath = Path.Combine(tPath, Application.CompanyName);
    tPath = Path.Combine(tPath, Application.ProductName);
    

    Jetzt kommt ja die Application-Klasse eigentlich aus dem Namespace:
    System.Windows.Forms
    Spricht da was dagegen, dass in einer WPF-Anwendung zu verwenden?
    Da ich in WPF keine korrespondierende Funktion finden konnte.
    Gruß



  • WinForms benutzt intern auch nur Reflection:

    public static string CompanyName
    {
        get
        {
            AssemblyCompanyAttribute company = (AssemblyCompanyAttribute)AssemblyCompanyAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute));
    
            return company.Company;
        }
    }
    
    public static string ProductName
    {
        get
        {
            AssemblyProductAttribute product = (AssemblyProductAttribute)AssemblyProductAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyProductAttribute));
    
            return product.Product;
        }
    }
    


  • Ok,
    vielen Danke 🙂


Anmelden zum Antworten