本文整理汇总了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));
}
示例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());
}
示例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;
}
示例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]);
});
}
}
示例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] );
}
示例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);
}
示例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);
}
示例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));
}
}
示例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));
}
示例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();
}
示例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);
}
示例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;
}
示例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"));
}
}
示例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;
}
示例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);
}
}