同时,该元素会自动成为 Flex 容器,简称容器。且容器的所有子元素会自动成为 Flex 容器成员,简称项目。项目的float、clear、vertical-align属性将失效。 容器中默认存在两根轴:主轴和交叉轴。主轴和交叉轴互相垂直,类似于平面坐标系中的 x 轴和 y 轴。项目将自动沿着主轴方向排列,排满时将沿交叉轴方向堆砌,即在交叉轴方向上换行(前提是容器flex-wrap属性不为nowrap)。
flex-basis 定义了该元素的空间大小(the size of that item in terms of the space),flex 容器里除了元素所占的空间以外的富余空间就是可用空间 available space。该属性的默认值是 auto 。此时,浏览器会检测这个元素是否具有确定的尺寸。在上面的例子中,所有元素都设定了宽度(width)为 100px,所以 flex-basis 的值为 100px。
using (TextWriter w = File.CreateText ("but.txt")) // Use default UTF-8 w.WriteLine ("but-"); // encoding. using (Stream s = File.OpenRead ("but.txt")) for (int b; (b = s.ReadByte()) > ?1;) Console.WriteLine (b);
98// b 117// u 116// t 226// em dash byte 1 Note that the byte values 128// em dash byte 2 are >= 128 for each part 148// em dash byte 3 of the multibyte sequence. 13// <CR> 10// <LF>
publicvoidSaveData (Stream s) { var w = new BinaryWriter (s); w.Write (Name); w.Write (Age); w.Write (Height); w.Flush(); // Ensure the BinaryWriter buffer is cleared. // We won't dispose/close it, so more data } // can be written to the stream.
publicvoidLoadData (Stream s) { var r = new BinaryReader (s); Name = r.ReadString(); Age = r.ReadInt32(); Height = r.ReadDouble(); }
BinaryReader 也可以读入字节数组。下面读取一个可搜索流的全部内容:
1 2
byte[] data = new BinaryReader (s).ReadBytes ((int) s.Length);
string filePath = @"c:\temp\test.txt"; FileAttributes fa = File.GetAttributes (filePath); if ((fa & FileAttributes.ReadOnly) > 0) { fa ^= FileAttributes.ReadOnly; File.SetAttributes (filePath, fa); } // Now we can delete the file, for instance: File.Delete (filePath);
using (TextReader reader = new StringReader(text)) { while (reader.Peek() != -1) { Console.WriteLine("Peek = {0}", (char)reader.Peek()); Console.WriteLine("Read = {0}", (char)reader.Read()); } reader.Close(); }
using (TextReader reader = new StringReader(text)) { char[] charBuffer = newchar[3]; int data = reader.ReadBlock(charBuffer, 0, 3); for (int i = 0; i < charBuffer.Length; i++) { Console.WriteLine("通过readBlock读出的数据:{0}", charBuffer[i]); } reader.Close(); }
using (TextReader reader = new StringReader(text)) { string lineData = reader.ReadLine(); Console.WriteLine("第一行的数据为:{0}", lineData); reader.Close(); }
using (TextReader reader = new StringReader(text)) { string allData = reader.ReadToEnd(); Console.WriteLine("全部的数据为:{0}", allData); reader.Close(); }
直接报一个这个错System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.大致的意思就是同步操作不被允许,请使用ReadAsync的方式或设置AllowSynchronousIO为true。
publicasync Task<IActionResult> UploadDatabase() { if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { ModelState.AddModelError("File", $"The request couldn't be processed (Error 1)."); // Log error
return BadRequest(ModelState); }
// Accumulate the form data key-value pairs in the request (formAccumulator). var formAccumulator = new KeyValueAccumulator(); var trustedFileNameForDisplay = string.Empty; var untrustedFileNameForStorage = string.Empty; var streamedFileContent = Array.Empty<byte>();
var boundary = MultipartRequestHelper.GetBoundary( MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit); var reader = new MultipartReader(boundary, HttpContext.Request.Body);
var section = await reader.ReadNextSectionAsync();
while (section != null) { var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse( section.ContentDisposition, outvar contentDisposition);
if (hasContentDispositionHeader) { if (MultipartRequestHelper .HasFileContentDisposition(contentDisposition)) { untrustedFileNameForStorage = contentDisposition.FileName.Value; // Don't trust the file name sent by the client. To display // the file name, HTML-encode the value. trustedFileNameForDisplay = WebUtility.HtmlEncode( contentDisposition.FileName.Value);
if (!ModelState.IsValid) { return BadRequest(ModelState); } } elseif (MultipartRequestHelper .HasFormDataContentDisposition(contentDisposition)) { // Don't limit the key name length because the // multipart headers length limit is already in effect. var key = HeaderUtilities .RemoveQuotes(contentDisposition.Name).Value; var encoding = GetEncoding(section);
if (encoding == null) { ModelState.AddModelError("File", $"The request couldn't be processed (Error 2)."); // Log error
return BadRequest(ModelState); }
using (var streamReader = new StreamReader( section.Body, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true)) { // The value length limit is enforced by // MultipartBodyLengthLimit varvalue = await streamReader.ReadToEndAsync();
if (string.Equals(value, "undefined", StringComparison.OrdinalIgnoreCase)) { value = string.Empty; }
formAccumulator.Append(key, value);
if (formAccumulator.ValueCount > _defaultFormOptions.ValueCountLimit) { // Form key count limit of // _defaultFormOptions.ValueCountLimit // is exceeded. ModelState.AddModelError("File", $"The request couldn't be processed (Error 3)."); // Log error
return BadRequest(ModelState); } } } }
// Drain any remaining section body that hasn't been consumed and // read the headers for the next section. section = await reader.ReadNextSectionAsync(); }
// Bind form data to the model var formData = new FormData(); var formValueProvider = new FormValueProvider( BindingSource.Form, new FormCollection(formAccumulator.GetResults()), CultureInfo.CurrentCulture); var bindingSuccessful = await TryUpdateModelAsync(formData, prefix: "", valueProvider: formValueProvider);
if (!bindingSuccessful) { ModelState.AddModelError("File", "The request couldn't be processed (Error 5)."); // Log error
return BadRequest(ModelState); }
// **WARNING!** // In the following example, the file is saved without // scanning the file's contents. In most production // scenarios, an anti-virus/anti-malware scanner API // is used on the file before making the file available // for download or for use by other systems. // For more information, see the topic that accompanies // this sample app.