On Wed, Feb 22, 2012 at 9:53 PM, thargy <[email protected]> wrote:
>> If you have a CustomAttribute.ConstructorParameters collection, it
> I have both CustomAttribute.ConstructorArguments AND
> CustomAttribute.Constructor.Parameters, a quick check of the source on
> GitHub reveals that is still the case on the latest branch.  Perhaps
> you misread my comment and missed the dot between the CustomAttribute
> and Parameters?

I actually did. Cecil 0.6 has a ConstructorParameters collection that
was renamed in 0.9, hence the confusion.
CustomAttribute.Constructor.Parameters actually point to the
parameters of the constructors. You don't want to modify that unless
you want to modify the constructor of say, AttachDataAttribute.

> I'm not trying to add a new Attribute, I'm trying to modify an
> existing attribute in the assembly (as per example).

The principle is the same, instead of creating a new one, you can just
modify an existing one. You can add a CustomAttributeNamedArgument in
the Properties, and if everything is correct, it will be serialized at
Write time.

> Further to previous question, I get the type by resolving the
> module.TypeSystem.CorLib to an AssemblyDefinition and using GetType on
> the MainModule, this guarantees I get the type from the right
> framework library and avoid creating a dependency on the Type in the
> framework currently being used.

This work too.

> To come back to my problem, is the only way to remove the existing
> attribute and add a new one, or is it possible to do this on an
> existing attribute?

It shouldn't be a problem to modify an existing one.

Jb

-- 
--
mono-cecil

Reply via email to