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


C# System.IO类代码示例

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


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

示例1: given_empty_cache_and_valid_commit_function

        public void given_empty_cache_and_valid_commit_function()
        {
            var cache = new LockingInMemoryCache();

            long? commitStoreVersion = null;
            long? commitStreamVersion = null;

            cache.ConcurrentAppend("stream", GetEventBytes(1), (version, storeVersion) =>
                {
                    commitStoreVersion = storeVersion;
                    commitStreamVersion = version;
                });

            Assert.AreEqual(1, commitStoreVersion, "commitStoreVersion");
            Assert.AreEqual(1, commitStreamVersion, "commitStreamVersion");

            Assert.AreEqual(1, cache.StoreVersion);

            var expected = new[]
                {
                    CreateKey(1, 1, "stream"),
                };
            DataAssert.AreEqual(expected, cache.ReadStream("stream",0,100));
            DataAssert.AreEqual(expected, cache.ReadAll(0, 100));
        }
开发者ID:mojamcpds,项目名称:lokad-cqrs-1,代码行数:25,代码来源:when_doing_concurrent_append.cs

示例2: GenerateCompareOperatorCode

        public static void GenerateCompareOperatorCode() {
            var s = new StringBuilder();

            var types = new[] {
                                  "DynamicValue", "bool", "byte", "sbyte", "char", "decimal", "double", "float",
                                  "int", "uint", "long", "ulong", "short", "ushort", "string"
                              };

            var operators = new[] {"==", "!=", ">", "<", ">=", "<="};

            foreach (string @operator in operators) {
                foreach (string type1 in types) {
                    string typeName = type1;

                    s.AppendLine("public static bool operator " + @operator + "(DynamicValue p1, " + typeName + " p2) {");

                    if (typeName == "DynamicValue") {
                        s.AppendLine("return (p1.Value " + @operator + " (dynamic)p2.To(p1.Type));");
                    }
                    else {
                        s.AppendLine("return (p1.Value " + @operator + " (dynamic)DynamicConversion.To(p1.Type, p2));");
                    }
                    s.AppendLine("}");
                    s.AppendLine();
                }
            }

            File.WriteAllText("code.cs", s.ToString());
        }
开发者ID:MartijnB,项目名称:DynamicType.NET,代码行数:29,代码来源:CodeGen.cs

示例3: GetRunning

 public bool GetRunning()
 {
     var json = _wc.DownloadString(URL + "?action=getStatus");
     var status = new { running = false };
     status = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(json, status);
     return status.running;
 }
开发者ID:knabbi,项目名称:GW2WBot,代码行数:7,代码来源:StatusAPI.cs

示例4: TransformToGrayscaleFromArray

        public void TransformToGrayscaleFromArray()
        {
            foreach (var data in TestUtils.GetTestImagesData("*.jpg"))
            {
                Assert.DoesNotThrow(() =>
                {
                    var transforms = new[]
                    {
                        new TJTransformDescription
                        {
                            Operation = TJTransformOperations.TJXOP_NONE,
                            Options = TJTransformOptions.GRAY,
                            Region = TJRegion.Empty
                        }
                    };
                    var result = _transformer.Transform(data.Item2, transforms, TJFlags.NONE);

                    Assert.NotNull(result);
                    Assert.NotNull(result.Length == 1);

                    var file = Path.Combine(OutDirectory, "gray_" + Path.GetFileName(data.Item1));
                    File.WriteAllBytes(file, result[0]);
                });
            }
        }
开发者ID:qmfrederik,项目名称:AS.TurboJpegWrapper,代码行数:25,代码来源:TJTransformerTests.cs

示例5: SortObjectCanBeSortedByMonsterIdAndMark

        public void SortObjectCanBeSortedByMonsterIdAndMark()
        {
            var s = new[]{
             new SortedBoxObject { Mark = 0, MonsterId = 3 },
             new SortedBoxObject { Mark = 0, MonsterId = 2 },
             new SortedBoxObject { Mark = 0, MonsterId = 3 },
             new SortedBoxObject { Mark = 0, MonsterId = 1 },
             new SortedBoxObject { Mark = 1, MonsterId = 3 },
             new SortedBoxObject { Mark = 1, MonsterId = 2 },
             new SortedBoxObject { Mark = 2, MonsterId = 3 },
             new SortedBoxObject { Mark = 1, MonsterId = 1 },
             new SortedBoxObject { Mark = 0, MonsterId = 0 }
            };

            var r = s.OrderBy( o=> o ).ToArray();

            Assert.AreSame( s[6], r[0] );
            Assert.AreSame( s[7], r[1] );
            Assert.AreSame( s[5], r[2] );
            Assert.AreSame( s[4], r[3] );
            Assert.AreSame( s[8], r[4] );
            Assert.AreSame( s[3], r[5] );
            Assert.AreSame( s[1], r[6] );
            Assert.AreSame( s[0], r[7] );
            Assert.AreSame( s[2], r[8] );
        }
