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


C# XmlWriter.WriteStringAsync方法代码示例

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


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

示例1: ToXml

        private static async Task ToXml(object obj, XmlWriter writer, SerializerOptions options = null)
        {
            var type = obj.GetType();
            var typeInfo = type.GetTypeInfo();

            if (typeInfo.IsPrimitive || type == typeof(string) || type == typeof(decimal))
            {
                await writer.WriteStringAsync(Convert.ToString(obj, CultureInfo.InvariantCulture));
            }
            else if (typeInfo.IsEnum)
            {
                await writer.WriteStringAsync(Enum.GetName(type, obj));
            }
            else if (type == typeof(DateTime))
            {
                var format = DateFormatForOptions(options);
                await writer.WriteStringAsync(((DateTime)obj).ToString(format));
            }
            else if (typeInfo.ImplementedInterfaces.Contains(typeof(IEnumerable)))
            {
                foreach (var val in (IEnumerable) obj)
                {
                    await writer.WriteStartElementAsync(null, NameForType(val.GetType()), null);
                    await ToXml(val, writer);
                    await writer.WriteEndElementAsync();
                }
            }
            else
            { 
                foreach(var property in type.GetRuntimeProperties())
                {
                    SerializerOptions opt = null;
                    var ignoreAttr = property.GetCustomAttribute<XmlIgnoreAttribute>();
                    var isStatic = property.GetMethod.IsStatic;
                    if (ignoreAttr != null || isStatic)
                    {
                        continue;
                    }

                    var attr = property.GetCustomAttribute<XmlElementAttribute>();
                    if (attr != null)
                    {
                        opt = new SerializerOptions { DataType = attr.DataType, };
                    }

                    var value = property.GetMethod.Invoke(obj, new object[0]);
                    await writer.WriteStartElementAsync(null, property.Name, null);
                    if (value != null)
                    {
                        await ToXmlNode(value, writer, opt);
                    }
                    await writer.WriteEndElementAsync();
                }
            }

        }
开发者ID:wastaz,项目名称:SillyXml,代码行数:56,代码来源:XmlSerializer.cs

示例2: ReplayAsync

            internal async Task ReplayAsync(XmlWriter writer)
            {
                if (_singleStringValue != null)
                {
                    await writer.WriteStringAsync(_singleStringValue).ConfigureAwait(false);
                    return;
                }

                BufferChunk bufChunk;
                for (int i = _firstItem; i <= _lastItem; i++)
                {
                    Item item = _items[i];
                    switch (item.type)
                    {
                        case ItemType.EntityRef:
                            await writer.WriteEntityRefAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.CharEntity:
                            await writer.WriteCharEntityAsync((char)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.SurrogateCharEntity:
                            char[] chars = (char[])item.data;
                            await writer.WriteSurrogateCharEntityAsync(chars[0], chars[1]).ConfigureAwait(false);
                            break;
                        case ItemType.Whitespace:
                            await writer.WriteWhitespaceAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.String:
                            await writer.WriteStringAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.StringChars:
                            bufChunk = (BufferChunk)item.data;
                            await writer.WriteCharsAsync(bufChunk.buffer, bufChunk.index, bufChunk.count).ConfigureAwait(false);
                            break;
                        case ItemType.Raw:
                            await writer.WriteRawAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.RawChars:
                            bufChunk = (BufferChunk)item.data;
                            await writer.WriteCharsAsync(bufChunk.buffer, bufChunk.index, bufChunk.count).ConfigureAwait(false);
                            break;
                        case ItemType.ValueString:
                            await writer.WriteStringAsync((string)item.data).ConfigureAwait(false);
                            break;
                        default:
                            Debug.Assert(false, "Unexpected ItemType value.");
                            break;
                    }
                }
            }
开发者ID:ChuangYang,项目名称:corefx,代码行数:50,代码来源:XmlWellformedWriterHelpersAsync.cs

示例3: WriteDeclAsync

 internal async Task WriteDeclAsync(XmlWriter writer, XmlRawWriter rawWriter) {
     Debug.Assert(kind == NamespaceKind.NeedToWrite);
     if (null != rawWriter) {
         await rawWriter.WriteNamespaceDeclarationAsync(prefix, namespaceUri).ConfigureAwait(false);
     }
     else {
         if (prefix.Length == 0) {
             await writer.WriteStartAttributeAsync(string.Empty, "xmlns", XmlReservedNs.NsXmlNs).ConfigureAwait(false);
         }
         else {
             await writer.WriteStartAttributeAsync("xmlns", prefix, XmlReservedNs.NsXmlNs).ConfigureAwait(false);
         }
         await writer.WriteStringAsync(namespaceUri).ConfigureAwait(false);
         await writer.WriteEndAttributeAsync().ConfigureAwait(false);
     }
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:16,代码来源:XmlWellformedWriterHelpersAsync.cs

示例4: RenderAsync

        public static async Task RenderAsync(XmlWriter writer, params SpeedBarItem[] items)
        {
            if (items == null || items.Length == 0)
                return;

            await writer.WriteStartElementAsync("ul");
            await writer.WriteAttributeStringAsync("id", "SpeedList");

            foreach (var item in items)
            {
                await writer.WriteStartElementAsync("li");

                await writer.WriteStartElementAsync("a");
                await writer.WriteAttributeStringAsync("href", item.Url);
                await writer.WriteAttributeStringAsync("title", item.Title);
                await writer.WriteStringAsync(item.Label);
                await writer.WriteEndElementAsync();

                await writer.WriteEndElementAsync();
            }

            await writer.WriteEndElementAsync();
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:23,代码来源:SpeedBarComponent.cs

示例5: RenderPageNavigatorsAsync

        private async Task RenderPageNavigatorsAsync(XmlWriter writer)
        {
            await writer.WriteStartElementAsync("p");
            {
                var nextPageIndex = pageIndex + 1;
                var moreErrors = nextPageIndex*pageSize < totalCount;

                if (moreErrors)
                {
                    await writer.WriteStartElementAsync("a");
                    await writer.WriteAttributeStringAsync("href", $"{BasePageName}?page={nextPageIndex + 1}&size={pageSize}");
                    await writer.WriteAttributeStringAsync("rel", "next");
                    {
                        await writer.WriteStringAsync("Next errors");
                    }
                    await writer.WriteEndElementAsync();
                }

                // If not on the first page then render a link to the firs page.

                if (pageIndex > 0 && totalCount > 0)
                {
                    if (moreErrors)
                        await writer.WriteRawAsync("; ");

                    await writer.WriteStartElementAsync("a");
                    await writer.WriteAttributeStringAsync("href", $"{BasePageName}?page=1&size={pageSize}");
                    await writer.WriteAttributeStringAsync("rel", "start");
                    {
                        await writer.WriteStringAsync("Back to first page");
                    }
                    await writer.WriteEndElementAsync();
                }
            }
            await writer.WriteEndElementAsync();
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:36,代码来源:ErrorLogViewMiddleware.cs

示例6: RenderErrorsAsync

        private async Task RenderErrorsAsync(XmlWriter writer)
        {
            //
            // Create a table to display error information in each row.
            //

            await writer.WriteStartElementAsync("table");
            await writer.WriteAttributeStringAsync("id", "ErrorLog");
            await writer.WriteAttributeStringAsync("style", "border-spacing: 0;");
            {

                //
                // Create the table row for headings.
                //

                await writer.WriteStartElementAsync("tr");
                {
                    await RenderCellAsync(writer, "th", "Host", "host-col");
                    await RenderCellAsync(writer, "th", "Code", "code-col");
                    await RenderCellAsync(writer, "th", "Type", "type-col");
                    await RenderCellAsync(writer, "th", "Error", "error-col");
                    await RenderCellAsync(writer, "th", "User", "user-col");
                    await RenderCellAsync(writer, "th", "Date", "date-col");
                    await RenderCellAsync(writer, "th", "Time", "time-col");
                }
                await writer.WriteEndElementAsync();

                //
                // Generate a table body row for each error.
                //

                for (int index = 0; index < errorLogEntries.Count; index++)
                {
                    var errorLogEntry = errorLogEntries[index];

                    await writer.WriteStartElementAsync("tr");
                    await writer.WriteAttributeStringAsync("class", index % 2 == 0 ? "even-row" : "odd-row");
                    {
                        // Format host and status code cells.

                        var error = errorLogEntry.Error;

                        await RenderCellAsync(writer, "td", error.HostName, "host-col");
                        await RenderCellAsync(writer, "td", error.StatusCode.ToString(), "code-col", HttpCodeParser.GetstatusDescription(error.StatusCode));
                        await RenderCellAsync(writer, "td", ErrorShortName(error.TypeName), "host-col", error.TypeName);

                        //
                        // Format the message cell, which contains the message 
                        // text and a details link pointing to the page where
                        // all error details can be viewed.
                        //

                        await writer.WriteStartElementAsync("td");
                        await writer.WriteAttributeStringAsync("class", "error-col");
                        {
                            await writer.WriteStartElementAsync("label");
                            {
                                await writer.WriteStringAsync(error.Message);
                            }
                            await writer.WriteEndElementAsync();

                            await writer.WriteStartElementAsync("a");
                            await writer.WriteAttributeStringAsync("href", $"{BasePageName}/detail?id={errorLogEntry.Id}");
                            {
                                await writer.WriteRawAsync("Details&hellip;");
                            }
                            await writer.WriteEndElementAsync();
                        }
                        await writer.WriteEndElementAsync();

                        // Format the user, date and time cells.
                        await RenderCellAsync(writer, "td", error.User, "user-col");
                        await RenderCellAsync(writer, "td", error.Time.DateTime.ToShortDateString(), "date-col", error.Time.DateTime.ToLongDateString());
                        await RenderCellAsync(writer, "td", error.Time.DateTime.ToShortTimeString(), "time-col", error.Time.DateTime.ToLongTimeString());

                    }
                    await writer.WriteEndElementAsync();
                }
            }
            await writer.WriteEndElementAsync();
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:81,代码来源:ErrorLogViewMiddleware.cs

示例7: RenderTitleAsync

        private async Task RenderTitleAsync(XmlWriter writer)
        {
            await writer.WriteStartElementAsync("h1");
            await writer.WriteAttributeStringAsync("id", "PageTitle");
            await writer.WriteStringAsync("Error Log for ");

            await writer.WriteStartElementAsync("span");
            await writer.WriteAttributeStringAsync("id", "ApplicationName");
            await writer.WriteAttributeStringAsync("title", ApplicationName);
            await writer.WriteStringAsync(ApplicationName);

            var machineName = EnvironmentUtilities.GetMachineNameOrDefault();
            if (!string.IsNullOrEmpty(machineName?.Trim()))
            {
                await writer.WriteStringAsync(" on ");
                await writer.WriteStringAsync(machineName);
            }

            await writer.WriteEndElementAsync(); // </span>

            await writer.WriteEndElementAsync(); // </h1>
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:22,代码来源:ErrorLogViewMiddleware.cs

示例8: RenderNoErrorsAsync

        private async Task RenderNoErrorsAsync(XmlWriter writer)
        {
            await writer.WriteStartElementAsync("p");

            await writer.WriteStringAsync("No errors found. ");

            //
            // It is possible that there are no error at the requested 
            // page in the log (especially if it is not the first page).
            // However, if there are error in the log
            //

            if (pageIndex > 0 && totalCount > 0)
            {
                var href = $"{BasePageName}?page=1&size={pageSize}";

                await writer.WriteStartElementAsync("a");
                await writer.WriteAttributeStringAsync("href", href);
                await writer.WriteAttributeStringAsync("rel", "start");

                await writer.WriteStringAsync("Go to first page");
                await writer.WriteEndElementAsync();

                await writer.WriteStringAsync(". ");
            }

            await writer.WriteEndElementAsync();
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:28,代码来源:ErrorLogViewMiddleware.cs

示例9: RenderStockPageSizesAsync

        private async Task RenderStockPageSizesAsync(XmlWriter writer)
        {
            //
            // Write out a set of stock page size choices. Note that
            // selecting a stock page size re-starts the log 
            // display from the first page to get the right paging.
            //

            await writer.WriteStringAsync("Start with ");

            var stockSizes = new[] { 10, 15, 20, 25, 30, 50, 100 };

            for (var stockSizeIndex = 0; stockSizeIndex < stockSizes.Length; stockSizeIndex++)
            {
                var stockSize = stockSizes[stockSizeIndex];

                if (stockSizeIndex > 0)
                    await writer.WriteStringAsync(stockSizeIndex + 1 < stockSizes.Length ? ", " : " or ");

                var href = $"{BasePageName}?page=1&size={stockSize}";

                await writer.WriteStartElementAsync("a");
                await writer.WriteAttributeStringAsync("href", href);
                await writer.WriteAttributeStringAsync("rel", "start");

                await writer.WriteStringAsync(stockSize.ToString());
                await writer.WriteEndElementAsync();
            }

            await writer.WriteStringAsync(" errors per page.");
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:31,代码来源:ErrorLogViewMiddleware.cs

示例10: RenderStatsAsync

        private async Task RenderStatsAsync(XmlWriter writer)
        {
            var firstErrorNumber = pageIndex * pageSize + 1;
            var lastErrorNumber = firstErrorNumber + errorLogEntries.Count - 1;
            var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);

            await writer.WriteStringAsync($"Errors {firstErrorNumber} to {lastErrorNumber} of total {totalCount} (page {(pageIndex + 1)} of {totalPages}). ");
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:8,代码来源:ErrorLogViewMiddleware.cs

示例11: RenderCellAsync

        private static async Task RenderCellAsync(XmlWriter writer, string cellType, string contents, string cssClassName, string tooltip = "")
        {
            await writer.WriteStartElementAsync(cellType);
            await writer.WriteAttributeStringAsync("class", cssClassName);

            if (string.IsNullOrEmpty(contents?.Trim()))
            {
                await writer.WriteRawAsync("&nbsp;");
            }
            else
            {
                if (string.IsNullOrEmpty(tooltip?.Trim()))
                {
                    await writer.WriteStringAsync(contents);
                }
                else
                {
                    await writer.WriteStartElementAsync("label");
                    await writer.WriteAttributeStringAsync("title", tooltip);
                    await writer.WriteStringAsync(contents);
                    await writer.WriteEndElementAsync();
                }
            }

            await writer.WriteEndElementAsync();
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:26,代码来源:ErrorLogViewMiddleware.cs

示例12: RenderErrorAsync

        private async Task RenderErrorAsync(XmlWriter writer)
        {
            var error = errorLogEntry.Error;

            await writer.WriteStartElementAsync("h1");
            await writer.WriteAttributeStringAsync("id", "PageTitle");
            {
                await writer.WriteStringAsync(error.Message);
            }
            await writer.WriteEndElementAsync();

            await SpeedBarComponent.RenderAsync(writer, SpeedBarComponent.GetHome(BasePageName));

            await writer.WriteStartElementAsync("p");
            await writer.WriteAttributeStringAsync("id", "ErrorTitle");
            {
                await writer.WriteStartElementAsync("span");
                await writer.WriteAttributeStringAsync("id", "ErrorType");
                {
                    await writer.WriteStringAsync(error.TypeName);
                }
                await writer.WriteEndElementAsync();

                await writer.WriteStartElementAsync("span");
                await writer.WriteAttributeStringAsync("id", "ErrorTypeMessageSeparator");
                {
                    await writer.WriteStringAsync(": ");
                }
                await writer.WriteEndElementAsync();

                await writer.WriteStartElementAsync("span");
                await writer.WriteAttributeStringAsync("id", "ErrorMessage");
                {
                    await writer.WriteStringAsync(error.Message);
                }
                await writer.WriteEndElementAsync();
            }
            await writer.WriteEndElementAsync();

            await writer.WriteStartElementAsync("pre");
            await writer.WriteAttributeStringAsync("id", "ErrorDetail");
            {
                await writer.WriteStringAsync(error.Detail);
            }
            await writer.WriteEndElementAsync();

            await writer.WriteStartElementAsync("p");
            await writer.WriteAttributeStringAsync("id", "ErrorLogTime");
            {
                await writer.WriteStringAsync($"Logged on {error.Time}.");
            }
            await writer.WriteEndElementAsync();

            await writer.WriteStartElementAsync("p");
            {
                await writer.WriteStringAsync("See also:");
            }
            await writer.WriteEndElementAsync();

            await writer.WriteStartElementAsync("ul");
            {
                await writer.WriteStartElementAsync("li");
                {
                    await writer.WriteStringAsync("Raw/Source data in ");

                    await writer.WriteStartElementAsync("a");
                    await writer.WriteAttributeStringAsync("href", "json" + requestQuery);
                    await writer.WriteAttributeStringAsync("rel", "alternate");
                    await writer.WriteAttributeStringAsync("type", "application/json");
                    {
                        await writer.WriteStringAsync("JSON");
                    }
                    await writer.WriteEndElementAsync();
                }
                await writer.WriteEndElementAsync();
            }
            await writer.WriteEndElementAsync();

            await RenderDictionaryAsync(writer, error.ServerEnvironment, "ServerVariables", "Server Environment");
            await RenderDictionaryAsync(writer, error.Headers.ToDictionary(pair => pair.Key, pair => string.Join(", ", pair.Value)), "ServerVariables", "Headers");
            await RenderDictionaryAsync(writer, error.Query.ToDictionary(pair => pair.Key, pair => string.Join(", ", pair.Value)), "ServerVariables", "Query");
            await RenderDictionaryAsync(writer, error.Cookies, "ServerVariables", "Cookies");
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:83,代码来源:ErrorDetailViewMiddleware.cs

示例13: RenderNoErrorAsync

 private static async Task RenderNoErrorAsync(XmlWriter writer)
 {
     await writer.WriteStartElementAsync("p");
     await writer.WriteStringAsync("Error not found in log.");
     await writer.WriteEndElementAsync();
 }
开发者ID:Eonix,项目名称:Elmo,代码行数:6,代码来源:ErrorDetailViewMiddleware.cs

示例14: RenderDictionaryAsync

        private static async Task RenderDictionaryAsync(XmlWriter writer, Dictionary<string, string> dictionary, string id, string title)
        {
            if (!dictionary.Any())
                return;

            await writer.WriteStartElementAsync("div");
            await writer.WriteAttributeStringAsync("id", id);
            {
                await writer.WriteStartElementAsync("p");
                await writer.WriteAttributeStringAsync("class", "table-caption");
                {
                    await writer.WriteStringAsync(title);
                }
                await writer.WriteEndElementAsync();

                await writer.WriteStartElementAsync("div");
                await writer.WriteAttributeStringAsync("class", "scroll-view");
                {
                    await writer.WriteStartElementAsync("table");
                    {
                        await writer.WriteStartElementAsync("tr");
                        {
                            await writer.WriteStartElementAsync("th");
                            await writer.WriteAttributeStringAsync("class", "name-col");
                            {
                                await writer.WriteStringAsync("Name");
                            }
                            await writer.WriteEndElementAsync();

                            await writer.WriteStartElementAsync("th");
                            await writer.WriteAttributeStringAsync("class", "value-col");
                            {
                                await writer.WriteStringAsync("Value");
                            }
                            await writer.WriteEndElementAsync();
                        }
                        await writer.WriteEndElementAsync();

                        var count = 0;
                        foreach (var line in dictionary)
                        {
                            await writer.WriteStartElementAsync("tr");
                            await writer.WriteAttributeStringAsync("class", count%2 == 0 ? "even-row" : "odd-row");
                            {
                                await writer.WriteStartElementAsync("td");
                                await writer.WriteAttributeStringAsync("class", "key-col");
                                {
                                    await writer.WriteStringAsync(line.Key);
                                }
                                await writer.WriteEndElementAsync();

                                await writer.WriteStartElementAsync("td");
                                await writer.WriteAttributeStringAsync("class", "value-col");
                                {
                                    await writer.WriteStringAsync(line.Value);
                                }
                                await writer.WriteEndElementAsync();
                            }
                            await writer.WriteEndElementAsync();
                        }
                    }
                    await writer.WriteEndElementAsync();
                }
                await writer.WriteEndElementAsync();
            }
            await writer.WriteEndElementAsync();

            await writer.WriteElementStringAsync("br", string.Empty);
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:69,代码来源:ErrorDetailViewMiddleware.cs

示例15: RenderDocumentEndAsync

        private async Task RenderDocumentEndAsync(XmlWriter writer)
        {
            //
            // Write the powered-by signature, that includes version information.
            //

            await writer.WriteStartElementAsync("p"); // <p>
            await writer.WriteAttributeStringAsync("id", "Footer");


            //PoweredBy poweredBy = new PoweredBy();
            //poweredBy.RenderControl(writer);

            //
            // Write out server date, time and time zone details.
            //

            var now = DateTime.Now;

            await writer.WriteStringAsync("Server date is ");
            await writer.WriteStringAsync(now.ToString("D", CultureInfo.InvariantCulture));

            await writer.WriteStringAsync(". Server time is ");
            await writer.WriteStringAsync(now.ToString("T", CultureInfo.InvariantCulture));

            await writer.WriteStringAsync(". All dates and times displayed are in the ");
            await writer.WriteStringAsync(TimeZone.CurrentTimeZone.IsDaylightSavingTime(now) ?
                TimeZone.CurrentTimeZone.DaylightName : TimeZone.CurrentTimeZone.StandardName);
            await writer.WriteStringAsync(" zone. ");

            //
            // Write out the source of the log.
            //

            await writer.WriteStringAsync("This log is provided by the ");
            await writer.WriteStringAsync(ErrorLog.Name);
            await writer.WriteStringAsync(".");

            await writer.WriteEndElementAsync();// </p>

            await writer.WriteEndElementAsync(); // </body>
            await writer.WriteEndElementAsync(); // </html>
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:43,代码来源:ErrorViewBaseMiddleware.cs


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