Hi, Jb,
One more question.
I decompile the assembly by ildasm with /caverbal option.
The [DefaultValue(0)] becomes something like:
.custom instance void
[System]System.ComponentModel.DefaultValueAttribute::.ctor(object)
= {object(int32(0))}
Do you think ildasm knows some tricks to decode the custom attribute
binary?
How can it be sure to take the 0 as value without the type definition?
Regards
Wicky
On Aug 6, 5:18 pm, Jb Evain <[email protected]> wrote:
> Hey,
>
> On Fri, Aug 6, 2010 at 7:15 AM, Wicky <[email protected]> wrote:
> > I don't know it would fail before accessing it, right?
>
> You can know.
>
> static bool IsResolvable (CustomAttribute attribute)
> {
> try {
> foreach (var parameter in attribute.Constructor.Parameters)
> if (parameter.ParameterType.Resolve () == null)
> return false;
> } catch (FileNotFoundException) {
> return false;
> }
>
> return true;
>
> }
> > Even I know one of ConstructorArguments cannot be resolved, then how
> > can I access other ConstructorArguments(or Perperties and Fields)?
>
> You can't, that's not specific to Cecil, it's specific to the custom
> attribute encoding format. Basically the issue is that they encode
> enums using their underlying type's value. And there's no way to read
> this value properly (it can be anything between one and eight bytes
> long) without resolving the enumeration type to know the actual size
> of the enum. Cecil can't take a guess here.
>
> > I can get TypeReference of the enum type, it's ok for me, but how to
> > get the value 0 without resolve it?
>
> As I said, it's not possible.
>
> --
> Jb Evain <[email protected]>
--
--
mono-cecil