Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternative to large messy attributes?

Tags:

c#

attributes

I often find that attributes can be too large. Sometimes it feels like the attributes take up more of the screen than the code. It can make it hard to spot the method names.

Also, they are not reusable, so you can end up repeating your values a lot.

To counter this I considered creating my own attribute class, which inherits from the required attribute, and just sets all the properties to the defaults I need.
However, in most cases attributes are sealed, putting a stop to my schemes.

Is there any alternative to large attributes?


As a random example of what I'm talking about:

[SoapDocumentMethod(
    "http://services.acme.co.uk/account/Web/GetCustomerDetails/GetCustomerDetails", 
    RequestNamespace = "http://services.acme.co.uk/account/Web", 
    ResponseNamespace = "http://services.acme.co.uk/account/Web", 
    Use = SoapBindingUse.Literal, 
    ParameterStyle = SoapParameterStyle.Wrapped)]
public Response GetCustomerDetails(Request request)
{
    //...
}
like image 256
Buh Buh Avatar asked May 19 '11 10:05

Buh Buh


1 Answers

While it doesn't solve all your problems, you should be using constants for your repeated values, especially strings.

[SoapDocumentMethod(
    URL, RequestNamespace = NAMESPACE, ResponseNamespace = NAMESPACE, 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public Response GetCustomerDetails(Request request)
{
    //...
}
like image 106
C. Ross Avatar answered Sep 20 '22 16:09

C. Ross