Add %csattributes for adding C# attributes to enum values, see docs for example.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11691 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4ebb9b0db2
commit
5eeab68e21
4 changed files with 34 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
using csharp_attributesNamespace;
|
||||
|
||||
public class runme
|
||||
|
|
@ -171,6 +172,24 @@ public class runme
|
|||
if (Attribute.GetCustomAttribute(member, typeof(Eurostar2Attribute)) == null)
|
||||
throw new Exception("No attribute for " + member.Name);
|
||||
}
|
||||
// Enum value attributes
|
||||
Type walesType = typeof(MoreStations.Wales);
|
||||
{
|
||||
MemberInfo member = (MemberInfo)walesType.GetMember("Cardiff")[0];
|
||||
DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(System.ComponentModel.DescriptionAttribute));
|
||||
if (attribute == null)
|
||||
throw new Exception("No attribute for " + member.Name);
|
||||
if (attribute.Description != "Cardiff city station")
|
||||
throw new Exception("Incorrect attribute value for " + member.Name);
|
||||
}
|
||||
{
|
||||
MemberInfo member = (MemberInfo)walesType.GetMember("Swansea")[0];
|
||||
DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(System.ComponentModel.DescriptionAttribute));
|
||||
if (attribute == null)
|
||||
throw new Exception("No attribute for " + member.Name);
|
||||
if (attribute.Description != "Swansea city station")
|
||||
throw new Exception("Incorrect attribute value for " + member.Name);
|
||||
}
|
||||
// Enum csattribute typemap
|
||||
{
|
||||
Type cymrutype = typeof(Cymru);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ public:
|
|||
int GlobalFunction(int myInt) { return myInt; }
|
||||
%}
|
||||
|
||||
//%include "enumsimple.swg"
|
||||
//%include "enumtypesafe.swg"
|
||||
|
||||
// Test the attributes feature
|
||||
%csattributes MoreStations::MoreStations() "[InterCity1]"
|
||||
|
|
@ -25,6 +27,8 @@ int GlobalFunction(int myInt) { return myInt; }
|
|||
%csattributes Wales "[InterCity6]"
|
||||
%csattributes Paddington() "[InterCity7]"
|
||||
%csattributes DidcotParkway "[InterCity8]"
|
||||
%csattributes MoreStations::Cardiff "[System.ComponentModel.Description(\"Cardiff city station\")]"
|
||||
%csattributes Swansea "[System.ComponentModel.Description(\"Swansea city station\")]"
|
||||
|
||||
%typemap(csattributes) MoreStations "[Eurostar1]"
|
||||
%typemap(csattributes) MoreStations::Wales "[Eurostar2]"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue