/// <summary>分析命名空间</summary> /// <param name="code"></param> /// <returns></returns> String ParseNameSpace(String code) { var sb = new StringBuilder(); var ss = code.Split(new String[] { Environment.NewLine }, StringSplitOptions.None); foreach (var item in ss) { // 提取命名空间 if (!String.IsNullOrEmpty(item)) { var line = item.Trim(); if (line.StartsWith("using ") && line.EndsWith(";")) { var len = "using ".Length; line = line.Substring(len, line.Length - len - 1); if (!NameSpaces.Contains(line)) { NameSpaces.Add(line); } // 不能截断命名空间,否则报错行号会出错 sb.AppendLine(); continue; } } sb.AppendLine(item); } return(sb.ToString().Trim()); }
public Class(string name, string nameSpace, List <string> refrences, List <string> attributes) : this(name, nameSpace) { this.Refrences = refrences; this.Attributes = attributes; Refrences.ForEach(r => NameSpaces.Add(r)); }
public NetflixTimedText() { NameSpaces.Add(new XmlNameSpace { Prefix = "profile", Url = "http://www.netflix.com/ns/ttml/profile/nflx-tt" }); }
public TypeCreator AddNameSpace(string name) { if (!NameSpaces.Contains(name)) { NameSpaces.Add(name); } return(this); }
private static void GenerateExtension() { IDictionary <string, DataTableProcessor.DataProcessor> datableDataProcessors = new SortedDictionary <string, DataTableProcessor.DataProcessor>(); IDictionary <string, DataTableProcessor.DataProcessor> binaryReaderDataProcessors = new SortedDictionary <string, DataTableProcessor.DataProcessor>(); var dataProcessorBaseType = typeof(DataTableProcessor.DataProcessor); var types = GetTypeNames(dataProcessorBaseType); for (var i = 0; i < types.Count; i++) { if (!types[i].IsClass || types[i].IsAbstract || types[i].ContainsGenericParameters) { continue; } if (dataProcessorBaseType.IsAssignableFrom(types[i])) { DataTableProcessor.DataProcessor dataProcessor = null; dataProcessor = (DataTableProcessor.DataProcessor)Activator.CreateInstance(types[i]); if (dataProcessor.IsComment || dataProcessor.IsId || dataProcessor.IsEnum) { continue; } datableDataProcessors.Add(dataProcessor.LanguageKeyword, dataProcessor); } } AddEnumType(datableDataProcessors); NameSpaces.Add("System"); NameSpaces.Add("System.IO"); NameSpaces.Add("System.Collections.Generic"); NameSpaces.Add("UnityEngine"); NameSpaces = NameSpaces.Distinct().ToList(); GenerateDataTableExtensionArray(datableDataProcessors); GenerateDataTableExtensionList(datableDataProcessors); GenerateBinaryReaderExtensionList(datableDataProcessors); GenerateBinaryReaderExtensionArray(datableDataProcessors); GenerateDataTableExtensionDictionary(datableDataProcessors); GenerateBinaryReaderExtensionDictionary(datableDataProcessors); AssetDatabase.Refresh(); }
private static void GenerateExtensionByAnalysis() { List <string> types = new List <string>(32); foreach (var dataTableFileName in DataTableConfig.DataTablePaths) { var lines = File.ReadAllLines(dataTableFileName, Encoding.UTF8); var rawRowCount = lines.Length; var rawColumnCount = 0; var rawValues = new List <string[]>(); for (var i = 0; i < lines.Length; i++) { var rawValue = lines[i].Split('\t'); for (var j = 0; j < rawValue.Length; j++) { rawValue[j] = rawValue[j].Trim('\"'); } if (i == 0) { rawColumnCount = rawValue.Length; } else if (rawValue.Length != rawColumnCount) { throw new GameFrameworkException(Utility.Text.Format( "Data table file '{0}', raw Column is '{2}', but line '{1}' column is '{3}'.", dataTableFileName, i.ToString(), rawColumnCount.ToString(), rawValue.Length.ToString())); } rawValues.Add(rawValue); } types.AddRange(rawValues.ToArray()[2]); types = types.Distinct().ToList(); } types.Remove("Id"); types.Remove("#"); types.Remove(""); types.Remove("comment"); List <DataTableProcessor.DataProcessor> datableDataProcessors = types.Select(DataTableProcessor.DataProcessorUtility.GetDataProcessor).ToList(); NameSpaces.Add("System"); NameSpaces.Add("System.IO"); NameSpaces.Add("System.Collections.Generic"); NameSpaces.Add("UnityEngine"); NameSpaces = NameSpaces.Distinct().ToList(); var dataProcessorsArray = datableDataProcessors .Where(_ => _.LanguageKeyword.ToLower().EndsWith("[]")) .Select(_ => DataTableProcessor.DataProcessorUtility.GetDataProcessor(_.LanguageKeyword.ToLower() .Replace("[]", ""))) .ToDictionary(_ => _.LanguageKeyword, _ => _); var dataProcessorsList = datableDataProcessors .Where(_ => _.LanguageKeyword.ToLower().StartsWith("list")) .Select(_ => DataTableProcessor.DataProcessorUtility.GetDataProcessor(_.LanguageKeyword.ToLower() .Replace("list", "").Replace("<", "").Replace(">", ""))) .ToDictionary(_ => _.LanguageKeyword, _ => _); var dataProcessorsDictionary = datableDataProcessors .Where(_ => _.LanguageKeyword.ToLower().StartsWith("dictionary")) .Select(_ => { var keyValue = _.LanguageKeyword.ToLower() .Replace("dictionary", "").Replace("<", "").Replace(">", "").Split(','); return(new[] { DataTableProcessor.DataProcessorUtility.GetDataProcessor(keyValue[0]), DataTableProcessor.DataProcessorUtility.GetDataProcessor(keyValue[1]) }); } ).ToList(); if (dataProcessorsArray.Count > 0) { GenerateDataTableExtensionArray(dataProcessorsArray); GenerateBinaryReaderExtensionArray(dataProcessorsArray); } if (dataProcessorsList.Count > 0) { GenerateDataTableExtensionList(dataProcessorsList); GenerateBinaryReaderExtensionList(dataProcessorsList); } if (dataProcessorsDictionary.Count > 0) { GenerateDataTableExtensionDictionary(dataProcessorsDictionary); GenerateBinaryReaderExtensionDictionary(dataProcessorsDictionary); } AssetDatabase.Refresh(); }