开发者ID:Zazcallabah,项目名称:PokeSave,代码行数:26,代码来源:PcBufferTests.cs

示例6: IsSupported

        private static bool IsSupported(string fileName)
        {
            string extension = Path.GetExtension(fileName).ToLowerInvariant();
            string[] allowed = new[] { ".js", ".css", ".html", ".htm", ".less", ".scss", ".coffee", ".iced", ".config", ".cs", "vb" };

            return allowed.Contains(extension);
        }
开发者ID:vandro,项目名称:FileNesting,代码行数:7,代码来源:PathSegmentFileNester.cs

示例7: RenderTexture

        public static void RenderTexture(TextureInfo textureInfo, float x, float y, float orientation = 0,
            float offsetX = 0, float offsetY = 0,
            LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
            LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Center,
            float opacity = 1f,
            float scale = 1f)
        {
            GL.Enable(All.Texture2D);
            GL.BindTexture(All.Texture2D, textureInfo.TextureId);

            GL.PushMatrix();
            GL.Translate(x, y, 0f);
            GL.Rotate(orientation, 0, 0, 1);
            GL.Scale (scale, scale, 1);

            x = offsetX + DetermineHorizontalAlignmentCorrection(horizontalAlignment, textureInfo.Width);
            y = -offsetY + DetermineVerticalAlignmentCorrection(verticalAlignment, textureInfo.Height);

            var halfWidth = textureInfo.Width / 2;
            var halfHeight = textureInfo.Height / 2;

            var vertextArray = new[]
            {
                x - halfWidth, y - halfHeight,
                x + halfWidth, y - halfHeight,
                x + halfWidth, y + halfHeight,
                x - halfWidth, y + halfHeight
            };

            RenderTextureWithoutBinding(textureInfo.TextureId, vertextArray, opacity);

            GL.PopMatrix();
            GL.BindTexture(All.Texture2D, 0);
            GL.Disable(All.Texture2D);
        }
开发者ID:pauldendulk,项目名称:Mapsui,代码行数:35,代码来源:TextureHelper.cs

示例8: FiltersEventsWithLevelExactValue

        public void FiltersEventsWithLevelExactValue()
        {
            var expected = new[]
            {
                new EventExpectation
                {
                    Level = Level.Error,
                    Logger = "Root.ChildA.LoggerA1",
                    Thread = "Thread-5",
                    Timestamp = 1411231353795L,
                    Message = "#5. Test event F.",
                    Throwable = null,
                    Id = 672
                }
            };

            using (var sourceStream = new MemoryStream (sampleBytes))
            using (var source = Log4JFile.Create (sourceStream))
            using (var subject = new FilterLevel (Level.Error, Level.Error))
            {
                source.Encoding = Encoding.GetEncoding (1251);
                var actual = source.GetEvents ().Where (subject);
                Assert.That (actual, Is.EqualTo (expected));
            }
        }
开发者ID:MaxKot,项目名称:Log4JDash,代码行数:25,代码来源:FilterLevelTests.cs

示例9: IsSatisifedBy

 public bool IsSatisifedBy(string path)
 {
     var fileExt = Path.GetExtension(path);
     var extensions = new[] { "PNG", "PCX", "JPG", "JPEG", "GIF", "TIF", "BMP", "TGA", };
     if (fileExt != null && fileExt != "") fileExt = fileExt.Substring(1).ToUpper();
     return extensions.Any(extension => fileExt != null && fileExt.Equals(extension));
 }
开发者ID:bsimser,项目名称:goldbox,代码行数:7,代码来源:ImagePlugin.cs

示例10: GetPrelude

		private static string GetPrelude(DirectoryInfo dir)
		{
			var preludeFile = new[] { dir, dir.Parent }.
				SelectMany(d => d.GetFiles("prelude.*", SearchOption.TopDirectoryOnly))
				.FirstOrDefault(f => f.Exists);
			return preludeFile == null ? "" : preludeFile.ContentAsUtf8();
		}
开发者ID:andgein,项目名称:uLearn,代码行数:7,代码来源:CSharpSlideLoader.cs

