generating

Hello,

maybe I didn't understood the real target of the open api for r#, but my
plan is to generate a class using table attributes from a database! Is
this possible? (like codesmith!)

Something like: (


// Generated Code!
public class ClassNameTable
{
public DataTable GetNewDataTable()
{
DataTable dt = new DataTable("dtname");

dt.Columns.Add("column1", typeof(int));
...

return dt;
}

public int? Column1
{
get {return _column1;}
set {_column1 = value;}
} int? _column1;

...
}

thanks!
Jose Cruz

6 comments
Comment actions Permalink

I wonder why any code generators are necessary for this task.
Whay can't you simply generate text file?

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"José Cruz" <jose.cruz@zmail.pt> wrote in message
news:dhgekm$kui$1@is.intellij.net...

Hello,

>

maybe I didn't understood the real target of the open api for r#, but my
plan is to generate a class using table attributes from a database! Is
this possible? (like codesmith!)

>

Something like: (

>
>

// Generated Code!
public class ClassNameTable
{
public DataTable GetNewDataTable()
{
DataTable dt = new DataTable("dtname");

>

dt.Columns.Add("column1", typeof(int));
...

>

return dt;
}

>

public int? Column1
{
get {return _column1;}
set {_column1 = value;}
} int? _column1;

>

...
}

>

thanks!
Jose Cruz



0
Comment actions Permalink

I have some tables with 600 columns! I just want to give some
connection, table name and R# generates a file with all the 600
columns(properties and Columns for a DataTable).
It seems to me that file templates and live templates have a static
layout. I cant instruct R# to generate a file using a template with
external information, like a XML File with attributes, or a
Macro-PlugIN(accessing a BD and discover columsn names and types a
return them to R#).

or maybe I'm wrong...

Eugene Pasynkov (JetBrains) wrote:

I wonder why any code generators are necessary for this task.
Whay can't you simply generate text file?


Hello,
>
> maybe I didn't understood the real target of the open api for r#, but my
> plan is to generate a class using table attributes from a database! Is
> this possible? (like codesmith!)
>
> Something like: (
>
>
> // Generated Code!
> public class ClassNameTable
> {
> public DataTable GetNewDataTable()
> {
> DataTable dt = new DataTable("dtname");
>
> dt.Columns.Add("column1", typeof(int));
> ...
>
> return dt;
> }
>
> public int? Column1
> {
> get {return _column1;}
> set {_column1 = value;}
> } int? _column1;
>
> ...
> }

0
Comment actions Permalink

Hello José,

I have some tables with 600 columns!

Evidently, your data model requires normalization.

Generating too much code based on some external information source is usually
a bad idea unless the user cannot modify that code. So Custom Build Tool
maybe your choice.

In your case the generated code should be in sync with the data model --
so better place it in some separate file and recreate from scratch each time.

Resharper's templates actually work like some basic snippets which can be
altered afterwards, and I do not feel they can help you much.

Regards,
Maxim.



0
Comment actions Permalink

I think it could be a great feature to R#, a template macro that calls
some external class!

Maxim Babenko wrote:

Hello José,

>> I have some tables with 600 columns!


Evidently, your data model requires normalization.

Generating too much code based on some external information source is
usually a bad idea unless the user cannot modify that code. So Custom
Build Tool maybe your choice.

In your case the generated code should be in sync with the data model --
so better place it in some separate file and recreate from scratch each
time.

Resharper's templates actually work like some basic snippets which can
be altered afterwards, and I do not feel they can help you much.

Regards,
Maxim.


0
Comment actions Permalink

Hello José,

as far as I understand, you're doing a kind of object-relational mapping.
Unfortunately, we're not planning any built-in support for this in ReSharper
-
there're tools on that market, and we're not going to compete with them.
Moreover, such a support always requires some flexibility (you hardly really
need all 600 properties in you class representing the relational table),
and this is
a non-trivial part of the existing tools.

However, it really not a bad idea for you to write a plug-in for ReSharper.
It seems
to me that you'll only need:

1) Retrieve a database schema using ADO.NET or what not
2) Add a file to the project (check IProject/IProjectItem interfaces among
ReSharper APIs)
3) Generate the wrapper class either by hard-coding text or using ReSharper's
API for that
(check ICSharpElementFactory interface among ReSharper APIs)

Sorry if I misundertood your problem.

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I think it could be a great feature to R#, a template macro that calls
some external class!

Maxim Babenko wrote:

>> Hello José,
>>
>>> I have some tables with 600 columns!
>>>
>> Evidently, your data model requires normalization.
>>
>> Generating too much code based on some external information source is
>> usually a bad idea unless the user cannot modify that code. So Custom
>> Build Tool maybe your choice.
>>
>> In your case the generated code should be in sync with the data model
>> -- so better place it in some separate file and recreate from scratch
>> each time.
>>
>> Resharper's templates actually work like some basic snippets which
>> can be altered afterwards, and I do not feel they can help you much.
>>
>> Regards,
>> Maxim.


0
Comment actions Permalink

There is a newsgroup devoted to ReSharper API issues: jetbrains.resharper.openapi.
Please post such questions there.

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hello,

maybe I didn't understood the real target of the open api for r#, but
my plan is to generate a class using table attributes from a database!
Is this possible? (like codesmith!)

Something like: (

// Generated Code!
public class ClassNameTable
{
public DataTable GetNewDataTable()
{
DataTable dt = new DataTable("dtname");
dt.Columns.Add("column1", typeof(int));
...
return dt;
}
public int? Column1
{
get {return _column1;}
set {_column1 = value;}
} int? _column1;
...
}
thanks!
Jose Cruz



0

Please sign in to leave a comment.