// Resolve the field into context here public override void PreSerialize(CppTypeContext context, IField field) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (field is null) { throw new ArgumentNullException(nameof(field)); } // In this situation, if the type is a pointer, we can simply forward declare. // Otherwise, we need to include the corresponding file. This must be resolved via context // If the resolved type name is null, we won't serialize this field // First, resolve the field type to see if it exists // If it does, because it is a field, we can FD it if it is a pointer // If it is not a pointer, then we need to include it // If it is a nested class, we need to deal with some stuff (maybe) var resolvedName = context.GetCppName(field.Type, true); if (!string.IsNullOrEmpty(resolvedName)) { Resolved(field); } // In order to ensure we get an UnresolvedTypeException when we serialize ResolvedTypeNames.Add(field, resolvedName); string SafeFieldName() { var name = field.Name; if (name.EndsWith("k__BackingField")) { name = name.Split(angleBrackets, StringSplitOptions.RemoveEmptyEntries)[0]; } name = string.Join("$", name.Split(angleBrackets)).Trim('_'); if (char.IsDigit(name[0])) { name = "_" + name; } return(_config.SafeName(name)); } SafeFieldNames.Add(field, SafeFieldName()); }