0
namespace MyStyle
{
    public class Styles
    {                  
            //intended to store style.properties & style.values class 

        public sealed class sealdPropsClass 
        {
            public sealed const string DarkBlueColor = "darkBlue";
        }

        public static class staticPropsClass
        {
            public static const string LightBlueColor = "lightBlue";
        }
    }
}

accessing like so :

 using MyStyles;
 
 string ColorBlue = Styles.sealedPropsClass.DarkBlueColor;

in another question about classes and inheritance I had been warned to refrain the static modifier

reason is : it would be un accessible to others while The Current user is already Accessing the class

via current page or another web application that uses that class .

what i would like to understand from this example:

1.

How Can i wrap Styles in an outer class(is that what i Should do?) :

so i would be able to use an instance = a clone, of the subject class as in this code below:

public Styles CurrentAppStyles = new Styles();

string darkColor = CurrentAppStyles.sealdPropsClass.DarkBlueColor

2.

if i am importing MyStyle namespace via

 using MyStyle; ///<-- is that an instance ? 

meaning it would not (if there was an Exeption error for that case) alert user:

"Styles.SealedPropsClass.DarkBlueColor is Currently being used, Please try again later..."

or it is actually instantiating the Whole namespace (that's what i think happens in this case)

and thanks for the Great help i can get here , from your experience and Knowledge !!

updated (source of Question)

this is where i have been warned , could you pleas shed some more light ???

This isn't answering your question but I noticed this hasn't been pointed out yet: your mail class is dangerous because it is declared static and has public static fields exposed. **

** update 2** my fault was that i didn't get from Joshuas comment is actually sharing the state globally was the issue rather access issue... so , i guess in the case of using constant fields (strings etc...) would not be a problem

Community
  • 1
  • 1
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76
  • Do you really get this kind of error? There should be no problem accessing static variable by several users. – Amiram Korach Nov 12 '12 at 14:29
  • Are you just trying to make a class to hold constants? If so, then you're over-thinking this problem. Just make Styles a static class filled with static readonly strings and access them like this; MyStyle.Styles.DarkBlue etc. – Chris McAtackney Nov 12 '12 at 14:29
  • 1
    That warning about static was specific to the use of it in your "mail" example. Like Joshua said, making it static means you're sharing the state globally. However, if you're just using it for some stateless purpose (like storing constants), then it's fine. – Chris McAtackney Nov 12 '12 at 14:38

1 Answers1

0

so what i can understand by now that using a static class is not to be avoided at all scenarios for example . extention methods are used via a static class , most of my sub classess are static for example :"

public class container // instanciated so name is not so relevant 
{                      // e.g : container c = new container()
                       // usage- c.utils.......
    public static class utils // used from an instance of container
    {
      public static int Str2int(string strToConvert)
      {
          return Convert.ToInt32(StrToConvert);
      }
    }
}
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76