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,6 +1,9 @@
|
|||
Version 1.3.41 (in progress)
|
||||
============================
|
||||
|
||||
2009-09-14: wsfulton
|
||||
[C#] Add %csattributes for adding C# attributes to enum values, see docs for example.
|
||||
|
||||
2009-09-11: wsfulton
|
||||
Fix memmove regression in cdata.i as reported by Adriaan Renting.
|
||||
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -1226,12 +1226,17 @@ public:
|
|||
|
||||
{
|
||||
EnumFeature enum_feature = decodeEnumFeature(parent);
|
||||
const String *csattributes = Getattr(n, "feature:cs:attributes");
|
||||
|
||||
if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) {
|
||||
// Wrap (non-anonymous) C/C++ enum with a proper C# enum
|
||||
// Emit the enum item.
|
||||
if (!GetFlag(n, "firstenumitem"))
|
||||
Printf(enum_code, ",\n");
|
||||
|
||||
if (csattributes)
|
||||
Printf(enum_code, " %s\n", csattributes);
|
||||
|
||||
Printf(enum_code, " %s", symname);
|
||||
|
||||
// Check for the %csconstvalue feature
|
||||
|
|
@ -1252,6 +1257,9 @@ public:
|
|||
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers");
|
||||
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
|
||||
|
||||
if (csattributes)
|
||||
Printf(enum_code, " %s\n", csattributes);
|
||||
|
||||
if ((enum_feature == TypesafeEnum) && parent_name && !unnamedinstance) {
|
||||
// Wrap (non-anonymous) enum using the typesafe enum pattern
|
||||
if (Getattr(n, "enumvalue")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue