当前位置: 首页>>代码示例>>C#>>正文


C# ReferencedFileSave.GetTypeForCsvFile方法代码示例

本文整理汇总了C#中FlatRedBall.Glue.SaveClasses.ReferencedFileSave.GetTypeForCsvFile方法的典型用法代码示例。如果您正苦于以下问题:C# ReferencedFileSave.GetTypeForCsvFile方法的具体用法?C# ReferencedFileSave.GetTypeForCsvFile怎么用?C# ReferencedFileSave.GetTypeForCsvFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FlatRedBall.Glue.SaveClasses.ReferencedFileSave的用法示例。


在下文中一共展示了ReferencedFileSave.GetTypeForCsvFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AdjustDataFilesIfIsCsv

        public static void AdjustDataFilesIfIsCsv(string oldName, ReferencedFileSave rfs)
        {
            // We'll remove the old file from the project, delete it, then have the RFS regenerate/add the new one to the project

            //////////////Early Out///////////////////

            if (!rfs.IsCsvOrTreatedAsCsv || UsesAlterntaiveClass(rfs))
            {
                return;
            }
            ////////////End Early Out/////////////////
            string className = rfs.GetTypeForCsvFile(oldName);

            string whatToRemove = "DataTypes/" + className + ".Generated.cs";
            ProjectManager.ProjectBase.RemoveItem(whatToRemove);
            string fileToDelete = whatToRemove;
            fileToDelete = ProjectManager.MakeAbsolute(fileToDelete);
            if (System.IO.File.Exists(fileToDelete))
            {
                try
                {
                    FileHelper.DeleteFile(fileToDelete);
                }
                catch (Exception e)
                {
                    GlueGui.ShowMessageBox("Could not delete the file " + fileToDelete + "\n\nThe file is no longer referneced by the project so it is not necessary to delete this file manually.");
                }
            }

            CsvCodeGenerator.GenerateAndSaveDataClass(rfs, rfs.CsvDelimiter);
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:31,代码来源:ReferencedFileSaveSetVariableLogic.cs

示例2: GetDictionaryTypes

        public static void GetDictionaryTypes(ReferencedFileSave referencedFileSave, out string keyType, out string valueType)
        {
            valueType = referencedFileSave.GetTypeForCsvFile();

            // To know the value type, we gotta pop this bad boy open and find the first requied type
            keyType = null;

            char oldDelimiter = CsvFileManager.Delimiter;

            switch (referencedFileSave.CsvDelimiter)
            {
                case AvailableDelimiters.Comma:
                    CsvFileManager.Delimiter = ',';
                    break;
                case AvailableDelimiters.Tab:
                    CsvFileManager.Delimiter = '\t';
                    break;
                case AvailableDelimiters.Pipe:
                    CsvFileManager.Delimiter = '|';
                    break;
            }

            string absoluteFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name);

            // If the file doesn't exist this will generate bad code.  But this isn't
            // considered a silent failure because Glue will raise flags about missing
            // files earlier (like when it first starts up).  We don't want to crash the
            // entire application in this case.
            if (System.IO.File.Exists(absoluteFileName))
            {
                RuntimeCsvRepresentation rcr = CsvFileManager.CsvDeserializeToRuntime(absoluteFileName);

                // See if any of the headers are required
                foreach (CsvHeader header in rcr.Headers)
                {
                    int indexOfOpeningParen = header.Name.IndexOf("(");

                    if (indexOfOpeningParen != -1)
                    {
                        if (header.Name.IndexOf("required", indexOfOpeningParen) != -1)
                        {
                            keyType = CsvHeader.GetClassNameFromHeader(header.Name);
                            break;
                        }
                    }
                }
            }

            CsvFileManager.Delimiter = oldDelimiter;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:50,代码来源:CsvCodeGenerator.cs

示例3: ReactToRemovalIfCsv

        private static void ReactToRemovalIfCsv(ReferencedFileSave referencedFileToRemove, List<string> additionalFilesToRemove)
        {
            if (referencedFileToRemove.IsCsvOrTreatedAsCsv)
            {
                string name = referencedFileToRemove.GetTypeForCsvFile();
                // If the CSV uses a custom class then the user should not
                // be asked if the file for that class should be removed.  That
                // class was created independent of any CSV (perhaps by hand, perhaps
                // by plugin), so the user should have to explicitly remove the class.

                var customClass = ObjectFinder.Self.GlueProject.GetCustomClassReferencingFile(referencedFileToRemove.Name);

                if (customClass == null)
                {

                    var first = ObjectFinder.Self.GetAllReferencedFiles().FirstOrDefault(item => item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == name);

                    if (first == null)
                    {
                        // Remove the class
                        string whatToRemove = "DataTypes/" + name + ".Generated.cs";

                        additionalFilesToRemove.Add(whatToRemove);

                    }
                }
                
                // See if this uses a custom class.  If so, remove the CSV from
                // the class' list.
                if (customClass != null)
                {
                    customClass.CsvFilesUsingThis.Remove(referencedFileToRemove.Name);
                }
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:35,代码来源:GluxCommands.cs

示例4: GenerateCsvDeserializationCode

        private static void GenerateCsvDeserializationCode(ReferencedFileSave referencedFile, ICodeBlock codeBlock,  string variableName, string fileName, LoadType loadType)
        {
            #region Get the typeName (type as a string)

            string typeName;

            if (FileManager.GetExtension(fileName) == "csv" || referencedFile.TreatAsCsv)
            {
                // The CustomClass interface keeps a name just as it appears in Glue, so we want to use
                // the referencedFile.Name instead of the fileName because fileName will have "Content/" on it
                // and this shouldn't be the case for XNA 4 games
                typeName = CsvCodeGenerator.GetEntireGenericTypeForCsvFile(referencedFile);
            }

            else
            {
                typeName = "System.Collections.Generic.List<" + FileManager.RemovePath(FileManager.RemoveExtension(fileName)) + ">";
            }

            if (typeName.ToLower().EndsWith("file"))
            {
                typeName = typeName.Substring(0, typeName.Length - "file".Length);
            }
            #endregion

            #region Apply the delimiter change

            // Use the delimiter specified in Glue

            var block = codeBlock.Block();
            block.Line("// We put the { and } to limit the scope of oldDelimiter");
            block.Line("char oldDelimiter = FlatRedBall.IO.Csv.CsvFileManager.Delimiter;");

            char delimiterAsChar = referencedFile.CsvDelimiter.ToChar();

            block.Line(@"FlatRedBall.IO.Csv.CsvFileManager.Delimiter = '" + delimiterAsChar + "';");

            #endregion

            string whatToLoadInto;
            if (loadType == LoadType.CompleteLoad)
            {
                whatToLoadInto = "temporaryCsvObject";
                block.Line(string.Format("{0} {1} = new {0}();", typeName, whatToLoadInto));
            }
            else
            {
                whatToLoadInto = referencedFile.GetInstanceName();
                block.Line(string.Format("{0}.Clear();", whatToLoadInto));
            }

            #region Call CsvFileManager.CsvDeserializeList/Dictionary

            if (referencedFile.CreatesDictionary)
            {
                string keyType;
                string valueType;

                CsvCodeGenerator.GetDictionaryTypes(referencedFile, out keyType, out valueType);

                if (keyType == null)
                {
                    System.Windows.Forms.MessageBox.Show("Could not find the key type for:\n\n" + referencedFile.Name + "\n\nYou need to mark one of the headers as required or not load this file as a dictionary.");
                    keyType = "UNKNOWN_TYPE";

                }
                // CsvFileManager.CsvDeserializeDictionary<string, CarData>("Content/CarData.csv", carDataDictionary);
                block.Line(string.Format("FlatRedBall.IO.Csv.CsvFileManager.CsvDeserializeDictionary<{2}, {3}>(\"{0}\", {1});", ProjectBase.AccessContentDirectory + fileName,
                                  whatToLoadInto, keyType, valueType));
            }
            else
            {
                string elementType = referencedFile.GetTypeForCsvFile();

                block.Line(string.Format("FlatRedBall.IO.Csv.CsvFileManager.CsvDeserializeList(typeof({0}), \"{1}\", {2});",
                                         elementType, ProjectBase.AccessContentDirectory + fileName, whatToLoadInto));
            }

            #endregion

            block.Line("FlatRedBall.IO.Csv.CsvFileManager.Delimiter = oldDelimiter;");

            if (loadType == LoadType.CompleteLoad)
            {
                block.Line(string.Format("{0} = temporaryCsvObject;", variableName));
            }
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:87,代码来源:ReferencedFileSaveCodeGenerator.cs

示例5: GetEntireGenericTypeForCsvFile

        public static string GetEntireGenericTypeForCsvFile(ReferencedFileSave referencedFileSave)
        {
            string genericType = referencedFileSave.GetTypeForCsvFile();

            if (referencedFileSave.CreatesDictionary)
            {
                string keyType;
                string valueType;

                GetDictionaryTypes(referencedFileSave, out keyType, out valueType);
                return "System.Collections.Generic.Dictionary<" + keyType + ", " + valueType + ">";
            }
            else
            {
                return "System.Collections.Generic.List<" + genericType + ">";

            }

        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:19,代码来源:CsvCodeGenerator.cs


注:本文中的FlatRedBall.Glue.SaveClasses.ReferencedFileSave.GetTypeForCsvFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。