On 08/18/03 Hamza Karamali wrote:
> Thanks for the info.  However, I want to do this within the mono C code
> (I'm a Master's student trying to hack mono for research) -- not from C#.
> While I am compiling a method (in mini_method_compile, for example), I'd
> like to check the method attributes by referencing its metadata directly.
> Is there any easy way to do this in mono?  Or do I have to read the CLI
> specs and then use the functions in metadata.c in an appropriate manner?

You can call:
        MonoCustomAttrInfo* attributes = mono_custom_attrs_from_method (method);

It returns NULL if there are no attributes defined for the method.
MonoCustomAttrInfo is defined in reflection.h. You can run a loop
over the attrs array elements, checking whether the ctor belongs
to the attribute class that interests you. For example, given:

        class MySpecialAttribute: Attribute {...}
and
        [MySpecialAttribute]
        public void method (...) {...}

When compiling method, you can do something like (untested):

        // my_special_attr should be cached...
        MonoClass *my_special_attr = mono_class_from_name (image, "Hack", 
"MySpecialAttribute");
        MonoCustomAttrInfo* attributes = mono_custom_attrs_from_method (method);
        if (!attributes)
                return; // no special processing requested
        for (i = 0; i < attributes->num_attrs; ++i) {
                if (attributes->attrs [i].ctor->klass == my_special_attr) {
                        // do something special with method
                        break;
                }
        }
        mono_custom_attrs_free (attributes);

lupus

-- 
-----------------------------------------------------------------
[EMAIL PROTECTED]                                     debian/rules
[EMAIL PROTECTED]                             Monkeys do it better
_______________________________________________
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to