2013-05-02 52 views
0

我有三個窗口庫,用於繪製不同類型的位圖。他們都共享的一件事是:字體,顏色和筆。全球項目靜態變量

我想設計一個庫,我可以擁有所有的標準字體,顏色和筆,這樣如果我進行字體更改,它會在所有其他庫中進行全局更改。

例如:我有一個繪製到的位圖三個庫,它們都使用相同的設置:

 internal static readonly Font ELEVATION_FONT = new Font("Segoe UI Semibold", 7.9f), 
            DETAIL_BOX_FONT = new Font(FontFamily.GenericSerif, 8f, FontStyle.Regular);//"Palatino Linotype" 

    internal static readonly Color BACK_COLOR_SCREEN = Color.Black, 
            LINE_COLOR_SCREEN = Color.FromArgb(161, 161, 161), 
            BACK_COLOR = Color.White, 
            LINE_COLOR = Color.Black; 

我想創建一個庫調用MySoluctionNameDrawing和所有使用這些設置的其他庫爲了繪製位圖,他們將使用MySoluctionNameDrawing中的圖片。

這也是爲了可維護性。

MySoluctionName只是我的解決方案的名稱,但我相信你明白我的觀點是爲了演示目的。

任何人都有任何想法,作爲最簡單,最清潔的方式,讓我的所有繪圖相關的工具在一個庫中,並從其他庫中訪問它們,而無需弄亂一切?


這是我想出來的。

繪圖DLL

namespace AlumCloudDrawing 
    { 

     public static class DrawingOptions 
     { 
      public static readonly Font ELEVATION_FONT = new Font("Segoe UI Semibold", 7.9f), 
              DETAIL_BOX_FONT = new Font(FontFamily.GenericSerif, 8f, FontStyle.Regular);//"Palatino Linotype"  


      public static readonly Color BACK_COLOR_SCREEN = Color.Black, 
               LINE_COLOR_SCREEN = Color.FromArgb(161, 161, 161), 
               BACK_COLOR = Color.White, 
               LINE_COLOR = Color.Black; 
     } 
    } 

從依賴於圖紙dll庫庫使用參考。

internal static readonly Font ELEVATION_FONT = AlumCloudDrawing.DrawingOptions.ELEVATION_FONT, 
            DETAIL_BOX_FONT = AlumCloudDrawing.DrawingOptions.DETAIL_BOX_FONT; 

    internal static readonly Color BACK_COLOR_SCREEN = AlumCloudDrawing.DrawingOptions.BACK_COLOR_SCREEN, 
            LINE_COLOR_SCREEN = AlumCloudDrawing.DrawingOptions.LINE_COLOR_SCREEN, 
            BACK_COLOR = AlumCloudDrawing.DrawingOptions.BACK_COLOR, 
            LINE_COLOR = AlumCloudDrawing.DrawingOptions.LINE_COLOR; 

回答

1

我通常遵循這種模式

/src 
    FooApp.sln      -- solution file 
    /apps       -- folder for apps 
     /FooApp.Core     -- core project 
     /FooApp.Drawing1    -- project that references core 
     /FooApp.Drawing2    -- project that references core  
    /tests       -- tests 
     /FooApp.Core.Test 
     /FooApp.Drawing1.Test 
     /FooApp.Drawing2.Test 
+0

所以,我想我只是在做夢,我可以在一個庫中的靜態常量和參考,從另一個庫,並使用靜態常量,好像他們是本地的,不用必須做的顏色= MyConstants.BACK_COLOR – 2013-05-03 01:35:46

+0

爲什麼不呢?你只需要確保靜態變量是可見的,即改變'internal' =>'public' – oleksii 2013-05-03 07:22:06