mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Added initial MarkupDataMapping codegen
This commit is contained in:
@@ -7,7 +7,18 @@ namespace SimpleDebugClient
|
|||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Bridge bridge = new(OwlCore.Remoting.RemotingMode.Client);
|
Bridge bridge = new(OwlCore.Remoting.RemotingMode.Client);
|
||||||
while (true) ;
|
bridge.DispatcherStep += Bridge_DispatcherStep;
|
||||||
|
bridge.InterpreterStep += Bridge_InterpreterStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Bridge_DispatcherStep(string obj)
|
||||||
|
{
|
||||||
|
Console.WriteLine(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Bridge_InterpreterStep(object? sender, Microsoft.Iris.Debug.Data.InterpreterEntry e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,11 @@ namespace Microsoft.Iris.Debug
|
|||||||
public List<System.Xml.XmlDocument> DecompileResults { get; } = new List<System.Xml.XmlDocument>();
|
public List<System.Xml.XmlDocument> DecompileResults { get; } = new List<System.Xml.XmlDocument>();
|
||||||
public TraceSettings TraceSettings { get; } = TraceSettings.Current;
|
public TraceSettings TraceSettings { get; } = TraceSettings.Current;
|
||||||
|
|
||||||
|
#if OPENZUNE
|
||||||
|
public bool GenerateDataMappingModels { get; set; } = true;
|
||||||
|
public List<string> DataMappingModels { get; } = new List<string>();
|
||||||
|
#endif
|
||||||
|
|
||||||
public Bridge Bridge { get; } =
|
public Bridge Bridge { get; } =
|
||||||
#if OPENZUNE
|
#if OPENZUNE
|
||||||
new(OwlCore.Remoting.RemotingMode.Host);
|
new(OwlCore.Remoting.RemotingMode.Host);
|
||||||
|
|||||||
@@ -495,6 +495,11 @@ namespace Microsoft.Iris.Markup
|
|||||||
markupDataMapping.Mappings[index3] = dataMappingEntry;
|
markupDataMapping.Mappings[index3] = dataMappingEntry;
|
||||||
}
|
}
|
||||||
dataMappingsTable[index1] = markupDataMapping;
|
dataMappingsTable[index1] = markupDataMapping;
|
||||||
|
|
||||||
|
#if OPENZUNE
|
||||||
|
if (Application.DebugSettings.GenerateDataMappingModels)
|
||||||
|
Application.DebugSettings.DataMappingModels.Add(markupDataMapping.GenerateModelCode());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
_loadResultTarget.SetDataMappingsTable(dataMappingsTable);
|
_loadResultTarget.SetDataMappingsTable(dataMappingsTable);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
// 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
|
||||||
|
|
||||||
|
#if OPENZUNE
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Formatting;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
using Microsoft.CodeAnalysis.Formatting;
|
||||||
|
using Microsoft.CodeAnalysis.Options;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Microsoft.Iris.Markup
|
namespace Microsoft.Iris.Markup
|
||||||
{
|
{
|
||||||
internal class MarkupDataMapping
|
internal class MarkupDataMapping
|
||||||
@@ -40,6 +49,69 @@ namespace Microsoft.Iris.Markup
|
|||||||
set => _assemblyDataProviderCookie = value;
|
set => _assemblyDataProviderCookie = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => string.Format("({0}, {1})", _provider, _targetType);
|
public override string ToString() => $"({_provider}, {_targetType})";
|
||||||
|
|
||||||
|
#if OPENZUNE
|
||||||
|
/// <summary>
|
||||||
|
/// Generates C# code for a plain-old CLR object (POCO) that can
|
||||||
|
/// be used to serialize and deserialize the data this mapping
|
||||||
|
/// represents.
|
||||||
|
/// </summary>
|
||||||
|
public string GenerateModelCode()
|
||||||
|
{
|
||||||
|
CompilationUnitSyntax cu = SyntaxFactory.CompilationUnit()
|
||||||
|
.AddUsings
|
||||||
|
(
|
||||||
|
SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System"))
|
||||||
|
);
|
||||||
|
|
||||||
|
NamespaceDeclarationSyntax localNamespace = SyntaxFactory.NamespaceDeclaration(
|
||||||
|
SyntaxFactory.IdentifierName("Zune.Xml"));
|
||||||
|
|
||||||
|
ClassDeclarationSyntax modelClass = SyntaxFactory.ClassDeclaration(TargetType.Name)
|
||||||
|
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
|
||||||
|
|
||||||
|
System.Collections.Generic.List<MemberDeclarationSyntax> members = new(Mappings.Length);
|
||||||
|
foreach (var mapping in Mappings)
|
||||||
|
{
|
||||||
|
var propertyType = SyntaxFactory.ParseTypeName(mapping.Property.PropertyType.Name);
|
||||||
|
var property = SyntaxFactory.PropertyDeclaration(propertyType, mapping.Property.Name)
|
||||||
|
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
|
||||||
|
|
||||||
|
if (mapping.Source != null)
|
||||||
|
{
|
||||||
|
string elementName = mapping.Source[1..];
|
||||||
|
var elementNameAttr = SyntaxFactory.AttributeArgument(
|
||||||
|
SyntaxFactory.ParseExpression($"ElementName = {elementName}"));
|
||||||
|
|
||||||
|
var attributes = SyntaxFactory.AttributeList().AddAttributes
|
||||||
|
(
|
||||||
|
SyntaxFactory.Attribute(SyntaxFactory.IdentifierName("XmlElement"),
|
||||||
|
SyntaxFactory.AttributeArgumentList().AddArguments(elementNameAttr))
|
||||||
|
);
|
||||||
|
|
||||||
|
property = property.AddAttributeLists(attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
members.Add(property);
|
||||||
|
}
|
||||||
|
modelClass = modelClass.AddMembers(members.ToArray());
|
||||||
|
|
||||||
|
// Add to file root
|
||||||
|
localNamespace = localNamespace.AddMembers(modelClass);
|
||||||
|
cu = cu.AddMembers(localNamespace);
|
||||||
|
|
||||||
|
// Format file
|
||||||
|
AdhocWorkspace cw = new();
|
||||||
|
OptionSet options = cw.Options;
|
||||||
|
cw.Options.WithChangedOption(CSharpFormattingOptions.IndentBraces, true);
|
||||||
|
SyntaxNode formattedNode = Formatter.Format(cu, cw, options);
|
||||||
|
|
||||||
|
// Write to string
|
||||||
|
using System.IO.StringWriter writer = new();
|
||||||
|
formattedNode.WriteTo(writer);
|
||||||
|
return writer.ToString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,8 @@
|
|||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
||||||
<PackageReference Include="System.Security.Permissions" Version="6.0.0" />
|
<PackageReference Include="System.Security.Permissions" Version="6.0.0" />
|
||||||
<PackageReference Include="Vanara.PInvoke.Accessibility" Version="3.4.2" />
|
<PackageReference Include="Vanara.PInvoke.Accessibility" Version="3.4.2" />
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(UseOpenZune)' == 'true' ">
|
<PropertyGroup Condition=" '$(UseOpenZune)' == 'true' ">
|
||||||
|
|||||||
Reference in New Issue
Block a user