mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Updated data mapping codegen
This commit is contained in:
@@ -11,7 +11,8 @@ namespace Microsoft.Iris.Debug
|
|||||||
|
|
||||||
#if OPENZUNE
|
#if OPENZUNE
|
||||||
public bool GenerateDataMappingModels { get; set; } = true;
|
public bool GenerateDataMappingModels { get; set; } = true;
|
||||||
public List<string> DataMappingModels { get; } = new List<string>();
|
public List<(string Provider, string Type, string Code)> DataMappingModels { get; }
|
||||||
|
= new List<(string Provider, string Type, string Code)>();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public Bridge Bridge { get; } =
|
public Bridge Bridge { get; } =
|
||||||
|
|||||||
@@ -498,7 +498,9 @@ namespace Microsoft.Iris.Markup
|
|||||||
|
|
||||||
#if OPENZUNE
|
#if OPENZUNE
|
||||||
if (Application.DebugSettings.GenerateDataMappingModels)
|
if (Application.DebugSettings.GenerateDataMappingModels)
|
||||||
Application.DebugSettings.DataMappingModels.Add(markupDataMapping.GenerateModelCode());
|
Application.DebugSettings.DataMappingModels.Add(
|
||||||
|
(markupDataMapping.Provider, markupDataMapping.TargetType.Name, markupDataMapping.GenerateModelCode())
|
||||||
|
);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
_loadResultTarget.SetDataMappingsTable(dataMappingsTable);
|
_loadResultTarget.SetDataMappingsTable(dataMappingsTable);
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Microsoft.Iris.Markup
|
namespace Microsoft.Iris.Markup
|
||||||
@@ -54,7 +56,7 @@ namespace Microsoft.Iris.Markup
|
|||||||
const string indent = " ";
|
const string indent = " ";
|
||||||
const string newline = "\r\n";
|
const string newline = "\r\n";
|
||||||
|
|
||||||
string start = $@"namespace Zune.Xml;{newline}{newline}public class {TargetType.Name}{newline}{{{newline}";
|
string start = $@"using System;{newline}using System.Collections.Generic;{newline}{newline}namespace Zune.Xml;{newline}{newline}public class {TargetType.Name}{newline}{{{newline}";
|
||||||
string end = $@"}}{newline}";
|
string end = $@"}}{newline}";
|
||||||
|
|
||||||
var sb = new StringBuilder(start);
|
var sb = new StringBuilder(start);
|
||||||
@@ -62,21 +64,49 @@ namespace Microsoft.Iris.Markup
|
|||||||
foreach (var mapping in Mappings)
|
foreach (var mapping in Mappings)
|
||||||
{
|
{
|
||||||
string propertyType = mapping.Property.PropertyType.Name;
|
string propertyType = mapping.Property.PropertyType.Name;
|
||||||
string properyDeclaration = $"{indent}public {propertyType} {mapping.Property.Name} {{ get; set; }}{newline}";
|
if (_knownTypeNames.TryGetValue(propertyType, out var knownTypeName))
|
||||||
|
propertyType = knownTypeName;
|
||||||
|
|
||||||
|
string properyDeclaration = $"{indent}public {propertyType} {mapping.Property.Name} {{ get; set; }}";
|
||||||
|
|
||||||
if (mapping.Source != null)
|
if (mapping.Source != null)
|
||||||
{
|
{
|
||||||
string source = mapping.Source.Substring(1);
|
string source = mapping.Source.StartsWith("/") ? mapping.Source.Substring(1) : mapping.Source;
|
||||||
string xmlElemAttribute = $"{indent}[XmlElement(\"{source}\")]{newline}";
|
string xmlElemAttribute = $"{indent}[XmlElement(\"{source}\")]{newline}";
|
||||||
properyDeclaration = xmlElemAttribute + properyDeclaration;
|
properyDeclaration = xmlElemAttribute + properyDeclaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(properyDeclaration);
|
Type runtimeType = mapping.Property?.PropertyType?.RuntimeType;
|
||||||
|
if (runtimeType != null)
|
||||||
|
{
|
||||||
|
object defaultValue = (runtimeType.IsValueType && Nullable.GetUnderlyingType(runtimeType) == null)
|
||||||
|
? Activator.CreateInstance(runtimeType)
|
||||||
|
: null;
|
||||||
|
string defaultValueStr = defaultValue?.ToString() ?? "null";
|
||||||
|
|
||||||
|
if (defaultValueStr != (mapping.DefaultValue?.ToString() ?? "null"))
|
||||||
|
properyDeclaration += $" = {defaultValueStr};";
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(properyDeclaration + newline + newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(end);
|
sb.Append(end);
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, string> _knownTypeNames = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "Boolean", "bool" },
|
||||||
|
{ "Int32", "int" },
|
||||||
|
{ "UInt32", "uint" },
|
||||||
|
{ "Int64", "long" },
|
||||||
|
{ "UInt64", "ulong" },
|
||||||
|
{ "Int16", "short" },
|
||||||
|
{ "UInt16", "ushort" },
|
||||||
|
{ "String", "string" },
|
||||||
|
{ "List", "List<object>" },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user