本文整理汇总了C#中System.IO.StringWriter.WriteFormat方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.WriteFormat方法的具体用法?C# StringWriter.WriteFormat怎么用?C# StringWriter.WriteFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringWriter
的用法示例。
在下文中一共展示了StringWriter.WriteFormat方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToHeaderString
public static string ToHeaderString(this IList<EmailContact> contacts)
{
if (contacts.Count == 0) {
return string.Empty;
}
using (var sw = new StringWriter()) {
foreach (var contact in contacts) {
sw.WriteFormat("{0} <{1}>,", contact.Name, contact.Address);
}
sw.TrimEnd(',');
return sw.ToString();
}
}
示例2: ReadOnlyDictionaryOverloadTest
public void ReadOnlyDictionaryOverloadTest()
{
var now = DateTime.Now;
var keyValues = new Dictionary<string, object>()
{
{ "abc", 123 },
{ "defgh", now },
{ "ijkl", "XYZ" }
};
var tw = new StringWriter();
tw.WriteFormat(
"AAA{defgh}BBB{abc}CCC{ijkl}DDD",
keyValues);
Assert.AreEqual("AAA" + now + "BBB123CCCXYZDDD", tw.ToString());
}
示例3: DictionaryWithComparerOverloadTest
public void DictionaryWithComparerOverloadTest()
{
var now = DateTime.Now;
IDictionary<string, object> keyValues = new Dictionary<string, object>(
StringComparer.InvariantCultureIgnoreCase)
{
{ "aBc", 123 },
{ "dEFgh", now },
{ "ijKl", "XYZ" }
};
var tw = new StringWriter();
tw.WriteFormat(
"AAA{Defgh}BBB{abC}CCC{IjkL}DDD",
keyValues);
Assert.AreEqual("AAA" + now + "BBB123CCCXYZDDD", tw.ToString());
}
示例4: EnumerableOverloadWithComparerTest
public void EnumerableOverloadWithComparerTest()
{
var now = DateTime.Now;
IEnumerable<KeyValuePair<string, object>> keyValues = new[]
{
new KeyValuePair<string, object>("aBc", 123),
new KeyValuePair<string, object>("deFgH", now),
new KeyValuePair<string, object>("iJKl", "XYZ"),
};
var tw = new StringWriter();
tw.WriteFormat(
"AAA{Defgh}BBB{abC}CCC{IjkL}DDD",
StringComparer.InvariantCultureIgnoreCase,
keyValues);
Assert.AreEqual("AAA" + now + "BBB123CCCXYZDDD", tw.ToString());
}
示例5: EnumerableOverloadWithNoListTest
public void EnumerableOverloadWithNoListTest()
{
var now = DateTime.Now;
var keyValues = new[]
{
Tuple.Create("abc", (object)123),
Tuple.Create("defgh", (object)now),
Tuple.Create("ijkl", (object)"XYZ")
}.
Select(entry => new KeyValuePair<string, object>(entry.Item1, entry.Item2));
var tw = new StringWriter();
tw.WriteFormat(
"AAA{defgh}BBB{abc}CCC{ijkl}DDD",
keyValues);
Assert.AreEqual("AAA" + now + "BBB123CCCXYZDDD", tw.ToString());
}
示例6: EnumerableOverloadWithArrayTest
public void EnumerableOverloadWithArrayTest()
{
var now = DateTime.Now;
IEnumerable<KeyValuePair<string, object>> keyValues = new[]
{
new KeyValuePair<string, object>("abc", 123),
new KeyValuePair<string, object>("defgh", now),
new KeyValuePair<string, object>("ijkl", "XYZ"),
};
var tw = new StringWriter();
tw.WriteFormat(
"AAA{defgh}BBB{abc}CCC{ijkl}DDD",
keyValues);
Assert.AreEqual("AAA" + now + "BBB123CCCXYZDDD", tw.ToString());
}
示例7: GetAuthorizationUri
public Uri GetAuthorizationUri()
{
string url;
using (var sw = new StringWriter()) {
sw.Write(RequestEndpoint.AbsoluteUri);
if (Parameters.Count > 0) {
sw.Write("?");
foreach (var p in Parameters) {
sw.WriteFormat("{0}={1}&", p.Key, p.Value);
}
sw.TrimEnd('&');
}
url = sw.ToString();
}
var request = (HttpWebRequest) WebRequest.Create(url);
request.Accept = "*/*";
request.Method = "GET";
var response = request.GetResponse();
return response.ResponseUri;
}
示例8: CreateXOAuthKey
public string CreateXOAuthKey()
{
var requestParams = CreateOAuthRequestParams();
if (_sign) {
var signature = OAuthSignature.Create(this, requestParams);
requestParams.Add(OAuthParameters.OAuthSignature, signature);
}
string token;
using (var sw = new StringWriter()) {
sw.Write("GET ");
sw.Write(RequestEndpoint.AbsoluteUri);
sw.Write(Characters.Space);
var sorted = new SortedDictionary<string, string>();
foreach (var p in Parameters) {
sorted.Add(p.Key, p.Value);
}
foreach (var p in requestParams) {
sorted.Add(p.Key, p.Value);
}
foreach (var p in sorted) {
sw.WriteFormat("{0}=\"{1}\",", p.Key, p.Value);
}
sw.TrimEnd(',');
token = sw.ToString();
}
var bytes = Encoding.ASCII.GetBytes(token);
return Convert.ToBase64String(bytes);
}
示例9: CreateBaseString
private static string CreateBaseString(IEnumerable<char> url, IEnumerable<KeyValuePair<string, string>> requestParams, IEnumerable<KeyValuePair<string, string>> additional)
{
var combined = new SortedDictionary<string, string>();
foreach (var p in requestParams) {
combined.Add(p.Key, p.Value);
}
foreach (var p in additional) {
combined.Add(p.Key, HttpEncoder.UrlEncode(p.Value));
}
var requestString = NormalizeRequestParameters(combined);
using (var sw = new StringWriter()) {
sw.Write("GET&");
sw.WriteFormat("{0}&", HttpEncoder.UrlEncode(url));
sw.WriteFormat("{0}", HttpEncoder.UrlEncode(requestString));
return sw.ToString();
}
}