private void ProcessYAXAttribute(object attr)
{
if (attr is YAXCommentAttribute)
{
string comment = (attr as YAXCommentAttribute).Comment;
if(!String.IsNullOrEmpty(comment))
{
string[] comments = comment.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
for(int i = 0; i < comments.Length; i++)
{
comments[i] = String.Format(" {0} ", comments[i].Trim());
}
this.Comment = comments;
}
}
else if (attr is YAXSerializableTypeAttribute)
{
var theAttr = attr as YAXSerializableTypeAttribute;
this.FieldsToSerialize = theAttr.FieldsToSerialize;
if (theAttr.IsSerializationOptionSet())
{
SerializationOption = theAttr.Options;
m_isSerializationOptionSetByAttribute = true;
}
}
else if (attr is YAXSerializeAsAttribute)
{
Alias = StringUtils.RefineSingleElement((attr as YAXSerializeAsAttribute).SerializeAs);
}
else if (attr is YAXNotCollectionAttribute)
{
if(!ReflectionUtils.IsArray(m_udtType))
IsAttributedAsNotCollection = true;
}
else if (attr is YAXCustomSerializerAttribute)
{
Type serType = (attr as YAXCustomSerializerAttribute).CustomSerializerType;
Type genTypeArg;
bool isDesiredInterface = ReflectionUtils.IsDerivedFromGenericInterfaceType(serType, typeof(ICustomSerializer<>), out genTypeArg);
if (!isDesiredInterface)
{
throw new YAXException("The provided custom serialization type is not derived from the proper interface");
}
if (genTypeArg != UnderlyingType)
{
throw new YAXException("The generic argument of the class and the type of the class do not match");
}
this.CustomSerializerType = serType;
}
else if(attr is YAXPreserveWhitespaceAttribute)
{
PreservesWhitespace = true;
}
else if (attr is YAXNamespaceAttribute)
{
var nsAttrib = (attr as YAXNamespaceAttribute);
Namespace = nsAttrib.Namespace;
NamespacePrefix = nsAttrib.Prefix;
}
else if (attr is YAXCollectionAttribute)
{
m_collectionAttributeInstance = attr as YAXCollectionAttribute;
}
else if (attr is YAXDictionaryAttribute)
{
m_dictionaryAttributeInstance = attr as YAXDictionaryAttribute;
}
else
{
throw new Exception("Attribute not applicable to types!");
}
}