How Generic works in C#

  • Thread starter Thread starter _birdy
  • Start date Start date
B

_birdy

Guest
Hi Can someone explain me how IList<stream> works in here ,and how that createStream method works and how they relate to each other? I am not sure about Generic , and would be very much appreciated if you can provide the examples too. Thank you.

//declared variable on top
private IList<Stream> m_streams;

//create stream
private Stream CreateStream(string name,
string fileNameExtension, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new MemoryStream();
m_streams.Add(stream);
return stream;
}

//Export Method
private void Export(LocalReport report)
{
string deviceInfo = "<DeviceInfo>" + "<OutputFormat>EMF</OutputFormat>" + "<PageWidth>29.7cm</PageWidth>" + "<PageHeight>21cm</PageHeight>" + "<MarginTop>0.635cm</MarginTop>" + "<MarginLeft>0.635cm</MarginLeft>" + "<MarginRight>0cm</MarginRight>" + "<MarginBottom>0.2cm</MarginBottom>" + "</DeviceInfo>";
Warning[] warnings = null;
//Initialized Warning with Null (nothing) to remove warning at runtimes
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, warnings);
foreach (Stream stream in m_streams) {
stream.Position = 0;
}
}

//Adding Barcode
public byte[] GetBarcode(string valueToEncode, int width = 300, int height = 150, BarcodeLib.TYPE Symbology = BarcodeLib.TYPE.CODE128)
{
using (BarcodeLib.Barcode objBarcode = new BarcodeLib.Barcode()) {
objBarcode.IncludeLabel = true;
//Optionally, you can set the label font and size
objBarcode.LabelFont = new System.Drawing.Font("Arial", 18, FontStyle.Regular);
//FontStyle.Bold Or FontStyle.Italic
objBarcode.Encode(Symbology, valueToEncode, Color.Black, Color.White, width, height);
using (MemoryStream ms = new MemoryStream()) {
objBarcode.SaveImage(ms, BarcodeLib.SaveTypes.PNG);
return ms.ToArray();
}
}
}

Continue reading...
 
Back
Top