Hi,
I'm trying to copy a property and have problems with CustomAttributes. If
the custom attributed (decorated on the property) is in the same assembly as
the target property's type it will
still have MemberReference instead of MemberDefinition as the
CustomAttribute.Constructor (I haven't tried with constructor parameters
yet). I wonder if I'm missunderstanding something
or if it's a bug.
My workaround is to do something like this:
public static CustomAttribute CopyCustomAttribute(MemberReference
target,CustomAttribute source)
{
CustomAttribute copy = source.Clone();
if (!ReflectionHelper.AreScopeEqual(
source.Constructor.DeclaringType.Scope, target.DeclaringType.Scope))
{
TypeResolverUtil tru = new TypeResolverUtil(
target.DeclaringType.Module.Assembly,
source.Constructor.DeclaringType.Module.Assembly);
tru.ResolveCustomAttribute(copy);
}
else
{
if (!(copy.Constructor is MethodDefinition))
{
TypeDefinition td = target.DeclaringType.Module.Types[
copy.Constructor.DeclaringType.FullName];
copy.Constructor =
td.Constructors.GetConstructor(!copy.Constructor.HasThis,
copy.Constructor.Parameters);
}
}
return copy;
}
Regards,
Mario
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---