From 25206e23e9319d5fbc350d2dda89d1d23873a360 Mon Sep 17 00:00:00 2001 From: Alxandr Date: Fri, 24 Jul 2015 02:34:06 +0200 Subject: [PATCH] add discovery metadata --- .../NativeGenerator.cs | 7 +++++++ src/YoloDev.Dnx.NativeUtils/NativeApiAttribute.cs | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/YoloDev.Dnx.NativeUtils.Generator/NativeGenerator.cs b/src/YoloDev.Dnx.NativeUtils.Generator/NativeGenerator.cs index 6187e90..7ef3d37 100644 --- a/src/YoloDev.Dnx.NativeUtils.Generator/NativeGenerator.cs +++ b/src/YoloDev.Dnx.NativeUtils.Generator/NativeGenerator.cs @@ -19,6 +19,7 @@ class NativeGenerator readonly List _members = new List(); readonly ClassDeclarationSyntax _class; + readonly AttributeSyntax _attribute; public NativeGenerator(NativeModel api, Compilation compilation) { @@ -27,6 +28,11 @@ public NativeGenerator(NativeModel api, Compilation compilation) _class = SyntaxFactory.ClassDeclaration($"NativeMethods${api.Symbol.MetadataName}") .AddBaseListTypes(SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName(api.Symbol.ToDisplayString()))) .AddAttributeLists(SyntaxFactory.AttributeList().AddAttributes(CreateAttribute())); + _attribute = SyntaxFactory.Attribute(SyntaxFactory.ParseName(compilation.GetTypeName())) + .AddArgumentListArguments( + SyntaxFactory.AttributeArgument(SyntaxFactory.TypeOfExpression(SyntaxFactory.ParseTypeName(api.Symbol.ToDisplayString()))), + SyntaxFactory.AttributeArgument(SyntaxFactory.TypeOfExpression(SyntaxFactory.QualifiedName(_ns.Name, SyntaxFactory.IdentifierName(_class.Identifier)))) + ); } SyntaxTree Generate() @@ -42,6 +48,7 @@ SyntaxTree Generate() } return SyntaxFactory.SyntaxTree(SyntaxFactory.CompilationUnit() + .AddAttributeLists(SyntaxFactory.AttributeList().WithTarget(SyntaxFactory.AttributeTargetSpecifier(SyntaxFactory.Token(SyntaxKind.AssemblyKeyword))).AddAttributes(_attribute)) .WithMembers(new SyntaxList().Add(_ns.AddMembers(_class.AddMembers(_members.ToArray())))).NormalizeWhitespace()); } diff --git a/src/YoloDev.Dnx.NativeUtils/NativeApiAttribute.cs b/src/YoloDev.Dnx.NativeUtils/NativeApiAttribute.cs index dac2d1d..559dad9 100644 --- a/src/YoloDev.Dnx.NativeUtils/NativeApiAttribute.cs +++ b/src/YoloDev.Dnx.NativeUtils/NativeApiAttribute.cs @@ -3,7 +3,17 @@ namespace YoloDev.Dnx.NativeUtils { - [AttributeUsage(AttributeTargets.Class)] + [AttributeUsage(AttributeTargets.Assembly)] [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class NativeApiAttribute : Attribute {} + public sealed class NativeApiAttribute : Attribute + { + readonly Type _target; + readonly Type _implementation; + + public NativeApiAttribute(Type target, Type implementation) + { + _target = target; + _implementation = implementation; + } + } }