im writing a c# application. im pretty new to c#.
I got a StackOverflowException (yes! :D) trying to set the class properties in the constructor like this:
namespace WindowsUpdateOnLan
{
public class NetworkAdapter
{
public NetworkAdapter(PropertyDataCollection properties)
{
String value = null;
foreach (PropertyData pd in properties)
{
if (pd.Name.Equals("GUID"))
Id = Guid.Parse(pd.Value.ToString());
if (pd.Name.Equals("Name"))
Name = pd.Value.ToString();
if (pd.Name.Equals("NetConnectionID"))
{
value = Regex.Replace(pd.Value.ToString(), @"\s+", "");
adapterType = (AdapterTypeEnum)Enum.Parse(typeof(AdapterTypeEnum), value);
}
if (pd.Name.Equals("NetEnabled"))
{
value = Regex.Replace(pd.Value.ToString(), @"\s+", "");
adapterStatus = (AdapterStatusEnum)Enum.Parse(typeof(AdapterStatusEnum), value);
}
}
}
/// <summary>
/// Contains the GUID that is used to identify the adapter
/// </summary>
public Guid Id
{
get { return this.Id; }
private set { Id = value; }
}
And Visual Studio tells me to make sure i dont have an infinite loop.
I must have forgotten something important or maybe the syntax is not right.
Could anybody take a look at it?