Drizin / CodegenCS

C# Toolkit for Code Generation (T4 alternative!)
MIT License
223 stars 30 forks source link

not found .SaveToFile #14

Closed danijerez closed 1 year ago

danijerez commented 1 year ago

in version 3.1.0 the 'SaveToFile' function is not inside 'CodegenTextWriter', has it been refactored? Where can I find a changelog of the changes?

Drizin commented 1 year ago

Yeah, that was a bad refactor. Please check 3.1.1 where the methods are back (some with the deprecation attribute).

danijerez commented 1 year ago

Thanks, is the new way documented somewhere?

Drizin commented 1 year ago

I think there was a problem with 3.1.1 package. 3.1.2 should be ok. You should see the new extensions in CodegenCS.IO extending ICodegenOutputfile and ICodegenContext

danijerez commented 1 year ago

I can't find an example of how to adapt the deprecated function

Please use CodegenCS.IO extensions: ICodegenTextWriter.SaveToFile() or ICodegenOutputFile.SaveToFolder()

Should I stop using CodegenTextWriter?

Drizin commented 1 year ago

Yeah, I guess after a recent refactor things got a little confusing. I was trying to remove most I/O from the core library, it was being moved to a different assembly (and that's why the save methods were extensions) but then for some reasons I have aborted that idea, so maybe in next releases I might remove the deprecation attribute.

So... the old method is currently marked as obsolete but it still works:

var writer = new CodegenTextWriter();
writer.WriteLine("Hello, world");
writer.SaveToFile(@"C:\FullPath.cs");

The preferred way is using ICodegenContext and SaveToFolder extension:

using CodegenCS.IO;
var ctx = new CodegenContext();
var writer = ctx["FileName.cs"];
writer.WriteLine("Hello, world");
ctx.SaveToFolder(@"C:\");   // this extension is in CodegenCS.IO
danijerez commented 1 year ago

Perfect, thanks! I was able to refactor the code