GlueViewOfficialPlugins.Scripting.ExpressionParser.GetObjectFromContainerAndNameEvaluate C# (CSharp) Method

GetObjectFromContainerAndNameEvaluate() private static method

private static GetObjectFromContainerAndNameEvaluate ( object container, string memberName, CodeContext codeContext, object &foundValue, bool &wasFound ) : void
container object
memberName string
codeContext GlueView.Scripting.CodeContext
foundValue object
wasFound bool
return void
        private static void GetObjectFromContainerAndNameEvaluate(object container, string memberName, CodeContext codeContext, ref object foundValue, ref bool wasFound)
        {

            if (container is CsvEntry)
            {
                foundValue = (container as CsvEntry).GetValue(memberName);

            }

            if (codeContext.VariableStack.Count == 0)
            {
                throw new Exception("codeContext doesn't have any entries.  It needs to have at least one");
            }

            int index = -1;
            codeContext.GetVariableInformation(memberName, out index);

            if (index != -1)
            {
                foundValue = codeContext.VariableStack[index][memberName];
                wasFound = true;
            }

            if (wasFound == false && foundValue == null && container != null)
            {
                object instance = container;
                Type type = container.GetType();
                if (container is Type)
                {
                    instance = null;
                    type = container as Type;
                }

                // First let's do reflection
                if (container is ElementRuntime && (container as ElementRuntime).DirectObjectReference != null)
                {
                    ElementRuntime containerElementRuntime = container as ElementRuntime;

                    if (LateBinder.GetInstance(containerElementRuntime.DirectObjectReference.GetType()).TryGetValue(containerElementRuntime.DirectObjectReference, memberName, out foundValue))
                    {
                        // do nothing.
                        wasFound = true;
                    }
                }
                else
                {


                    if (LateBinder.GetInstance(type).TryGetValue(instance, memberName, out foundValue))
                    {
                        // do nothing.
                        wasFound = true;
                    }
                }

                if (foundValue == null && container is ElementRuntime)
                {
                    ElementRuntime containerElementRuntime = container as ElementRuntime;

                    IElement containerElement = (container as ElementRuntime).AssociatedIElement;


                    foundValue = TryToGetStateCategoryFromElement(memberName, containerElement);

                    if (foundValue == null)
                    {
                        foundValue = containerElementRuntime.GetContainedElementRuntime(memberName);
                    }

                    if (foundValue == null)
                    {
                        foundValue = containerElementRuntime.GetReferencedFileSaveRuntime(memberName);
                    }

                    if (foundValue == null && containerElement != null)
                    {
                        // Some values like X or Y are stored inside the element runtime
                        // (because it actually stores those values locally).  However, if
                        // a value doesn't have an underlying value, 
                        CustomVariable variable = containerElementRuntime.GetCustomVariable(memberName, VariableGetType.AsExistsAtRuntime);
                        //CustomVariable variable = containerElement.GetCustomVariableRecursively(memberName);
                        if (variable != null)
                        {
                            if (variable.GetIsCsv())
                            {
                                string rfsToLookFor = FileManager.RemoveExtension(variable.Type);
                                foundValue = containerElementRuntime.GetReferencedFileSaveRuntime(rfsToLookFor);
                                // if it's null, maybe it's a global file
                                if (foundValue == null)
                                {
                                    ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(variable.Type);
                                    if (rfs != null)
                                    {
                                        foundValue = GluxManager.GlobalContentFilesRuntime.LoadReferencedFileSave(rfs, true, containerElement);
                                    }
                                }

                                if (foundValue != null)
                                {
                                    foundValue = GetCsvEntryByRequiredKey(variable.DefaultValue as string, foundValue as RuntimeCsvRepresentation);
                                    // We have a RFS, so let's get values out of it
                                }
                            }
                            else
                            {
                                foundValue = variable.DefaultValue;
                                wasFound = true;
                            }
                        }
                    }
                    wasFound = foundValue != null;
                }
                else if (container is StateSaveCategory)
                {
                    foundValue = (container as StateSaveCategory).States.FirstOrDefault(state => state.Name == memberName);
                    wasFound = foundValue != null;
                }
                else if (container is IElement)
                {
                    foundValue = TryToGetStateCategoryFromElement(memberName, container as IElement);
                }

            }
            if (wasFound == false && foundValue == null)
            {
                foundValue = ObjectFinder.Self.GetElementUnqualified(memberName);
                wasFound = foundValue != null;
            }
            if (wasFound == false && foundValue == null)
            {
                foundValue = TypeManager.GetTypeFromString(memberName);

                wasFound = foundValue != null;


            }
        }