On 8 Dez., 22:41, Jb Evain <[email protected]> wrote:
> On Tue, Dec 8, 2009 at 10:19 PM, Johannes <[email protected]> wrote:
> > The variant definition classes lack a super class, over which I could
> > do my checks without worrying about the actual type.
>
> Am not sure to get what you mean?
This my current output method:
public static void WriteLine(this object type) {
if (type == null)
return;
if (type is TypeDefinition) {
var typeDef = type as TypeDefinition;
string @abstract = typeDef.IsAbstract ? "abstract " : "";
string kind = typeDef.IsClass ? "class" : typeDef.IsEnum ?
"enum" :
typeDef.IsInterface ? "interface" : "unknown kind";
Console.Out.WriteLine("{0}: {1}{2}", typeDef.FullName,
@abstract,
kind);
} else if (type is MethodDefinition) {
var methodDef = type as MethodDefinition;
Console.Out.WriteLine(CreateMethodOutput(methodDef));
} else if (type is FieldDefinition) {
var fieldDef = type as FieldDefinition;
Console.Out.WriteLine("{0}.{1}",
fieldDef.DeclaringType.FullName,
fieldDef.Name);
} else if (type is PropertyDefinition) {
var propertyDef = type as PropertyDefinition;
Console.Out.WriteLine("{0}.{1}:",
propertyDef.DeclaringType.FullName, propertyDef.Name);
if (propertyDef.SetMethod != null) {
Console.Out.WriteLine("\tSet: {0}", CreateMethodOutput
(propertyDef.SetMethod));
}
if (propertyDef.GetMethod != null) {
Console.Out.WriteLine("\tGet: {0}", CreateMethodOutput
(propertyDef.GetMethod));
}
} else {
Console.Out.WriteLine("*** ERROR *** Unknown type: {0}",
type.ToString());
}
}
Assuming a supertype for all those definition types, combining all
properties, I could probably simplify the code above. On the other
hand, I understand your reasoning not to have properties which will be
always false.
>
> > I haven't included events in my checks because I don't see a way how
> > to check their accessibility.
>
> Events, just like Properties, are just metadata gluing together
> methods. You have to poke at their methods (which can have different
> visibilities).
But events themselves can have different visibilities, they can be
even virtual (even that is a dumb thing to do). How can I draw
conclusions from the methods to the event itself?
Johannes
--
--
mono-cecil