I have an assignment that I have to write a custom attribute. The attribute must be applicable to interfaces only (at most once) and allows me to associate the name (it must be a String) of the default implementation to its interface. (There can be even more than one implementation, but it's important that there must be at least one default implementation). The following is my code:
[AttributeUsage(AttributeTargets.Interface)]
public class ImplementationNameAttribute:Attribute
{
public List<string> Implementations { get; set; }
public ImplementationNameAttribute(List<string> implementations)
{
foreach(var i in implementations)
Implementations.Add(i);
}
}
[ImplementationName(/*what should I write here?*/)]
public interface I
{
}
public class C:I
{
}
If the parameters are string, how can I use GetType() to check if a certain object is indeed a class and is an implementation of interface I? Keep in mind that the assignment says the parameters are strings and not objects.