private void UpdateIncludedAndExcluded(StateSave instance)
        {
            ResetToDefault();

            ExcludeMember("InstructionSaves");
            ExcludeMember("NamedObjectPropertyOverrides");
            IElement element = ObjectFinder.Self.GetElementContaining(instance);

                        
            for (int i = 0; i < element.CustomVariables.Count; i++)
            {
                CustomVariable customVariable = element.CustomVariables[i];

                StateSave stateSaveOwningVariable = null;

                // This doesn't share variables, so it may own the variable
                StateSaveCategory thisCategory = GetContainingCategory(instance, element);
                List<StateSave> statesInThisCategory = null;
                if (thisCategory != null)
                {
                    statesInThisCategory = thisCategory.States;
                }
                else
                {
                    statesInThisCategory = element.States;
                }

                foreach (StateSave stateInThisCategory in statesInThisCategory)
                {
                    if (stateInThisCategory.AssignsVariable(customVariable))
                    {
                        stateSaveOwningVariable = instance;
                    }
                }

                if (stateSaveOwningVariable == null)
                {
                    stateSaveOwningVariable = GetStateThatVariableBelongsTo(customVariable, element);
                }
                Type type = TypeManager.GetTypeFromString(customVariable.Type);

                TypeConverter typeConverter = customVariable.GetTypeConverter(CurrentElement, instance, null);
                    
                Attribute[] customAttributes;
                if (stateSaveOwningVariable == instance ||
                    stateSaveOwningVariable == null || GetContainingCategory(instance, element) == GetContainingCategory(stateSaveOwningVariable, element))
                {

                    customAttributes = new Attribute[] 
                    { 
                        new CategoryAttribute("State Variable"),
                        new EditorAttribute(typeof(StateValueEditor), typeof(System.Drawing.Design.UITypeEditor))
                        
                    };
                }
                else
                {
                    StateSaveCategory category = GetContainingCategory(stateSaveOwningVariable, element);

                    string categoryName = "Uncategorized";

                    if (category != null)
                    {
                        categoryName = category.Name;
                    }
                    customAttributes = new Attribute[] 
                    { 
                        // Do we want it to be readonly?  I think this may be too restrictive
                        //new ReadOnlyAttribute(true),
                        new CategoryAttribute("Variables set by other states"),
                        new DisplayNameAttribute(customVariable.Name + " set in " + categoryName)
                        //,
                        //new EditorAttribute(typeof(StateValueEditor), typeof(System.Drawing.Design.UITypeEditor))
                    };
                }


                Type typeToPass = customVariable.GetRuntimeType();
                if (typeToPass == null)
                {
                    typeToPass = typeof(string);
                }

                IncludeMember(
                    customVariable.Name,
                    typeToPass,
                    delegate(object sender, MemberChangeArgs args)
                    {
                        object value = args.Value;

                        // May 16, 2012
                        // This crashed if
                        // the type was a Texture2D.
                        // I don't think we ever want
                        // to set the value on a StateSave
                        // to an actual Texture2D - rather it
                        // should be a string.  I don't think it
                        // should ever be any loaded file, in fact,
                        // so we should prob make sure it's not a file
                        // by adding a check.
                        if (CustomVariablePropertyGridDisplayer.GetShouldCustomVariableBeConvertedToType(args, customVariable))
                        {
                            value = PropertyValuePair.ConvertStringToType((string)args.Value, customVariable.GetRuntimeType());
                        }

                        instance.SetValue(args.Member, value);

                    }

                    ,
                    delegate()
                    {
                        return GetValue(customVariable.Name);

                    },
                    typeConverter,
                    customAttributes


                    );
            }


            //if (false)
            //{

            //    #region Add the Object Overrides

            //    Type namedObjectPropertyOverrideType = typeof(NamedObjectPropertyOverride);
            //    TypeConverter expandableTypeConverter = new ExpandableObjectConverter();

            //    List<NamedObjectSave> namedObjectList = element.NamedObjects;

            //    pdc = AddNamedObjectOverrides(pdc, namedObjectPropertyOverrideType, expandableTypeConverter, namedObjectList);

            //    #endregion
            //}


        }