1

I have created following class

Static class CustomerServiceData.cs

namespace QSys.Library.Security
{
    public static class CustomerServiceData
    {
        public static bool CompanyNameUpdatable
        {
            get;
            set;
        }
        public static bool AddressUpdatable
        {
            get;
            set;
        }
        public static bool CityUpdatable
        {
            get;
            set;
        }
    }
}

Now i set value of static class as following. CustomerDataService.cs

namespace QSys.Web.Services
{
    public class CustomerDataService : DomainService
    { 
public void GetCustomerDataService()
        {
            CustomerServiceData.CompanyNameUpdatable = true;
            CustomerServiceData.AddressUpdatable = true;
            CustomerServiceData.CityUpdatable = true;
        }
    }
}

Here i would like to create Static Class Property and it will return whole static class like CustomerViewModel.cs

public class CustomerViewModel : NotificationObject
{
 #region Properties
        public CustomerServiceData SecurityData
        {
            get
            {
                // I HAVE RETURN CustomerServiceData AS STATIC
                //What should be coming here...? 
                return CustomerServiceData;
            }
        }
        public Customer Customer
        {
            get { return _customer; }
            set
            {
                _customer = value;
                RaisePropertyChanged(() => Customer);
            }
        }
        #endregion
}

Any comments and suggestions would be appreciated!

Thanks in Advance, Imdadhusen

imdadhusen
  • 2,493
  • 7
  • 40
  • 75

1 Answers1

3

You can't - there's no such concept as returning the class itself, and you can't use a static class as a parameter type, return type, variable type etc.

You could turn CustomerServiceData into a non-static class but make it a singleton... but personally I would just stop it from being static entirely. Static data - globals, basically - makes it hard to test your code and to reason about it properly. Avoid global data wherever you can. Think about what needs the shared data, and the best way of getting it there (e.g. dependency injection, providers, passing the data to methods etc).

Your CustomerDataService.GetCustomerDataService method (which is somewhat oddly named) should *return a CustomerServiceData rather than just updating static properties.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194