Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
add discovery metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Alxandr committed Jul 24, 2015
1 parent 816d405 commit 25206e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/YoloDev.Dnx.NativeUtils.Generator/NativeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NativeGenerator

readonly List<MemberDeclarationSyntax> _members = new List<MemberDeclarationSyntax>();
readonly ClassDeclarationSyntax _class;
readonly AttributeSyntax _attribute;

public NativeGenerator(NativeModel api, Compilation compilation)
{
Expand All @@ -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<CompilerGeneratedAttribute>()));
_attribute = SyntaxFactory.Attribute(SyntaxFactory.ParseName(compilation.GetTypeName<NativeApiAttribute>()))
.AddArgumentListArguments(
SyntaxFactory.AttributeArgument(SyntaxFactory.TypeOfExpression(SyntaxFactory.ParseTypeName(api.Symbol.ToDisplayString()))),
SyntaxFactory.AttributeArgument(SyntaxFactory.TypeOfExpression(SyntaxFactory.QualifiedName(_ns.Name, SyntaxFactory.IdentifierName(_class.Identifier))))
);
}

SyntaxTree Generate()
Expand All @@ -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<MemberDeclarationSyntax>().Add(_ns.AddMembers(_class.AddMembers(_members.ToArray())))).NormalizeWhitespace());
}

Expand Down
14 changes: 12 additions & 2 deletions src/YoloDev.Dnx.NativeUtils/NativeApiAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 25206e2

Please sign in to comment.