On Nov 5, 1:43 pm, "Lotfi Gheribi" <[EMAIL PROTECTED]> wrote:
> Hy,
>
> > Is there a way to get all of the properties for a TypeDefinition, base
> > class(es) included (i.e. all the way up to the root)? I looked at
> > DeclaringType but that gives me a TypeReference which doesn't have
> > Properties on it.
>
> I don't think this is possible in Cecil. You have to browse all the parent
> types manually.
> Remember that the parent type can be in another assembly.

Yeah, I wrote a method:

private static List<PropertyDefinition> GetProperties(this
TypeDefinition @this)
{
        var properties = new List<PropertyDefinition>(
                from PropertyDefinition property in @this.Properties
                select property);

        if(@this.BaseType != @this.Module.Import(typeof(object)))
        {
                var baseTypeAssembly = (new
DefaultAssemblyResolver()).Resolve(@this.BaseType.Scope as
AssemblyNameReference);
                properties.AddRange(
        
[EMAIL PROTECTED]());
        }

        return properties;
}


which works...but the problem now is that all of the properties are
PropertyDefinitions, and their getters and setters are
MethodDefintions, which is true...but if the base type comes from
another assembly, that's not technically true. I ended up getting all
sorts of [ERROR: INVALID TOKEN] things showing up in ILDasm because
there is no method defintion in the current assembly.
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to