private bool AddXmlSchemaProviderAttribute(CatelType catelType)
{
var catelTypeDefinition = catelType.TypeDefinition;
var methodName = GetXmlSchemaMethodName(catelType);
var existingCustomAttribute = (from attribute in catelTypeDefinition.CustomAttributes
where string.Equals(attribute.AttributeType.Name, "XmlSchemaProviderAttribute")
select attribute).FirstOrDefault();
if (existingCustomAttribute != null)
{
var constructorArgument = existingCustomAttribute.ConstructorArguments[0];
if (string.Equals(constructorArgument.Value, methodName))
{
return false;
}
}
var xmlSchemaProviderAttribute = catelTypeDefinition.Module.FindType("System.Xml", "System.Xml.Serialization.XmlSchemaProviderAttribute");
var attributeConstructor = catelTypeDefinition.Module.Import(xmlSchemaProviderAttribute.Resolve().Constructor(false));
var customAttribute = new CustomAttribute(attributeConstructor);
customAttribute.ConstructorArguments.Add(new CustomAttributeArgument(catelTypeDefinition.Module.TypeSystem.String, methodName));
catelTypeDefinition.CustomAttributes.Add(customAttribute);
return true;
}