I'm new to C# and have been modifying some code a previous employee wrote. If I understand correctly, and I'm sure I dont, I need to add an Add method to the MachineInfoClass. It appears to already have one near the end. Maybe its the scope of the method not being public? and help for this green c# programmer would be greatly appreciated.
namespace AIMS_CMM_Calibration_Reporter
{
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Class to describe information related the CMM that was calibrated
/// </summary>
public class MachineInfoClass:IEnumerator,IEnumerable
{
public MachineInfoClass()
{`enter code here`
//default empty constructor
}
public string SerialNumber { get; set; }
public string ModelNumber { get; set; }
public string YearBuilt { get; set; }
//private double _measUncertMicrons = 0.1;
//public double MeasUncertMicrons
//{
// get { return _measUncertMicrons; }
// set
// {//TODO: Measurement Uncertainty maths
// _measUncertMicrons = value;
// double linearUncert = Math.Round(_measUncertMicrons + (1000 / 250), 1);
// double volumnUncert = Math.Round(linearUncert * 2, 1);
// _measUncertCalcText = "MPE = " + _measUncertMicrons.ToString() + " um +( L / 250.0 mm) um Value outside maximum limit (Linear/Volumetric uncertainty to 1000mm " + linearUncert.ToString() + "um/ " + volumnUncert.ToString() + "um)";
// }
//}
//private string _measUncertCalcText = string.Empty;
public string MeasUncertText { get; set; } = string.Empty;
//{
// get { return _measUncertCalcText; }
//}
public string MachinePerformanceSpec { get; set; } = string.Empty;
public MeasurementRange MeasRange { get; set; } = new MeasurementRange();
public ProbeSystemClass ProbeDetails { get; set; } = new ProbeSystemClass();
object IEnumerator.Current
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
/// Class to describe information related to the CMM capabilities
/// </summary>
public class MeasurementRange
{
public string MachineUnits { get; set; }
public string Xrange { get; set; }
public string Yrange { get; set; }
public string Zrange { get; set; }
}
bool IEnumerator.MoveNext()
{
throw new NotImplementedException();
}
void IEnumerator.Reset()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public static implicit operator MachineInfoClass(List<MachineInfoClass> v)
{
throw new NotImplementedException();
}
internal void Remove(object item)
{
throw new NotImplementedException();
}
internal void Add(MachineInfoClass newCMM)
{
throw new NotImplementedException();
}
}
}
****This is where the error actually pops up in frmMain.CS at the xlmserializer ****
public bool SaveReport(string filePath)
{
try
{
//load values from the form into the calreport object
if (!saveValuesintoCalReportObj()) throw new Exception("Form to CalReportObj failed.");
//save the calibration object data to xml
XmlWriterSettings ws = new XmlWriterSettings();
ws.NewLineHandling = NewLineHandling.Entitize; //<-- needed to keep newlines for addresses, etc
XmlSerializer xSave = new XmlSerializer(typeof(CalibrationReport));
using (XmlWriter xWrite = XmlWriter.Create(filePath, ws))
{
xSave.Serialize(xWrite, calReport);
}
activeReportXMLFilename = filePath;
this.Text = Application.ProductName + " :: " + activeReportXMLFilename;
updateMRUlist(activeReportXMLFilename);
return true;
}
catch (Exception ex)
{
//String innerMessage = (ex.InnerException != null)
// ? ex.InnerException.Message
// : "";
MessageBox.Show("Failed to serialize and/or save." + Environment.NewLine + Environment.NewLine + ex.Message );
return false;
}
}