我有一个方法,我想将一个对象的内容复制到另一个对象,因此修改一个不会改变另一个。所以在这里讨论我需要克隆两个对象:Clone two objects。
但我的问题是LightningChartUltimate
类来自dll。我无法实现IClonable
。任何人都可以告诉我创建图表副本的选项是什么,所以对新对象的任何更改都不会影响图表吗?
public void SaveImage(string fileName,
TargetImageFormat imgFormat,
double width, double height, double fontscale,
bool launchExplorerAfterSave,LightningChartUltimate chart)
{
double originalMarkerFontSize = 0;
try
{
if (File.Exists(fileName))
File.Delete(fileName);
TargetImageFormat imageFormat = imgFormat;
BitmapAntialiasOptions option = new BitmapAntialiasOptions();
option.ActualPixelWeight = 1;
option.ResolutionDivider = 1;
option.BlurRadius = 0;
LightningChartUltimate TempChart = new LightningChartUltimate();
TempChart = chart; //THE PROBLEM IS IF I UPDATE TempChart IT INTERNALLY AFFECTS chart object. AND chart is being used at so many other places.
originalMarkerFontSize = m_ChartFontForSeriesEventMarker.Size;
TempChart.Title.Font.Size = TempChart.Title.Font.Size * fontscale;
TempChart.ViewXY.XAxes[0].Title.Font.Size = TempChart.ViewXY.XAxes[0].Title.Font.Size * fontscale;
TempChart.ViewXY.YAxes[0].Title.Font.Size = TempChart.ViewXY.YAxes[0].Title.Font.Size * fontscale;
TempChart.ViewXY.XAxes[0].LabelsFont.Size = TempChart.ViewXY.XAxes[0].LabelsFont.Size * fontscale;
TempChart.ViewXY.YAxes[0].LabelsFont.Size = TempChart.ViewXY.YAxes[0].LabelsFont.Size * fontscale;
TempChart.ViewXY.LegendBoxes[0].SeriesTitleFont.Size *= fontscale;
SeriesEventMarker marker = new SeriesEventMarker();
marker.Label.Font.Size = m_ChartFontForSeriesEventMarker.Size * fontscale;
TempChart.Width = width;
TempChart.Height = height;
using (FileStream stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
{
TempChart.SaveToStream(stream, imageFormat, option,
Convert.ToInt32(width), Convert.ToInt32(height));
//chart.SaveToFile(string.Format("{0}.{1}",fileName,imgFormat.ToLower()), option, (int)imageSaveSize.Width, (int)imageSaveSize.Height);
}
}
catch (Exception exception)
{
SystemDebugLogLogger.LogError(exception, "LightningChartUserControl:Error in SaveImage");
throw exception;
}
finally
{
m_ChartFontForSeriesEventMarker.Size = originalMarkerFontSize;
}
}