I might be missing something, but I’m getting what I think seems an odd error, that none of the other developers are getting with the same code…
public void SomeMethod(... symbolInfo)
{
ElementId elementId = symbolInfo.GetElementIds().Head(true);
if (elementId.HasValue())
{
// error here "Use of possibly unassigned field 'Type'"
object element = repository.FindElement(elementId.Type, elementId.Id);
if (element != null) { ... }
}
}
public struct ElementId
{
public string Id;
public MDAPI_ElementType Type;
}
With the following extension methods:
public static bool IsEmpty(this ElementId id)
{
return id.Type == ElementType.ElementUnknown || string.IsNullOrEmpty(id.Id);
}
public static bool HasValue(this ElementId id)
{
return !id.IsEmpty();
}
Can anyone tell my why this won’t build?
I’ve managed to fix my build error, by instead calling an extension method which directly takes the ElementId. I have no idea why this fixes the issue though!