Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 07-18-2005
DeepDiver's Avatar
DeepDiver DeepDiver is offline
Registered User
 
Name: Thomas Müller
Organization: Freelance Software Developer
Project: Project depend on Customers
 
Join Date: Nov 2004
Location: Munich, Bavaria, Germany
Posts: 100
C#: Attributes with Ice generated classes and structs

hi,

i'd like to use .net serialization on ice generated classes/structs.
therefore i need set the attribute [Serializable] in the beginning of the
call definition.

is there a way to do this?
maybe the compiler could support a metadata directive for this.

thx tom

PS: another solution would be to work with ice classes and registed and
object factory which generates an object base on a class with the attribute.
but thats a bit of an overkill fo just have one attribues set.

PPS: such a metadata directive is also needed for sequences and
dictionaries - in case ZeroC is planning to add this feature ;-)

Last edited by DeepDiver : 07-18-2005 at 04:14 PM. Reason: added comment on sequences and dictionaries
Reply With Quote
  #2 (permalink)  
Old 07-22-2005
DeepDiver's Avatar
DeepDiver DeepDiver is offline
Registered User
 
Name: Thomas Müller
Organization: Freelance Software Developer
Project: Project depend on Customers
 
Join Date: Nov 2004
Location: Munich, Bavaria, Germany
Posts: 100
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;
		};
	};
};
will create following code:
Code:
...
namespace A
{
    namespace B
    {
	[ System.ComponentModel.TypeConverter(typeof(MyClassConverter)) ]

	[ System.Serializable ]

	public struct S
	{
...
my changes in compiler source code is only for attribute usage on structs.
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 << " ]";
	}
in order to make the generated sources compile the attributes need be used with their full name.

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
Reply With Quote
  #3 (permalink)  
Old 07-23-2005
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
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.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -4. The time now is 11:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.