FlatRedBall.Glue.ElementRuntime.CreateCustomVariableContainer C# (CSharp) Method

CreateCustomVariableContainer() private method

This method populates the mCustomVariables list with default valued variables. These can later get set in SetCustomVariable, but they need to exist so that plugins like the script parser know whether something is a custom variable or not.
private CreateCustomVariableContainer ( CustomVariable cv ) : void
cv FlatRedBall.Glue.SaveClasses.CustomVariable The variable to evaluate and add if it is a custom variable.
return void
        private void CreateCustomVariableContainer(CustomVariable cv)
        {
            bool isCustomVariable = true;

            if(!string.IsNullOrEmpty(cv.SourceObject))
            {
                isCustomVariable = false;
            }

            if (isCustomVariable)
            {

                Type positionedObjectType = typeof(PositionedObject);

                PropertyInfo property = positionedObjectType.GetProperty(cv.Name);
                FieldInfo field = positionedObjectType.GetField(cv.Name);
                if (property != null || field != null)
                {
                    isCustomVariable = false;
                }
            }

            if (isCustomVariable)
            {
                EntitySave baseEntitySave = ObjectFinder.Self.GetEntitySave(this.AssociatedIElement.BaseElement);

                if (baseEntitySave != null && baseEntitySave.GetCustomVariable(cv.Name) != null)
                {
                    isCustomVariable = false;
                }
            }

            if (isCustomVariable)
            {
                object defaultValue = null;
                if (cv.GetIsFile())
                {
                    defaultValue = null;
                }
                    
                else if (cv.GetIsCsv())
                {
                    defaultValue = null;
                }
                else if (cv.GetIsVariableState())
                {
                    defaultValue = null;
                }
                else
                {
                    try
                    {
                        defaultValue = TypeManager.GetDefaultForTypeAsType(cv.Type);
                    }
                    catch
                    {
                        throw new Exception("Could not get the default value for variable " + cv);
                    }
                }

                mCustomVariables.Add(new PropertyValuePair(cv.Name, defaultValue));

            }
        }