public void AddTranslation(ClassDescriptor entry) { if (!EntriesByTag.ContainsKey(entry.TagName)) { EntriesByTag.Add(entry.TagName, entry); } if (!EntriesByClassSimpleName.ContainsKey(entry.DescribedClassSimpleName)) { EntriesByClassSimpleName.Add(entry.DescribedClassSimpleName, entry); } if (!EntriesByClassName.ContainsKey(entry.DescribedClassSimpleName)) { EntriesByClassName.Add(entry.DescribedClassSimpleName, entry); } String[] otherTags = XmlTools.OtherTags(entry.DescribedClass); if (otherTags != null) { foreach (string otherTag in otherTags.Where(otherTag => !string.IsNullOrEmpty(otherTag))) { EntriesByTag.Add(otherTag, entry); } } }
/// <summary> /// Recursive method to resolve annotations in parameter class and its super classes. /// This mehthod creates field descriptors and other optimized datastructures, which /// is used for marshalling and ummarshalling of runtime objects. /// </summary> /// <param name="thatClass"> /// The parameter class <c>Type</c> to resolve any defined annotations. /// </param> /// <param name="fieldDescriptorClass"> /// Used by recursive call from inside the function. Can be null if being called /// for the first time. /// </param> public void DeriveAndOrganizeFieldsRecursive(Type thatClass) { if (XmlTools.IsAnnotationPresent <SimplInherit>(thatClass)) { TypeInfo classTypeInfo = thatClass.GetTypeInfo(); Type[] superClassGenericArguments = classTypeInfo.BaseType.GenericTypeArguments; ClassDescriptor superClassDescriptor = GetClassDescriptor(classTypeInfo.BaseType); ReferFieldDescriptorsFrom(superClassDescriptor, superClassGenericArguments); } IEnumerable <FieldInfo> fields = thatClass.GetTypeInfo().DeclaredFields; // Iterate through all fields for the type foreach (FieldInfo thatField in fields) { // We don't serialize static values in S.im.pl, continue on to the next field if ((thatField.IsStatic)) { continue; } Int16 fieldType = FieldTypes.UnsetType; if (XmlTools.IsScalar(thatField)) { fieldType = FieldTypes.Scalar; } else if (XmlTools.IsAnnotationPresent <SimplComposite>(thatField)) { fieldType = FieldTypes.CompositeElement; } else if (XmlTools.IsAnnotationPresent <SimplCollection>(thatField)) { fieldType = FieldTypes.CollectionElement; } else if (XmlTools.IsAnnotationPresent <SimplMap>(thatField)) { fieldType = FieldTypes.MapElement; } if (fieldType == FieldTypes.UnsetType) { continue; //not a simpl serialization annotated field } FieldDescriptor fieldDescriptor = NewFieldDescriptor(thatField, fieldType, fieldDescriptorClass); //generics fieldDescriptor.GenericTypeVarsContextCD = this; if (fieldDescriptor.FdType == FieldTypes.Scalar) { Hint xmlHint = fieldDescriptor.XmlHint; switch (xmlHint) { case Hint.XmlAttribute: _attributeFieldDescriptors.Add(fieldDescriptor); break; case Hint.XmlText: case Hint.XmlTextCdata: break; case Hint.XmlLeaf: case Hint.XmlLeafCdata: _elementFieldDescriptors.Add(fieldDescriptor); break; } } else { _elementFieldDescriptors.Add(fieldDescriptor); } if (XmlTools.IsCompositeAsScalarValue(thatField)) { _scalarValueFieldDescriptor = fieldDescriptor; } _fieldDescriptorsByFieldName.Add(thatField.Name, fieldDescriptor); if (fieldDescriptor.IsMarshallOnly) { continue; } String fieldTagName = fieldDescriptor.TagName; if (fieldDescriptor.IsWrapped) { FieldDescriptor wrapper = NewFieldDescriptor(fieldDescriptor, fieldTagName, fieldDescriptorClass); MapTagToFdForTranslateFrom(fieldTagName, wrapper); } else if (!fieldDescriptor.IsPolymorphic) { String tag = fieldDescriptor.IsCollection ? fieldDescriptor.CollectionOrMapTagName : fieldTagName; MapTagToFdForTranslateFrom(tag, fieldDescriptor); var otherTagsAttributes = XmlTools.GetAnnotation <SimplOtherTags>(thatField); String[] otherTags = XmlTools.OtherTags(otherTagsAttributes); if (otherTags != null) { foreach (String otherTag in otherTags) { MapTagToFdForTranslateFrom(otherTag, fieldDescriptor); } } } else { MapTagClassDescriptors(fieldDescriptor); } } }