|
|
|
||||||
|
hi everybody,
i allowed myself to modify the slice2sc sources in order to support a new meta data directive: ["cs:attribute(*)"] where * is the attribute added to the generated csharp source example: Code:
module A
{
module B
{
["cs:attribute(System.Serializable)",
"cs:attribute(System.ComponentModel.TypeConverter(typeof(MyClassConverter)))"]
struct S
{
int i0;
};
};
};
Code:
...
namespace A
{
namespace B
{
[ System.ComponentModel.TypeConverter(typeof(MyClassConverter)) ]
[ System.Serializable ]
public struct S
{
...
changed files are slice/CsUtil.cpp and slice2cs/Gen.cpp. added lines in slice/CsUtil.cpp line number 1106 Code:
static const string meta_attribute = "attribute";
string tag = s.substr(prefix.size(), meta_attribute.size());
if( tag == meta_attribute )
{
continue;
}
added lines in Gen.cpp line number 2098: Code:
StringList metadata = p->getMetaData();
StringList::const_iterator iter = metadata.begin();
static const string meta_attribute = "cs:attribute";
for( ; iter != metadata.end(); ++iter )
{
string tag = iter->substr( 0, meta_attribute.size() );
if( tag != meta_attribute )
continue;
string::size_type idx0 = iter->find_first_of( '(' );
string::size_type idx1 = iter->find_last_of( ')' );
string::size_type count = idx1 - idx0 - 1;
string attribute = iter->substr( idx0 + 1, count );
_out << sp << nl << "[ " << attribute << " ]";
}
quick comment for the ZeroC team: if you want to incorporate this mechanism/support into the next versions, please let me know and i'll implement this on other code elements like classes, data members of structs etc. Take care and have a nice weekend tom |
|
||||||
|
Thanks for that Tom!
I will implement a mechanism such as this for the next major release. I'm not quite sure exactly what shape it will take, but it will apply not just to structs. I'd rather have a more general mechanism that applies to any Slice construct. BTW, the "cs" and "vb" metadata directives will be renamed to "clr", so if you set an attribute, it applies to both C# and VB. (The old directives will be deprecated and continue to work a few more releases.) It doesn't make sense to, for example, generate the array mapping for sequences in C#, but the collection mapping for sequences in VB because that makes the generated assemblies incompatible across the two languages. Cheers, Michi. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Helper Classes not Generated | zhi | Help Center | 5 | 01-04-2007 08:18 AM |
| Feature Request: partial classes / structs in .net | programmerdad | Comments | 2 | 08-09-2006 11:24 PM |
| Latency: structs vs. classes | n2503v | Help Center | 7 | 10-09-2005 01:08 AM |
| generated C# classes don't have constructors with arguments for fields | kovacm | Bug Reports | 1 | 08-07-2005 08:00 PM |
| c# implicit type coversion for Ice generated classes/structs | DeepDiver | Help Center | 1 | 01-25-2005 08:30 AM |