private static bool GenerateInstantiationOrAssignment(NamedObjectSave namedObject, IElement saveObject, 
            ICodeBlock codeBlock, string overridingName, List<string[]> referencedFilesAlreadyUsingFullFile)
        {
            AssetTypeInfo nosAti = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(namedObject.InstanceType);

            string objectName = namedObject.FieldName;

            bool succeeded = true;

            #region If SourceType is File
            if (namedObject.SourceType == SourceType.File)
            {
                if (string.IsNullOrEmpty(namedObject.SourceFile))
                {
                    succeeded = false;
                }
                else
                {
                    EntitySave entitySave = null;
                    ReferencedFileSave rfs = GetReferencedFileSaveReferencedByNamedObject(namedObject, saveObject, ref entitySave);

                    #region //////////////////////EARLY OUT!!!!  Exit out if the RFS is null or the name is bad

                    if (rfs == null && string.IsNullOrEmpty(overridingName))
                    {
                        if (!string.IsNullOrEmpty(namedObject.SourceFile))
                        {
                            // July 11, 2011
                            // I used to think
                            // that it was best
                            // to "should loudly"
                            // whenever encountering
                            // a bug, however, breaking
                            // the build for everyone is
                            // not the way to do it.  Intead
                            // I'm going to make this not generate
                            // any code if there is no SourceFile, and
                            // we should have some way in Glue to search
                            // for and find incomplete definitions.
                            //string exceptionString = "This object references the file " +
                            //    namedObject.SourceFile + " which is not part of this object.";

                            //stringBuilder.AppendLine("\t\t\tthrow new InvalidOperationException(\"" + exceptionString + "\");");
                            succeeded = false;
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }



                    if ((string.IsNullOrEmpty(namedObject.SourceName) || namedObject.SourceName == "<NONE>") &&
                        FileManager.GetExtension(namedObject.SourceFile) != "srgx")
                    {
                        succeeded = false;
                    }
                    #endregion

                    if (succeeded)
                    {
                        string containerName = overridingName;
                        if (rfs != null)
                        {
                            containerName = rfs.GetInstanceName();// FileManager.RemovePath(FileManager.RemoveExtension(namedObject.SourceFile));
                        }

                        List<StateSave> statesUsingThisNamedObject = saveObject.GetAllStatesReferencingObject(objectName);

                        if (statesUsingThisNamedObject.Count != 0)
                        {
                            InstantiateObjectInSwitchStatement(namedObject, codeBlock, referencedFilesAlreadyUsingFullFile,
                                nosAti, objectName, rfs, statesUsingThisNamedObject, saveObject, containerName, null);
                        }
                        else
                        {
                            InstantiateObjectUsingFile(namedObject, codeBlock, referencedFilesAlreadyUsingFullFile, nosAti, objectName, rfs, saveObject, containerName, overridingName);
                        }
                    }
                }
            }

            #endregion

            else if (namedObject.SourceType == SourceType.FlatRedBallType)
            {
                // We treat Cameras in a special way:
                if (namedObject.ClassType == "Camera")
                {
                    if (namedObject.IsNewCamera)
                    {
                        string contentManagerNameString = "ContentManagerName";
                        codeBlock.Line(objectName + " = new FlatRedBall.Camera(" + contentManagerNameString + ");");
                        codeBlock.Line("FlatRedBall.SpriteManager.Cameras.Add(" + objectName + ");");
                    }
                    else
                    {
                        codeBlock.Line(objectName + " = FlatRedBall.SpriteManager.Camera;");

                    }
                }
                else if (namedObject.IsContainer)
                {
                    codeBlock.Line(objectName + " = this;");
                }
                else
                {
                    string qualifiedName = namedObject.GetQualifiedClassType();

                    if (namedObject.GetAssetTypeInfo() != null)
                    {
                        qualifiedName = namedObject.GetAssetTypeInfo().QualifiedRuntimeTypeName.QualifiedType;
                    }


                    codeBlock.Line(string.Format("{0} = new {1}();", objectName, qualifiedName));

                    if (namedObject.IsLayer || 
                        namedObject.SourceType == SourceType.FlatRedBallType)
                    {
                        codeBlock.Line(string.Format("{0}.Name = \"{1}\";", objectName, objectName));
                    }
                }


            }



            #region else if SourceType is Entity

            else // SourceType == SourceType.Entity
            {
                codeBlock.Line(string.Format("{0} = new {1}(ContentManagerName, false);", objectName,
                                             GetQualifiedTypeName(namedObject)));
                codeBlock.Line(string.Format("{0}.Name = \"{1}\";", objectName, objectName));
                // If it's an Entity List that references a List that can be created by Entities, then the Screen should register this list with the factory

            }

            #endregion
            return succeeded;
        }