Raph,

Particularly, all I did was iterate through all types, find all
CustomAttributes, iterate through all constructors, filter those which
had a "System.Type" in the constructor value, the just called Value on
the constructor argument:

   reference.MainModule.Types
   |> Seq.map(fun x -> (x, x.CustomAttributes |> Seq.filter(fun y ->
y.HasConstructorArguments && y.ConstructorArguments |> Seq.exists(fun
z -> z.Type.FullName = "System.Type"))))
   |> Seq.filter(fun (x, y) -> y |> Seq.isEmpty |> not)
   |> Seq.iter(fun (x, y) -> y |> Seq.iter(fun z ->
z.ConstructorArguments |> Seq.iter(fun q -> (q.Value :?>
TypeReference) |> ignore)))

This may have been overkill, but it resolved the issue for me - this
code was originally meant to remove the CustomAttribute all together
and add it back, so I just ended up modifying it to this once Jb
explained it to me. As far as I can tell, you may just have to access
ConstructorArguments and do nothing with them, just make sure to spin
over all of them, even if you don't do anything with it. I was casting
them to a TypeReference.

-- Kevin J.

On Mar 2, 10:43 am, Raph <[email protected]> wrote:
> hi kevin!
>
> since i am working on a quite similar piece of software, i have a
> question:
> what do you mean by touching? is e.g.
> "customAttribute.ConstructorArguments.Count" enough?
> or do i really have to touch every single value by hand?
>
> thank you!
>
> On 28 Feb., 00:33, Kevin Jones <[email protected]> wrote:
>
>
>
> > Jb,
>
> > Thanks for the insight. Touching the Attribute's constructor values
> > appeared to resolve the issue.
>
> > Many thanks,
> > -- Kevin J.
>
> > On Feb 27, 5:41 pm, Jb Evain <[email protected]> wrote:
>
> > > Hi Kevin,
>
> > > Thanks for the fantastic repro.
>
> > > On Sun, Feb 27, 2011 at 11:01 PM, Kevin Jones <[email protected]> wrote:
> > > > Thanks for taking your time to look at this.
>
> > > So, the issue is indeed due to how custom attributes are encoded, for
> > > types, as a plain string. For speed reason, Cecil when roundtripping
> > > an assembly, doesn't deserialize custom attributes before serializing
> > > them back, but simply copy their byte[] value over to the new
> > > assembly.
>
> > > In your case, it's enough to load the CustomAttributes of the types.
> > > For instance, if you make sure you access the .ConstructorArguments of
> > > the CustomAttribute on SomeType, your test will pass. I'm afraid
> > > you'll indeed have to force yourself the load of the attributes
> > > content. There's currently no helper method in Cecil to ease that.
>
> > > Jb- Hide quoted text -
>
> - Show quoted text -

-- 
--
mono-cecil

Reply via email to