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


C# Reference.CreateReference方法代码示例

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


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

示例1: Convert

        public bool Convert()
        {
            try {
                richTextBox1.Text = "Core loaded! adding references." + Environment.NewLine;
                reference = new Reference(csproj);
                reference.RemoveOriginal("fNbt");
                reference.RemoveReference("fNbt");
                reference.CreateReference("fNbt", ReferencePaths.FnbtPath);

                reference.RemoveOriginal("System.Threading");
                reference.RemoveReference("System.Threading");
                reference.CreateReference("System.Threading", ReferencePaths.ThreadingPath);

                reference.RemoveOriginal("System.Tuples");
                reference.RemoveReference("System.Tuples");
                reference.CreateReference("System.Tuples", ReferencePaths.TuplePath);

                reference.RemoveOriginal("Newtonsoft.Json");
                reference.RemoveReference("Newtonsoft.Json");
                reference.CreateReference("Newtonsoft.Json", ReferencePaths.NewtonsoftPath);

                reference.ChangeFramework();

                richTextBox1.Text += reference.Status;
                var list = new List<string>();
                DirSearch(list, Path.GetDirectoryName(csproj));

                foreach (string path in list)
                {
                    if (path.Contains(".csproj"))
                    {
                        continue;
                    }

                    StringBuilder builder = new StringBuilder();
                    bool needsTuple = false;
                    foreach (var line in File.ReadAllLines(path))
                    {
                        builder.AppendLine(line);

                        if (line.Contains("using System.Tuples;"))
                        {
                            break;
                        }
                        else if (line.Contains("Tuple"))
                        {
                            needsTuple = true;
                        }
                    }

                    builder.Replace(".Item1", ".Element1");
                    builder.Replace(".Item2", ".Element2");
                    builder.Replace(".Item3", ".Element3");
                    builder.Replace("Tuple.Create", "Tuple.New");
                    string val = Environment.ExpandEnvironmentVariables("%USERPROFILE%").Replace("\\", "/");
                    builder.Replace("Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)", "\"" + val + "\"");
                    builder.Replace("\".truecraft\", \"settings.json\"", "\".truecraft/settings.json\"");

                    if (needsTuple)
                    {
                        File.WriteAllText(path, "using System.Tuples;" + Environment.NewLine + builder.ToString());
                        builder.Clear(); // clear builder to save memeory
                    }
                    else
                    {
                        File.WriteAllText(path, builder.ToString());
                        builder.Clear(); // clear builder to save memeory
                    }
                }
                return true;
            } catch (Exception e)
            {
                richTextBox1.Text += "Converting Core failed!" + Environment.NewLine + e.Message;
                return false;
            }
        }
开发者ID:whalleyboi,项目名称:TrueCraft-To-.NET-3.5,代码行数:76,代码来源:TrueCraft.Core.cs

