本文整理汇总了C#中Parameters.GetNames方法的典型用法代码示例。如果您正苦于以下问题:C# Parameters.GetNames方法的具体用法?C# Parameters.GetNames怎么用?C# Parameters.GetNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameters
的用法示例。
在下文中一共展示了Parameters.GetNames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParametersToPDL
/// <summary>
/// Converts a <see cref="Parameters"/> to a PDL gramma formatted <b>string</b>.
/// </summary>
/// <param name="data">The <see cref="Parameters"/> to be converted.</param>
/// <param name="cooked">Set <b>true</b> to create a string formatted for human reading.</param>
/// <param name="indent">The indent for human readability.</param>
/// <returns>The <b>string</b> containing the converted <paramref name="data"/>.</returns>
public static string ParametersToPDL(Parameters data, bool cooked = false, string indent = "")
{
StringBuilder ret = new StringBuilder();
if (cooked) ret.Append("{\r\n");
else ret.Append('{');
bool wasItem = false;
string[] names = data.GetNames();
for (int i = 0; i < names.Length; i++)
{
string name = names[i];
object value = data.Get(name);
if (cooked)
{
string newIndent = indent + '\t';
try
{
string val = "";
if (value is long) val = value.ToString();
else if (value is double)
{
val = ((double)value).ToString("G16", NeutralCulture);
}
else if (value is string) val = StringToPDL((string)value);
else if (value is bool) val = ((bool)value) ? "true" : "false";
else if (value is byte[]) val = DataBlobToPDL((byte[])value, true);
else if (value is Parameters) val = ParametersToPDL((Parameters)value, true, newIndent);
else if (value is List<string>) val = StringListToPDL((List<string>)value, true, newIndent);
else if (value is List<Parameters>) val = ParametersListToPDL((List<Parameters>)value, true, newIndent);
else if (value is List<long>) val = IntegerListToPDL((List<long>)value, true, newIndent);
else if (value is List<double>) val = FloatListToPDL((List<double>)value, true, newIndent);
else if (value is List<bool>) val = BooleanListToPDL((List<bool>)value, true, newIndent);
if (val.Length > 0)
{
ret.Append(newIndent);
ret.Append(name);
ret.Append('=');
ret.Append(val);
ret.Append(";\r\n");
wasItem = true;
}
}
catch
{
} // ignore
}
else
{
try
{
string val = "";
if (value is long) val = value.ToString();
else if (value is double)
{
val = value.ToString();
val = val.Replace(',', '.');
}
else if (value is string) val = StringToPDL((string)value);
else if (value is bool) val = ((bool)value) ? "true" : "false";
else if (value is byte[]) val = DataBlobToPDL((byte[])value, false);
else if (value is Parameters) val = ParametersToPDL((Parameters)value);
else if (value is List<string>) val = StringListToPDL((List<string>)value, false, indent);
else if (value is List<Parameters>) val = ParametersListToPDL((List<Parameters>)value, false, indent);
else if (value is List<long>) val = IntegerListToPDL((List<long>)value, false, indent);
else if (value is List<double>) val = FloatListToPDL((List<double>)value, false, indent);
else if (value is List<bool>) val = BooleanListToPDL((List<bool>)value, false, indent);
if (val.Length > 0)
{
ret.Append(name);
ret.Append('=');
ret.Append(val);
ret.Append(';');
wasItem = true;
}
}
catch
{
} // ignore
}
}
if (!wasItem) return "";
if (cooked) ret.Append(indent);
ret.Append('}');
return ret.ToString();
//.........这里部分代码省略.........