|
12 | 12 | using System.Linq;
|
13 | 13 | using System.Reflection;
|
14 | 14 | using System.Text;
|
| 15 | +using System.Text.RegularExpressions; |
15 | 16 |
|
16 | 17 | namespace nanoFramework.Tools.MetadataProcessor.Core
|
17 | 18 | {
|
@@ -465,27 +466,27 @@ private void GenerateAssemblyHeader()
|
465 | 466 | fieldCount = 0;
|
466 | 467 | foreach (var f in c.Fields.Where(f => !f.IsStatic && !f.IsLiteral))
|
467 | 468 | {
|
468 |
| - // sanity check for field name |
469 |
| - // like auto-vars and such |
470 |
| - if (f.Name.IndexOfAny(new char[] { '<', '>' }) > 0) |
| 469 | + // rename auto-properties backing field to a valid C++ identifier |
| 470 | + string fixedFieldName = string.Empty; |
| 471 | + string fieldWarning = string.Empty; |
| 472 | + |
| 473 | + if (Regex.IsMatch(f.Name, @"<\w+>k__BackingField")) |
471 | 474 | {
|
472 |
| - classData.InstanceFields.Add(new InstanceField() |
473 |
| - { |
474 |
| - FieldWarning = $"*** Something wrong with field '{f.Name}'. Possibly its backing field is missing (mandatory for nanoFramework).\n" |
475 |
| - }); |
| 475 | + fixedFieldName = $"{f.Name.Replace("<", "").Replace(">", "_")}"; |
| 476 | + fieldWarning = $"// auto-property backing field renamed to '{fixedFieldName}'"; |
476 | 477 | }
|
477 |
| - else |
| 478 | + |
| 479 | + if (_tablesContext.FieldsTable.TryGetFieldReferenceId(f, false, out ushort fieldRefId)) |
478 | 480 | {
|
479 |
| - if (_tablesContext.FieldsTable.TryGetFieldReferenceId(f, false, out ushort fieldRefId)) |
| 481 | + classData.InstanceFields.Add(new InstanceField() |
480 | 482 | {
|
481 |
| - classData.InstanceFields.Add(new InstanceField() |
482 |
| - { |
483 |
| - Name = f.Name, |
484 |
| - ReferenceIndex = firstInstanceFieldId++ |
485 |
| - }); |
486 |
| - } |
487 |
| - fieldCount++; |
| 483 | + Name = string.IsNullOrEmpty(fixedFieldName) ? f.Name : fixedFieldName, |
| 484 | + ReferenceIndex = firstInstanceFieldId++, |
| 485 | + FieldWarning = fieldWarning |
| 486 | + }); |
488 | 487 | }
|
| 488 | + |
| 489 | + fieldCount++; |
489 | 490 | }
|
490 | 491 |
|
491 | 492 | // methods
|
|
0 commit comments