C
chris.bahns
Hello All,
I am fairly new to creating custom attributes, and want to get a
better feel for how they should be named.
We have a class hierarchy, with a base class called "SequenceCommand".
This class has a couple static functions and an embedded class, all of
which are referenced in code like "SequenceCommand.Create()" or
"SequenceCommand.ArgumentDef". There is also a fairly rich hierarchy
of classes under it (maybe 10-15 intermediate classes and about 30
concrete/instantiable classes).
We recently created a custom attribute, which we would apply to the
concrete classes in the hierarchy that we intend to "use" (allowing
them to be used in reflection). This makes our reflection code, which
finds usable classes by name, quite a bit cleaner. Classes without
this attribute are not used, even if they are otherwise capable of
being instantiated, etc.
We want to call this custom attribute class
"SequenceCommandAttribute". The fact that you are applying this
attribute to a class implies that it is "usable", "instantiable", or
"executable", so I think it is slightly redundant to include these
terms in the name of the attribute class.
This approach leads to code like...
[SequenceCommand("MY_COMMAND")]
public class MySequenceCommand : SequenceCommand
{
// implementation
}
There is no conflict here, but it just looks odd that you see
"SequenceCommand" in two places -- one of which is actually referring
to the SequenceCommandAttribute class.
Question: Is this bad practice?
I have found two similar classes in .NET:
System.Runtime.Remoting.Activation.UrlAttribute and
System.SecurityPolicy.Url. These are in two different namespaces, but
perhaps, with the right combination of "using" statements, they could
lead to the same syntax I am describing.
Two alternatives:
1. Change the base class to "SequenceCommandBase"
I don't like this because of the references to the embedded class
"ArgumentDef" and the static functions. ("SequenceCommandBase" just
does not feel right in those cases)
2. Change the attribute class to "ExecutableSequenceCommandAttribute"
I don't like this because it is a little bit verbose, and the
attribute will be applied in many places.
Is there an official position on this sort of thing?
TIA for your help!
- Chris
I am fairly new to creating custom attributes, and want to get a
better feel for how they should be named.
We have a class hierarchy, with a base class called "SequenceCommand".
This class has a couple static functions and an embedded class, all of
which are referenced in code like "SequenceCommand.Create()" or
"SequenceCommand.ArgumentDef". There is also a fairly rich hierarchy
of classes under it (maybe 10-15 intermediate classes and about 30
concrete/instantiable classes).
We recently created a custom attribute, which we would apply to the
concrete classes in the hierarchy that we intend to "use" (allowing
them to be used in reflection). This makes our reflection code, which
finds usable classes by name, quite a bit cleaner. Classes without
this attribute are not used, even if they are otherwise capable of
being instantiated, etc.
We want to call this custom attribute class
"SequenceCommandAttribute". The fact that you are applying this
attribute to a class implies that it is "usable", "instantiable", or
"executable", so I think it is slightly redundant to include these
terms in the name of the attribute class.
This approach leads to code like...
[SequenceCommand("MY_COMMAND")]
public class MySequenceCommand : SequenceCommand
{
// implementation
}
There is no conflict here, but it just looks odd that you see
"SequenceCommand" in two places -- one of which is actually referring
to the SequenceCommandAttribute class.
Question: Is this bad practice?
I have found two similar classes in .NET:
System.Runtime.Remoting.Activation.UrlAttribute and
System.SecurityPolicy.Url. These are in two different namespaces, but
perhaps, with the right combination of "using" statements, they could
lead to the same syntax I am describing.
Two alternatives:
1. Change the base class to "SequenceCommandBase"
I don't like this because of the references to the embedded class
"ArgumentDef" and the static functions. ("SequenceCommandBase" just
does not feel right in those cases)
2. Change the attribute class to "ExecutableSequenceCommandAttribute"
I don't like this because it is a little bit verbose, and the
attribute will be applied in many places.
Is there an official position on this sort of thing?
TIA for your help!
- Chris