public void GetSourceElementAndVariableName(CustomVariable cv, out ElementRuntime sourceElement, out string variableName)
{
sourceElement = null;
variableName = null;
if (cv.DefinedByBase)
{
IElement baseElement = ObjectFinder.Self.GetIElement(mAssociatedIElement.BaseElement);
while (baseElement != null)
{
CustomVariable variableInBase = baseElement.GetCustomVariableRecursively(cv.Name);
if (!string.IsNullOrEmpty(variableInBase.SourceObject) && !string.IsNullOrEmpty(variableInBase.SourceObjectProperty))
{
string name = variableInBase.SourceObject;
sourceElement = GetElementFromName(name);
variableName = variableInBase.SourceObjectProperty;
break;
}
else if (variableInBase.SetByDerived == true && !variableInBase.DefinedByBase &&
string.IsNullOrEmpty(variableInBase.SourceObject))
{
sourceElement = this;
variableName = cv.Name;
break;
}
else
{
baseElement = ObjectFinder.Self.GetIElement(baseElement.BaseElement);
}
}
// If the variable is set by derived, and is the CurrentState for a state that's defined
// in the base, then we'll never get a SourceObject or SourceObjectProperty, but it does need
// to modify "this".
if (sourceElement == null)
{
sourceElement = this;
variableName = cv.Name;
}
}
else if (cv.SourceObject == null || cv.SourceObjectProperty == null)
{
sourceElement = this;
variableName = cv.Name;
}
else
{
string name = cv.SourceObject;
sourceElement = GetElementFromName(name);
variableName = cv.SourceObjectProperty;
}
}