Book a Demo

Author Topic: How can I manipulate the (class) filename in the easiest way?  (Read 5741 times)

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
How can I manipulate the (class) filename in the easiest way?
« on: February 20, 2024, 03:48:39 am »
Q: What would be the easiest way to manipulate the Code Generation to suggest a different file name than only the plain Class name?

I had an idea that I could either Tag a copy of the class, or make a different Code Template for the (other) partial class (and run the code generation twice by swapping the code language at the package level), but it seems that the Code Templates are not involved in constructing the class file name (?)

Since I use partial classes to shovel some framework code aside, I need to generate code in two different ways from the same class and thus I need to create two different files from the same class as well.
Example: Say I want the default name for one partial class file (MyClass.cs) and the other partial class filename (MyClass.co.cs)

-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How can I manipulate the (class) filename in the easiest way?
« Reply #1 on: February 20, 2024, 08:59:11 am »
Q: What would be the easiest way to manipulate the Code Generation to suggest a different file name than only the plain Class name?
Use the API to assign a different filename, then don't use the option in the Generate Package dialog to create the filenames.
[/quote]

but it seems that the Code Templates are not involved in constructing the class file name (?)
Correct. They aren't.

Since I use partial classes to shovel some framework code aside, I need to generate code in two different ways from the same class and thus I need to create two different files from the same class as well.
Example: Say I want the default name for one partial class file (MyClass.cs) and the other partial class filename (MyClass.co.cs)
From memory (and it's been a few years) EA handles partial classes by modeling them as separate entities, because even though they are conceptually part of the same thing, the language authors appeared to want to separate/hide portions of the code for a class. That means you have two filename fields to work with and you can do what you're after.

RIL

  • EA User
  • **
  • Posts: 164
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: How can I manipulate the (class) filename in the easiest way?
« Reply #2 on: February 20, 2024, 09:22:30 am »
Quote
From memory (and it's been a few years) EA handles partial classes by modeling them as separate entities, because even though they are conceptually part of the same thing, the language authors appeared to want to separate/hide portions of the code for a class. That means you have two filename fields to work with and you can do what you're after.

The problem with that is that when moving the project or copying the project, there would be need to recreated the file names, and then the two classes (with the same name) would.... have the same name and thus overwrite each other.

But as I write this I wonder if I could use a %path_name%\ClassName.co.cs to preserve the originally defined classname? I will try that.

//Rolf
-- There's always a solution --