Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: puromtec on May 14, 2008, 01:52:00 am

Title: c# attributes above function/properties/classes
Post by: puromtec on May 14, 2008, 01:52:00 am
I am using 7.0.818 of EA to generate code in C# language. It appears that EA cannot handle the "attributes" above C# constructs (properties, classes, etc.), such as the following c# property example below with the attributed of type 'XmlElement':

Code: [Select]
[XmlElement(Type = typeof(CustomSerializer<SingleAnalysis>))]
        public List<SingleAnalysis> Analysis
        {
            get
            {
                if (analysis == null)
                    analysis = new List<SingleAnalysis>();
                return analysis;
            }
            set
            {
                analysis = value;
            }
        }

What happens is on synchronization -> source code, the '[ etc. ]' is removed. This is really a deal breaker for us. Is there anything we can do with EA settings in templates that will let the '[ etc ]' to remain in the .cs files?
Title: Re: c# attributes above function/properties/classe
Post by: «Midnight» on May 14, 2008, 05:15:47 am
Search the forum for attributes and C#. I think there was a way to do this, and it was posted (perhaps by one of the Sparxians).

I could be wrong about this, but if so the post was to the effect that it couldn't be done. Either way you will have your answer.

I think it was a long time ago, so remember to set the search parameters accordingly.

David
Title: Re: c# attributes above function/properties/classe
Post by: davidmf on May 14, 2008, 06:27:16 am
Yep, there is a way to do this for classes (not however, for properties - that I know of).

Select a class from a class diagram, then using the context menu (right-mouse click) choose Add|Tagged Value to bring up the tag editor. If you add a tag called Attribute, you can give it one (or more separated by semi-colons) value(s).
Title: Re: c# attributes above function/properties/classe
Post by: Eve on May 14, 2008, 09:16:07 am
The tagged value mentioned above can be added to anything generated to code, including properties.