I have this construction in my BIML file:
myColumns = myFile.ReadLine().Replace("\"","").Split('|');
I would like to replace this with:
myColumns = myFile.ReadLine().Replace("\"","").Split('<#=delimiter#>');
but apparantly that does not work. Somehow syntaxhighlighting tells me that doesn't work.....
ALSO:
string[] myFiles = Directory.GetFiles(path, "*.csv");
string[] myFiles = Directory.GetFiles(path, "*.<#=filetype#>");
When simply using
myColumns = myFile.ReadLine().Replace("\"","").Split('delimiter');
it tells me Cannot implicitly convert type 'string' to 'char'
delimiter is declared as string delimiter ="|"
when changing that to char delimiter ="|"
I get exactly the same error but then at the line where I am declaring delimiter.....
If I am understanding you correctly, this part of your file:
myColumns = myFile.ReadLine().Replace("\"","").Split('|');
will already be contained within a code block or seperate code file, yes? If so you do not need to parameterise the delmiter
with another code block, but just reference the variable, assuming you have already declared it somewhere:
<#
...
char delimiter = '|';
...
var myColumns = myFile.ReadLine().Replace("\"","").Split(delimiter);
...
#>
In response to your comment, using this code would probably look something like this in your Biml file?
...
<Tables>
<Table Name="TableName" etc>
<Columns>
<# // This is the start of a Code Block
// We can define some C# data structures
char delimiter = '|';
var myColumns = myFile.ReadLine().Replace("\"","").Split(delimiter);
// Then start a loop which will generate some Biml nodes
foreach(string col in myColumns)
{
// Note that the foreach loop is left open despite closing the code block on the next line.
// This means the following Biml is looped over until the foreach ends.
#>
<Column Name="<#=col#>" etc />
<# // We can then start another code block which carries on from the last one
} // This closes the foreach loop defined earlier
#>
</Columns>
</Table>
</Tables>
...
You can see in this example how the C# code is contained within <#
and #>
tags with raw Biml everywhere else. The use of <#=
and #>
tags are a syntax shortcut for referencing previously defined C# variables. These obviously are only necessary when you are within a Biml part of the file and not already within a code block.