示例11: ComplexTest

        public void ComplexTest()
        {
            var source =
@"{{#each nav ~}}
  <a href=""{{url}}"">
    {{~#if test}}
      {{~title}}
    {{~else~}}
      Empty
    {{~/if~}}
  </a>
{{~/each}}";
            var template = Handlebars.Compile(source);
            var data = new {
                nav = new [] {
                    new {
                        url = "https://google.com",
                        test = true,
                        title = "Google"
                    },
                    new {
                        url = "https://bing.com",
                        test = false,
                        title = "Bing"
                    }
                }
            };
            var result = template(data);
            Assert.AreEqual(@"<a href=""https://google.com"">Google</a><a href=""https://bing.com"">Empty</a>", result);
        }
开发者ID:amaclean,项目名称:Handlebars.Net,代码行数:30,代码来源:WhitespaceTests.cs

示例12: Parse

        public TextureAtlas Parse(string dataFilePath)
        {
            if (!File.Exists(dataFilePath))
            {
                throw new FileNotFoundException(nameof(dataFilePath) + $" : {dataFilePath}");
            }
            var xml = XDocument.Load(dataFilePath);
            var atlasDetails = new {
                Width = (int)xml.Element("TextureAtlas").Attribute("width"),
                Height = (int)xml.Element("TextureAtlas").Attribute("height"),
                TextureRegions = from s in xml.Root.Descendants("sprite")
                    select new {
                        X = (int)s.Attribute("x"),
                        Y = (int)s.Attribute("y"),
                        Width = (int)s.Attribute("w"),
                        Height = (int)s.Attribute("h")
                    }
            };

            var textureAtlas = new TextureAtlas(atlasDetails.Width, atlasDetails.Height);
            foreach (var region in atlasDetails.TextureRegions)
            {
                textureAtlas.Add(new TextureRegion(region.X, region.Y, region.Width, region.Height));
            }
            return textureAtlas;
        }
开发者ID:rmckirby,项目名称:XogoEngine,代码行数:26,代码来源:TexturePackerParser.cs

示例13: non_dotnet_files_are_skipped

        public void non_dotnet_files_are_skipped()
        {
            var assemblyScanner = new AssemblyScanner(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestDlls"));

            var results = assemblyScanner
                .GetScannableAssemblies();

            var skippedFiles = results.SkippedFiles;

            var notProperDotNetDlls = new[]
                {
                    "libzmq-v120-mt-3_2_3.dll",
                    "Tail.exe",
                    "some_random.dll",
                    "some_random.exe"
                };

            foreach (var notProperDll in notProperDotNetDlls)
            {
                var skippedFile = skippedFiles.FirstOrDefault(f => f.FilePath.Contains(notProperDll));

                if (skippedFile == null)
                {
                    throw new AssertionException($"Could not find skipped file matching {notProperDll}");
                }

                Assert.That(skippedFile.SkipReason, Contains.Substring("not a .NET assembly"));
            }
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:29,代码来源:When_directory_with_non_dot_net_dll_is_scanned.cs

示例14: TransformImpl

        protected TribitPyramid TransformImpl(TribitPyramid tribitPyramid)
        {
            var indices = tribitPyramid.GetPyramidIndices();
            var bitscnt = new[] { 0, 0 };
            for (var i = 0; i < indices.Length; ++i) {
                var triange = tribitPyramid[indices[i]];
                var tribitPyramidRule = TribitPyramidRule.GetBy(triange);
                if (tribitPyramidRule != null) {
                    tribitPyramid[indices[i]] = tribitPyramidRule.To;
                }
                else {
                    bitscnt[triange[0]]++;
                }
            }
            if (bitscnt[0] + bitscnt[1] == indices.Length) {
                if (bitscnt[0] == 0) return new TribitPyramid(1);
                if (bitscnt[1] == 0) return new TribitPyramid(0);

                var bits = new byte[tribitPyramid.Count >> 2];
                for (var i = 0; i < bits.Length; ++i) {
                    bits[i] = tribitPyramid[indices[i]][0];
                }
                return new TribitPyramid(bits);
            }
            return tribitPyramid;
        }
开发者ID:steelmaker,项目名称:interview,代码行数:26,代码来源:TribitPyramidTransformer.cs

示例15: DownloadFile

 public void DownloadFile()
 {
     var path = packet.args.First().ToString();
     if (File.Exists(path))
     {
         var fileName = Path.GetFileName(path);
         var size = new FileInfo(path).Length;
         var data = new
         {
             fileValid = true,
             fileName,
             size
         };
         serializator.Serialize(_client, packet.endpoint, packet.syncKey, data);
         serializator.PushFile(_client, path);
     }
     else
     {
         var data = new
         {
             fileValid = false
         };
         serializator.Serialize(_client, packet.endpoint, packet.syncKey, data);
     }
 }
开发者ID:jakop345,项目名称:ulterius-server,代码行数:25,代码来源:FileController.cs


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