private static XElement GenerateClassElement(Type parentClassType) { var result = new XElement("Fields"); try { if (parentClassType != null) { var properties = AnReflectionCache.GetPropertyInfoList(parentClassType); if (properties?.Count > 0) { foreach (var property in properties.Where(prop => (prop?.Property != null) && (prop.Attribute != null))) { var type = property.Property.PropertyType; if (property.Property.PropertyType.IsEnum) { type = AnReflectionCache.GetUnderlyingType(type); } var className = type.FullName; if (!string.IsNullOrEmpty(className)) { result.Add(new XElement(property.Property.Name, new XAttribute("Type", TrimClassName(className)))); } } } } } catch (Exception ex) { AnLog.Error(ex); } return(result); }
private static void GetClasses(Type parentClassType, IDictionary <string, Type> classes) { try { if ((parentClassType != null) && (classes != null)) { var properties = AnReflectionCache.GetPropertyInfoList(parentClassType); if (properties?.Count > 0) { foreach (var property in properties.Where(prop => (prop?.Property != null) && (prop.Attribute != null))) { var type = property.Property.PropertyType; if (property.Property.PropertyType.IsEnum) { type = AnReflectionCache.GetUnderlyingType(type); } if (!(AnSerialization.SerialSizeDictionary.ContainsKey(type) || (type == typeof(string)) || (type == typeof(byte[])))) { if (!string.IsNullOrEmpty(type.BaseType?.Name) && (type.BaseType?.Name ?? "").ToLower().Contains("anbaseobjectlist")) { if (!string.IsNullOrEmpty(type.BaseType?.FullName)) { var subClassName = GenericOfClassName(type.BaseType?.FullName); if (!string.IsNullOrEmpty(subClassName)) { if (!classes.ContainsKey(subClassName)) { var subType = AnTypes.GetType(subClassName, null); if (subType != null) { classes.Add(subClassName, subType); GetClasses(subType, classes); } } } } } else { if (!string.IsNullOrEmpty(type.FullName) && !classes.ContainsKey(type.FullName)) { classes.Add(type.FullName, type); GetClasses(type, classes); } } } } } } } catch (Exception ex) { AnLog.Error(ex); } }