32 namespace Ntp.Analyzer.Config.Compiler
58 public bool ShowDefaultValues {
get;
set; }
64 public char IndentChar {
get;
set; }
70 public int IndentSize {
get;
set; }
78 builder =
new StringBuilder();
80 return builder.ToString();
87 case DateTimeKind.Local:
90 case DateTimeKind.Utc:
91 case DateTimeKind.Unspecified:
106 builder.Append(
string.Empty.PadLeft(size*IndentSize, IndentChar));
120 builder.AppendLine(
"{ ");
121 var lines = value.Trim().Split(
122 new[] {Environment.NewLine},
123 StringSplitOptions.None
125 foreach (var line
in lines)
127 AppendIndent(indent + 1);
128 builder.AppendLine(line.Trim());
130 AppendIndent(indent);
134 builder.Append(
"\"");
135 builder.Append(value);
136 builder.Append(
"\"");
139 if (value.Contains(
" ") || value.Contains(
"\t"))
141 builder.Append(
"\"");
142 builder.Append(value);
143 builder.Append(
"\"");
147 builder.Append(value);
151 builder.Append(value);
163 var properties = node.GetType().GetProperties().
165 delegate(PropertyInfo info)
167 var attribute =
System.Attribute.GetCustomAttribute(info, typeof(
NtpaIndex));
168 return ((
NtpaIndex) attribute)?.Index ??
int.MaxValue;
171 foreach (var property
in properties)
173 if (DecompileSetting(indent, node, property))
176 if (DecompileSettingCollection(indent, node, property))
179 if (DecompileReferenceCollection(indent, node, property))
182 DecompileReference(indent, node, property);
199 builder =
new StringBuilder();
201 DecompileComplexType(indent + 1, node);
208 if (res.ToString().Trim() ==
string.Empty)
214 AppendIndent(indent);
215 builder.AppendLine();
218 AppendIndent(indent);
219 builder.Append(typeName);
227 builder.AppendLine(
" {");
234 AppendIndent(indent);
235 builder.AppendLine(
"}");
248 if (reference == null)
251 var value =
property.GetValue(node, null);
257 if (configurationNode == null)
261 DecompileSimpleType(indent, keyword.Name, name, null,
Layout.Normal);
274 if (attribute == null)
279 var value =
property.GetValue(node, null);
280 if (!(value is IEnumerable))
284 foreach (var subObject
in value as IEnumerable)
287 if (configurationNode != null)
290 DecompileSimpleType(indent, keyword.Name, name, null,
Layout.Normal);
311 var value =
property.GetValue(node, null);
317 DecompileConfiguration(indent, keyword.Name, value as IConfigurationNode);
321 DecompileSimpleType(indent, keyword.Name, value, setting.Value, setting.Layout);
337 if (attribute == null)
342 var value =
property.GetValue(node, null);
347 if (collection.Flatten && value is IEnumerable)
349 foreach (var subObject
in value as IEnumerable)
351 DecompileComplexType(indent, subObject);
356 if (!(value is IEnumerable))
360 if (collection.Raise !=
Symbol.Undefined)
363 AppendIndent(indent);
364 builder.Append(
raise.Name);
365 builder.AppendLine(
" {");
370 foreach (var subObject
in value as IEnumerable)
372 DecompileConfiguration(indent + raiseAdd, keyword.Name, subObject as
IConfigurationNode);
375 if (collection.Raise !=
Symbol.Undefined)
377 AppendIndent(indent);
378 builder.AppendLine(
"}");
394 if (!ShowDefaultValues && value.Equals(defaultValue))
397 if (layout ==
Layout.Block)
399 AppendIndent(indent);
400 builder.AppendLine();
403 AppendIndent(indent);
404 builder.Append(name);
409 builder.Append((
bool) value ?
"Yes" :
"No");
411 else if (value is
string)
413 AppendString((
string) value, layout, indent);
415 else if (value is DateTimeKind)
417 AppendDateTimeKind((DateTimeKind) value);
419 else if (value is Uri)
421 AppendString(((Uri) value).OriginalString, layout, indent);
425 builder.Append(value);
428 builder.AppendLine();
void AppendDateTimeKind(DateTimeKind value)
bool DecompileReferenceCollection(int indent, object node, PropertyInfo property)
Decompiles a property with a collection of references if applicable.
bool DecompileSettingCollection(int indent, object node, PropertyInfo property)
Decompiles a collection property if applicable.
void DecompileComplexType(int indent, object node)
Decompiles a complex node type (classes).
void DecompileConfiguration(int indent, string typeName, IConfigurationNode node)
Decompiles a configuration section.
void AppendString(string value, Layout layout, int indent)
Appends the string to output.
static Keyword Find(Symbol symbol)
Decompiler()
Initializes a new instance of the Decompiler class.
void DecompileReference(int indent, object node, PropertyInfo property)
Decompiles a reference property if applicable.
bool DecompileSetting(int indent, object node, PropertyInfo property)
Decompiles a setting property if applicable.
string Execute()
Execute the decompiler.
void DecompileSimpleType(int indent, string name, object value, object defaultValue, Layout layout)
Decompiles a simple node type (integers, strings, etc.)
void AppendIndent(int size)
Appends indent to output.