Ditched Roslyn

This commit is contained in:
Yoshi Askharoun
2022-06-12 21:38:09 -05:00
parent 9461773d02
commit a41ef575ba
2 changed files with 13 additions and 51 deletions
+13 -49
View File
@@ -4,14 +4,7 @@
// 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 System.Text;
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
{ {
@@ -51,7 +44,6 @@ namespace Microsoft.Iris.Markup
public override string ToString() => $"({_provider}, {_targetType})"; public override string ToString() => $"({_provider}, {_targetType})";
#if OPENZUNE
/// <summary> /// <summary>
/// Generates C# code for a plain-old CLR object (POCO) that can /// Generates C# code for a plain-old CLR object (POCO) that can
/// be used to serialize and deserialize the data this mapping /// be used to serialize and deserialize the data this mapping
@@ -59,59 +51,31 @@ namespace Microsoft.Iris.Markup
/// </summary> /// </summary>
public string GenerateModelCode() public string GenerateModelCode()
{ {
CompilationUnitSyntax cu = SyntaxFactory.CompilationUnit() const string indent = " ";
.AddUsings const string newline = "\r\n";
(
SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("System"))
);
NamespaceDeclarationSyntax localNamespace = SyntaxFactory.NamespaceDeclaration( string start = $@"namespace Zune.Xml;{newline}{newline}public class {TargetType.Name}{newline}{{{newline}";
SyntaxFactory.IdentifierName("Zune.Xml")); string end = $@"}}{newline}";
ClassDeclarationSyntax modelClass = SyntaxFactory.ClassDeclaration(TargetType.Name) var sb = new StringBuilder(start);
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
System.Collections.Generic.List<MemberDeclarationSyntax> members = new(Mappings.Length);
foreach (var mapping in Mappings) foreach (var mapping in Mappings)
{ {
var propertyType = SyntaxFactory.ParseTypeName(mapping.Property.PropertyType.Name); string propertyType = mapping.Property.PropertyType.Name;
var property = SyntaxFactory.PropertyDeclaration(propertyType, mapping.Property.Name) string properyDeclaration = $"{indent}public {propertyType} {mapping.Property.Name} {{ get; set; }}{newline}";
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
if (mapping.Source != null) if (mapping.Source != null)
{ {
string elementName = mapping.Source[1..]; string xmlElemAttribute = $"{indent}[XmlElement(\"{mapping.Source[1..]}\")]{newline}";
var elementNameAttr = SyntaxFactory.AttributeArgument( properyDeclaration = xmlElemAttribute + properyDeclaration;
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); sb.Append(properyDeclaration);
} }
modelClass = modelClass.AddMembers(members.ToArray());
// Add to file root sb.Append(end);
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 return sb.ToString();
using System.IO.StringWriter writer = new();
formattedNode.WriteTo(writer);
return writer.ToString();
} }
#endif
} }
} }
-2
View File
@@ -44,8 +44,6 @@
<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' ">