|
11 | 11 | using System.IO;
|
12 | 12 | using System.Linq;
|
13 | 13 | using System.Text;
|
| 14 | +using System.Text.RegularExpressions; |
14 | 15 |
|
15 | 16 | namespace nanoFramework.Tools.MetadataProcessor.Core
|
16 | 17 | {
|
@@ -486,27 +487,27 @@ private void GenerateAssemblyHeader()
|
486 | 487 | fieldCount = 0;
|
487 | 488 | foreach (var f in c.Fields.Where(f => !f.IsStatic && !f.IsLiteral))
|
488 | 489 | {
|
489 |
| - // sanity check for field name |
490 |
| - // like auto-vars and such |
491 |
| - if (f.Name.IndexOfAny(new char[] { '<', '>' }) > 0) |
| 490 | + // rename auto-properties backing field to a valid C++ identifier |
| 491 | + string fixedFieldName = string.Empty; |
| 492 | + string fieldWarning = string.Empty; |
| 493 | + |
| 494 | + if (Regex.IsMatch(f.Name, @"<\w+>k__BackingField")) |
492 | 495 | {
|
493 |
| - classData.InstanceFields.Add(new InstanceField() |
494 |
| - { |
495 |
| - FieldWarning = $"*** Something wrong with field '{f.Name}'. Possibly its backing field is missing (mandatory for nanoFramework).\n" |
496 |
| - }); |
| 496 | + fixedFieldName = $"{f.Name.Replace("<", "").Replace(">", "_")}"; |
| 497 | + fieldWarning = $"// auto-property backing field renamed to '{fixedFieldName}'"; |
497 | 498 | }
|
498 |
| - else |
| 499 | + |
| 500 | + if (_tablesContext.FieldsTable.TryGetFieldReferenceId(f, false, out ushort fieldRefId)) |
499 | 501 | {
|
500 |
| - if (_tablesContext.FieldsTable.TryGetFieldReferenceId(f, false, out ushort fieldRefId)) |
| 502 | + classData.InstanceFields.Add(new InstanceField() |
501 | 503 | {
|
502 |
| - classData.InstanceFields.Add(new InstanceField() |
503 |
| - { |
504 |
| - Name = f.Name, |
505 |
| - ReferenceIndex = firstInstanceFieldId++ |
506 |
| - }); |
507 |
| - } |
508 |
| - fieldCount++; |
| 504 | + Name = string.IsNullOrEmpty(fixedFieldName) ? f.Name : fixedFieldName, |
| 505 | + ReferenceIndex = firstInstanceFieldId++, |
| 506 | + FieldWarning = fieldWarning |
| 507 | + }); |
509 | 508 | }
|
| 509 | + |
| 510 | + fieldCount++; |
510 | 511 | }
|
511 | 512 |
|
512 | 513 | // methods
|
|
0 commit comments