示例2: Convert

        public bool Convert()
        {
            try
            {
                richTextBox1.Text = "API loaded! adding references." + Environment.NewLine;
                reference = new Reference(csproj);
                reference.RemoveOriginal("fNbt");
                reference.RemoveReference("fNbt");
                reference.CreateReference("fNbt", ReferencePaths.FnbtPath);

                reference.RemoveOriginal("System.Threading");
                reference.RemoveReference("System.Threading");
                reference.CreateReference("System.Threading", ReferencePaths.ThreadingPath);

                reference.RemoveOriginal("System.Tuples");
                reference.RemoveReference("System.Tuples");
                reference.CreateReference("System.Tuples", ReferencePaths.TuplePath);

                reference.RemoveOriginal("YamlDotNet");
                reference.RemoveReference("YamlDotNet");
                reference.CreateReference("YamlDotNet", ReferencePaths.YamlPath);

                reference.ChangeFramework();

                richTextBox1.Text += reference.Status;

                var list = new List<string>();
                DirSearch(list, Path.GetDirectoryName(csproj));

                foreach (string path in list)
                {
                    if (path.Contains(".csproj"))
                    {
                        continue;
                    }

                    StringBuilder builder = new StringBuilder();
                    bool needsTuple = false;
                    foreach (var line in File.ReadAllLines(path))
                    {
                        builder.AppendLine(line);

                        if (line.Contains("using System.Tuples;"))
                        {
                            break;
                        }
                        else if (line.Contains("Tuple"))
                        {
                            needsTuple = true;
                        }
                    }

                    if (needsTuple)
                    {
                        File.WriteAllText(path, "using System.Tuples;" + Environment.NewLine + builder.ToString());
                        builder.Clear(); // clear builder to save memeory
                    }

                    bool modifiedAgain = false;
                    /// Pass #2 for fixes.
                    foreach (var line in File.ReadAllLines(path))
                    {
                        builder.AppendLine(line);
                        if (line.Contains(".Item1"))
                        {
                            builder.Replace(".Item1", ".Element1");
                            modifiedAgain = true;
                        }
                        else if (line.Contains(".Item2"))
                        {
                            builder.Replace(".Item2", ".Element2");
                            modifiedAgain = true;
                        }
                        else if (line.Contains(".Item3"))
                        {
                            builder.Replace(".Item3", ".Element3");
                            modifiedAgain = true;
                        }

                        if (line.Contains("Tuple.Create"))
                        {
                            builder.Replace("Tuple.Create", "Tuple.New");
                            modifiedAgain = true;
                        }
                    }

                    if (modifiedAgain)
                    {
                        File.WriteAllText(path, builder.ToString());
                        builder.Clear(); // clear builder to save memeory
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                richTextBox1.Text += "Converting API failed!" + Environment.NewLine + e.Message;
                return false;
            }
        }
开发者ID:whalleyboi,项目名称:TrueCraft-To-.NET-3.5,代码行数:100,代码来源:TrueCraftAPI.cs

示例3: Convert

        public bool Convert()
        {
            try
            {
                richTextBox1.Text = "Server loaded! adding references." + Environment.NewLine;
                reference = new Reference(csproj);
                reference.RemoveOriginal("fNbt");
                reference.RemoveReference("fNbt");
                reference.CreateReference("fNbt", ReferencePaths.FnbtPath);

                reference.RemoveOriginal("System.Threading");
                reference.RemoveReference("System.Threading");
                reference.CreateReference("System.Threading", ReferencePaths.ThreadingPath);

                reference.RemoveOriginal("System.Tuples");
                reference.RemoveReference("System.Tuples");
                reference.CreateReference("System.Tuples", ReferencePaths.TuplePath);

                reference.RemoveReference("YamlDotNet");
                reference.CreateReference("YamlDotNet", ReferencePaths.YamlPath);
                reference.ChangeFramework();

                richTextBox1.Text += reference.Status;
                var list = new List<string>();
                DirSearch(list, Path.GetDirectoryName(csproj));

                foreach (string path in list)
                {
                    if (path.Contains(".csproj"))
                    {
                        continue;
                    }

                    StringBuilder builder = new StringBuilder();
                    bool needsTuple = false;
                    foreach (var line in File.ReadAllLines(path))
                    {
                        builder.AppendLine(line);

                        if (line.Contains("using System.Tuples;"))
                        {
                            break;
                        }
                        else if (line.Contains("Tuple"))
                        {
                            needsTuple = true;
                        }
                    }

                    builder.Replace(".Item1", ".Element1");
                    builder.Replace(".Item2", ".Element2");
                    builder.Replace(".Item3", ".Element3");
                    builder.Replace("Tuple.Create", "Tuple.New");
                    builder.Replace("Directory.GetCurrentDirectory(), \"players\"", "(Directory.GetCurrentDirectory() + \"/players\")");
                    builder.Replace("new NbtList(\"inventory\", Inventory.GetSlots().Select(s => s.ToNbt())),", "new NbtList(\"inventory\", Inventory.GetSlots().Select(s => (NbtTag)s.ToNbt())),");
                    if (needsTuple)
                    {
                        File.WriteAllText(path, "using System.Tuples;" + Environment.NewLine + builder.ToString());
                        builder.Clear(); // clear builder to save memeory
                    }
                    else
                    {
                        File.WriteAllText(path, builder.ToString());
                        builder.Clear(); // clear builder to save memeory
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                richTextBox1.Text += "Converting API failed!" + Environment.NewLine + e.Message;
                return false;
            }
        }
开发者ID:whalleyboi,项目名称:TrueCraft-To-.NET-3.5,代码行数:74,代码来源:TrueCraft.Server.cs


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