-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
636 lines (532 loc) · 28.6 KB
/
Program.cs
File metadata and controls
636 lines (532 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Build.Construction;
namespace CsFakeGenerator
{
internal static class Program
{
private static int indentLevel = 0;
private static string Indent => new string(' ', indentLevel * 4);
private static List<FileInfo> generatedCsFiles = new();
private static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage: CsFakeGenerator.exe [input dll file] [output path]");
return;
}
var inputFile = args[0];
var outputFolder = args[1];
if (!File.Exists(inputFile))
{
Console.WriteLine($"Input file [{args[0]}] does not exist.");
return;
}
if (!Directory.Exists(outputFolder))
{
Console.WriteLine($"Output directory [{args[1]}] does not exist. Create it? Y/N ");
var key = Console.ReadKey();
if (key.Key != ConsoleKey.Y)
{
return;
}
}
ProcessAssembly(inputFile, outputFolder);
}
/// <summary>
/// Iterates through all public types in the specified assembly and outputs fakes of these types to the output folder.
/// </summary>
/// <param name="inputFile">The DLL file to process.</param>
/// <param name="outputFolder">The folder in which to save the fakes.</param>
/// <exception cref="ArgumentException">The input file does not exist.</exception>
private static void ProcessAssembly(string inputFile, string outputFolder)
{
if (!File.Exists(inputFile)) throw new ArgumentException("Input file does not exist", nameof(inputFile));
if (!Directory.Exists(outputFolder)) Directory.CreateDirectory(outputFolder);
var assembly = Assembly.LoadFrom(inputFile);
outputFolder = new DirectoryInfo(outputFolder).FullName;
foreach (var type in assembly.ExportedTypes)
{
// Skip nested types, they'll be picked up by their parent types
if (!type.IsNested)
{
indentLevel = 0;
var fileOutputPath = GetOutputPathForType(outputFolder, type);
var filePath = fileOutputPath + GetTypeName(type, false) + ".cs";
if (!Directory.Exists(fileOutputPath)) Directory.CreateDirectory(fileOutputPath);
Console.WriteLine($"Writing type {type.Name} to file {filePath}");
File.WriteAllText(filePath, ProcessType(type));
generatedCsFiles.Add(new FileInfo(filePath));
}
}
}
/// <summary>
/// Saves a csproj file in the output folder to build the fake library.
/// </summary>
/// <param name="assembly">The input assembly. Used to copy across references.</param>
/// <param name="inputFile">The location of the input file (assembly).</param>
/// <param name="outputFolder">The output folder.</param>
private static void CreateProjectFile(Assembly assembly, string inputFile, string outputFolder)
{
var projectRoot = ProjectRootElement.Create();
var propertyGroup = projectRoot.AddPropertyGroup();
propertyGroup.AddProperty("TargetFramework", "netstandard2.0");
propertyGroup.AddProperty("Configuration", "Debug");
propertyGroup.AddProperty("Platform", "x64");
var referenceGroup = projectRoot.AddItemGroup();
var inputFolder = inputFile.Substring(0, inputFile.LastIndexOf(Path.DirectorySeparatorChar) + 1);
foreach (var reference in assembly.GetReferencedAssemblies())
{
var item = referenceGroup.AddItem("Reference", reference.FullName);
}
var compileGroup = projectRoot.AddItemGroup();
foreach (var generatedCsFile in generatedCsFiles)
{
compileGroup.AddItem("Compile", generatedCsFile.Name);
}
var target = projectRoot.AddTarget("Build");
var task = target.AddTask("Csc");
task.SetParameter("Sources", "@(Compile)");
task.SetParameter("OutputAssembly", new FileInfo(inputFile).Name);
projectRoot.Save(outputFolder + Path.DirectorySeparatorChar + new FileInfo(inputFile).Name + ".csproj");
}
/// <summary>
/// Creates a fake for a type.
/// </summary>
/// <param name="type">The type to make a fake for, e.g. a class, enum, interface, struct.</param>
/// <returns>A string with a fake for this type.</returns>
private static string ProcessType(Type type)
{
bool typeHasNamespace = type.Namespace != null && !type.IsNested;
var typeOutput = new StringBuilder();
// Namespace declaration
if (typeHasNamespace)
{
typeOutput.Append("namespace ").Append(type.Namespace).Append("\n{\n");
indentLevel++;
}
// For delegates, use a single line delcaration
if (IsDelegate(type))
{
typeOutput.Append(Indent).Append(GetDelegateDeclaration(type)).Append('\n');
if (typeHasNamespace)
{
indentLevel--;
typeOutput.Append("}\n"); // Close namespace braces
}
return typeOutput.ToString();
}
// Type declaration
typeOutput.Append(Indent).Append(GetTypeDeclaration(type)).Append('\n');
typeOutput.Append(Indent).Append("{\n");
indentLevel++;
// Add nested types
foreach (var nestedType in type.GetNestedTypes())
{
typeOutput.Append(ProcessType(nestedType));
typeOutput.Append('\n');
}
// Add fields to classes / structs / interfaces
if (!type.IsEnum)
{
foreach (var field in type.GetFields())
{
typeOutput.Append(ProcessField(field));
}
typeOutput.Append('\n');
}
// Add enum members
if (type.IsEnum)
{
typeOutput.Append(ProcessEnumValues(type));
typeOutput.Append('\n');
}
// Add properties
foreach (var property in type.GetProperties())
{
typeOutput.Append(ProcessProperty(property));
}
typeOutput.Append('\n');
// Add methods
if (!type.IsEnum)
{
foreach (var method in type.GetMethods())
{
typeOutput.Append(ProcessMethod(method));
}
typeOutput.Append('\n');
}
indentLevel--;
typeOutput.Append(Indent).Append("}\n"); // Close class brace
if (typeHasNamespace)
{
indentLevel--;
typeOutput.Append("}\n"); // Close namespace braces
}
return typeOutput.ToString();
}
private static string GetDelegateDeclaration(Type type)
{
var typeDeclaration = new StringBuilder(Indent);
typeDeclaration.Append("public delegate ");
var invokeMethod = type.GetMethod("Invoke");
if (invokeMethod != null)
{
typeDeclaration.Append(GetTypeName(invokeMethod.ReturnType, true)).Append(' ');
typeDeclaration.Append(GetTypeName(type, false));
typeDeclaration.Append(GetMethodParameters(invokeMethod));
}
return typeDeclaration.Append(';').ToString();
}
/// <summary>
/// Lists out the enum's fields with their values.
/// </summary>
/// <param name="type">An enum type</param>
/// <returns>A string with all fields in the enum.</returns>
private static string ProcessEnumValues(Type type)
{
var names = Enum.GetNames(type);
var values = Enum.GetValues(type);
var enumValues = new List<string>();
foreach (var value in Enum.GetValues(type))
{
enumValues.Add(string.Concat(Indent, value, " = ", ((int) value).ToString()));
}
return string.Join(",\n", enumValues);
}
/// <summary>
/// Creates a line declaring a field.
/// </summary>
/// <param name="fieldInfo">The field to create a declaration for.</param>
/// <returns>A string declaring the field, or an empty string if the field is inherited from a base type.</returns>
private static string ProcessField(FieldInfo fieldInfo)
{
if (IsInherited(fieldInfo)) return string.Empty;
var fieldDeclaration = new StringBuilder(Indent);
fieldDeclaration.Append(GetAccessModifier(fieldInfo));
// Add static modifier. If the parent class is static and this member is not, skip it.
if (fieldInfo.IsStatic) fieldDeclaration.Append("static ");
if (fieldInfo.ReflectedType != null && fieldInfo.ReflectedType.IsAbstract &&
fieldInfo.ReflectedType.IsSealed && !fieldInfo.IsStatic) return string.Empty;
// Field type and name
fieldDeclaration.Append(GetTypeName(fieldInfo.FieldType, true)).Append(GetGenericTypeArguments(fieldInfo.FieldType, true))
.Append(' ').Append(fieldInfo.Name).Append(";\n");
return fieldDeclaration.ToString();
}
/// <summary>
/// Creates a line declaring a property.
/// </summary>
/// <param name="propertyInfo">The property to create a declaration for.</param>
/// <returns>A string declaring the specified property e.g. public [type] [name] { get; set; }</returns>
private static string ProcessProperty(PropertyInfo propertyInfo)
{
var propertyMethod = propertyInfo.GetMethod ?? propertyInfo.SetMethod;
if (propertyMethod == null) return string.Empty;
if (IsInherited(propertyMethod)) return string.Empty;
var propertyDeclaration = new StringBuilder(Indent);
propertyDeclaration.Append(GetAccessModifier(propertyInfo));
propertyDeclaration.Append(GetOverrideModifier(propertyMethod));
// Add static modifier. If the parent class is static and this member is not, skip it.
if (propertyMethod.IsStatic) propertyDeclaration.Append("static ");
if (propertyMethod.ReflectedType != null && propertyMethod.ReflectedType.IsAbstract &&
propertyMethod.ReflectedType.IsSealed && !propertyMethod.IsStatic) return string.Empty;
// Property type and generic arguments
propertyDeclaration.Append(GetTypeName(propertyInfo.PropertyType, true));
propertyDeclaration.Append(GetGenericTypeArguments(propertyInfo.PropertyType, true));
// Property name
propertyDeclaration.Append(' ').Append(propertyInfo.Name).Append(" { ");
// Getter / setter
if (propertyInfo.CanRead) propertyDeclaration.Append("get; ");
if (propertyInfo.CanWrite) propertyDeclaration.Append("set; ");
// Close property brace
propertyDeclaration.Append("}\n");
return propertyDeclaration.ToString();
}
/// <summary>
/// Returns an appropriate access modifier for the specified member, based on its parent type.
/// </summary>
/// <param name="memberInfo">The member.</param>
/// <returns>"public " when the member is not on an interface, otherwise an empty string.</returns>
private static string GetAccessModifier(MemberInfo memberInfo)
{
if (memberInfo.DeclaringType != null && !memberInfo.DeclaringType.IsInterface) return "public ";
return string.Empty;
}
/// <summary>
/// Creates a method declaration with default return value.
/// </summary>
/// <param name="methodInfo">The method to create a declaration for.</param>
/// <returns>A string containing the method's declaration and a method body returning a default value.</returns>
private static string ProcessMethod(MethodInfo methodInfo)
{
// Return nothing if inherited and not overridden
if (IsInherited(methodInfo)) return string.Empty;
var methodIsOnInterface = methodInfo.DeclaringType != null && methodInfo.DeclaringType.IsInterface;
// Return nothing if this method is part of a Property
if (methodInfo.Name.Length > 4 && methodInfo.DeclaringType != null &&
methodInfo.DeclaringType.GetProperty(methodInfo.Name.Substring(4)) != null)
{
return string.Empty;
}
var methodDeclaration = new StringBuilder(Indent);
methodDeclaration.Append(GetAccessModifier(methodInfo));
methodDeclaration.Append(GetOverrideModifier(methodInfo));
// Add static modifier. If the parent class is static and this member is not, skip it.
if (methodInfo.IsStatic) methodDeclaration.Append("static ");
if (methodInfo.ReflectedType != null && methodInfo.ReflectedType.IsAbstract &&
methodInfo.ReflectedType.IsSealed && !methodInfo.IsStatic) return string.Empty;
methodDeclaration.Append(GetTypeName(methodInfo.ReturnType, true));
methodDeclaration.Append(GetGenericTypeArguments(methodInfo.ReturnType, true));
// Name, parameters
methodDeclaration.Append(' ').Append(methodInfo.Name);
methodDeclaration.Append(GetGenericTypeArguments(methodInfo, true));
methodDeclaration.Append(GetMethodParameters(methodInfo));
if (methodIsOnInterface || methodInfo.IsAbstract)
{
// If this is on an interface or abstract, don't create a method body
methodDeclaration.Append(";\n");
return methodDeclaration.ToString();
}
// Method opening brace
methodDeclaration.Append('\n').Append(Indent).Append("{\n");
// Return default value
indentLevel++;
if (methodInfo.ReturnType == typeof(void))
{
methodDeclaration.Append(Indent).Append("return;\n");
}
else if (methodInfo.ReturnType.IsValueType || methodInfo.IsGenericMethod)
{
methodDeclaration.Append(Indent).Append("return default;\n");
}
else
{
methodDeclaration.Append(Indent).Append("return null;\n");
}
indentLevel--;
// Close method
methodDeclaration.Append(Indent).Append("}\n\n");
return methodDeclaration.ToString();
}
/// <summary>
/// Determines whether a method is overridden and returns its modifier or an empty string.
/// </summary>
/// <param name="methodInfo">The method to check.</param>
/// <returns>One of "abstract", "override", "new" or an empty string, depending on the method.</returns>
private static string GetOverrideModifier(MethodInfo methodInfo)
{
// Not required on an interface
if (methodInfo.DeclaringType != null && methodInfo.DeclaringType.IsInterface) return string.Empty;
if (methodInfo.IsAbstract)
{
// Property is an abstract member
return "abstract ";
}
if (methodInfo.GetBaseDefinition().IsAbstract)
{
// Overriding an abstract member
return "override ";
}
if (methodInfo.DeclaringType != methodInfo.ReflectedType)
{
// Find the original definition of the method
var baseMethod = methodInfo.GetBaseDefinition();
if (methodInfo.ReflectedType != null && methodInfo.ReflectedType.BaseType != null)
{
// If this is inherited directly from the base class, use its implementation instead
var inheritedMethod = methodInfo.ReflectedType.BaseType.GetMethods().FirstOrDefault(baseTypeMethod => baseTypeMethod.GetBaseDefinition() == methodInfo.GetBaseDefinition() &&
baseTypeMethod.DeclaringType == methodInfo.ReflectedType.BaseType);
baseMethod = inheritedMethod ?? baseMethod;
}
// Method has a base so is new or override depending on whether the base is final
return baseMethod.IsFinal ? "new " : "override ";
}
// Method isn't final (e.g. can be overridden), not static and the type it's on is a class - it's virtual
if (!methodInfo.IsFinal && !methodInfo.IsStatic && methodInfo.ReflectedType != null
&& methodInfo.ReflectedType.IsClass) return "virtual ";
// No special conditions apply, so no modifiers required
return string.Empty;
}
/// <summary>
/// Creates a line declaring the passed in type.
/// </summary>
/// <param name="type">A type declared in the input assembly.</param>
/// <returns>A string declaring the type.</returns>
private static string GetTypeDeclaration(Type type)
{
var typeDeclaration = new StringBuilder("public ");
if (type.IsClass)
{
// Class modifiers
if (type.IsAbstract && type.IsSealed) typeDeclaration.Append("static ");
else if (type.IsAbstract) typeDeclaration.Append("abstract ");
else if (type.IsSealed) typeDeclaration.Append("sealed ");
typeDeclaration.Append("class ");
}
else if (type.IsInterface) typeDeclaration.Append("interface ");
else if (type.IsEnum) typeDeclaration.Append("enum ");
else if (!type.IsEnum && type.IsValueType) typeDeclaration.Append("struct ");
// Add name of type with any generic arguments
typeDeclaration.Append(GetTypeName(type, false) + GetGenericTypeArguments(type, false) + GetGenericTypeArgumentRestrictions(type));
// Do not add interfaces or inheritance on enums
if (type.IsEnum) return typeDeclaration.ToString();
var inherits = new List<string>();
if (type.BaseType != null && type.BaseType != typeof(Object) && type.BaseType != typeof(Enum) && type.BaseType != typeof(ValueType))
{
// Add base type if not a primitive
inherits.Add(GetTypeName(type.BaseType, true) + GetGenericTypeArguments(type.BaseType, true));
}
// Add interfaces
Array.ForEach<Type>(type.GetInterfaces(), i => inherits.Add(GetTypeName(i, true) + GetGenericTypeArguments(i, true)));
// If a base class and/or interfaces were found, add them to the type declaration
if (inherits.Count > 0) typeDeclaration.Append(" : ").Append(string.Join(", ", inherits));
return typeDeclaration.ToString();
}
/// <summary>
/// Gets the type name to be used in various settings, such as file names, type declarations, parameters, etc.
/// </summary>
/// <param name="type">The type to give the name for.</param>
/// <param name="fullName">Whether to fully qualify the name with its namespace.</param>
/// <returns>The name, fully qualified or not, with generic markers removed and corrected for nested classes.</returns>
private static string GetTypeName(Type type, bool fullName)
{
if (type == typeof(void)) return "void";
// Get the type name, force full name if no FullName set, but if it's a generic parameter, e.g. T then don't
var typeName = fullName ? type.FullName ?? type.Namespace + '.' + type.Name : type.Name;
if (type.IsGenericParameter) typeName = type.Name;
if (typeName.Contains('`')) typeName = typeName.Substring(0, typeName.IndexOf("`", StringComparison.Ordinal)); // Remove `1 from generic types
if (typeName.Contains('+')) typeName = typeName.Replace('+', '.'); // Replace + from nested types
if (typeName.Contains('&')) typeName = typeName.Replace("&", ""); // Replace & for byref parameters
return typeName;
}
/// <summary>
/// Creates a list of method parameters in brackets.
/// </summary>
/// <param name="methodInfo">The method to get the parameters for.</param>
/// <returns>A string containing method parameter declarations in brackets.</returns>
private static string GetMethodParameters(MethodInfo methodInfo)
{
var parameters = new List<string>();
foreach (var parameterInfo in methodInfo.GetParameters())
{
var byref = parameterInfo.ParameterType.IsByRef ? "ref " : string.Empty;
parameters.Add(string.Concat(byref, GetTypeName(parameterInfo.ParameterType, true),
GetGenericTypeArguments(parameterInfo.ParameterType, true),
" ", parameterInfo.Name));
}
return string.Concat("(", string.Join(", ", parameters), ")");
}
/// <summary>
/// If the type takes generic type arguments (e.g. generic List T) then this method returns the generic arguments enclosed in < and >
/// </summary>
/// <param name="type">The type to return generic arguments for.</param>
/// <param name="useTypeNames">If true, the types are returned e.g. string, otherwise the name of the generic parameter is returned e.g. T.</param>
/// <returns>The generic arguments of the specified type, or an empty string if this type does not take generic arguments.</returns>
private static string GetGenericTypeArguments(Type type, bool useTypeNames)
{
if (!type.IsGenericType && type.GetGenericArguments().Length == 0) return string.Empty;
var typeDefinition = useTypeNames ? type : type.GetGenericTypeDefinition();
var genericArgumentNames = new List<string>();
foreach (var genericArgument in typeDefinition.GetGenericArguments())
{
genericArgumentNames.Add(GetTypeName(genericArgument, true));
}
return string.Concat("<", string.Join(", ", genericArgumentNames), ">");
}
private static string GetGenericTypeArguments(MethodInfo methodInfo, bool useTypeNames)
{
if (!methodInfo.IsGenericMethod) return string.Empty;
var memberDefinition = useTypeNames ? methodInfo : methodInfo.GetGenericMethodDefinition();
var genericArgumentNames = new List<string>();
foreach (var genericArgument in methodInfo.GetGenericArguments())
{
genericArgumentNames.Add(GetTypeName(genericArgument, true));
}
return string.Concat("<", string.Join(", ", genericArgumentNames), ">");
}
/// <summary>
/// If the type takes generic type arguments with restrictions (e.g. Class T where T : OtherClass), this returns the type restrictions (where clause).
/// </summary>
/// <param name="type">The type to return the generic argument restrictions for.</param>
/// <returns>A list of type restrictions, or an empty string if the type does not have any.</returns>
private static string GetGenericTypeArgumentRestrictions(Type type)
{
if (!type.IsGenericType) return string.Empty;
var restrictions = new StringBuilder();
// Loop through all generic arguments
var typeDefinition = type.GetGenericTypeDefinition();
foreach (var genericArgument in typeDefinition.GetGenericArguments())
{
// For each argument, loop through its restrictions
var argumentRestrictions = genericArgument.GetGenericParameterConstraints();
if (argumentRestrictions.Length > 0)
{
// Append all restrictions for this type
restrictions.Append(" where ").Append(genericArgument.Name).Append(" : ");
var argumentRestrictionsList = new List<string>();
for (int i = 0; i < argumentRestrictions.Length; i++)
{
if (argumentRestrictions[i] == typeof(System.ValueType) && !argumentRestrictions[i].IsEnum)
{
// ValueType that isn't an enum is a struct
argumentRestrictionsList.Insert(0, "struct");
}
else
{
// Otherwise get the name
argumentRestrictionsList.Add(GetTypeName(argumentRestrictions[i], true));
}
}
restrictions.Append(string.Join(", ", argumentRestrictionsList));
}
}
return restrictions.ToString();
}
/// <summary>
/// Checks whether the member is inherited without override.
/// </summary>
/// <param name="memberInfo">The member (property, method) to check.</param>
/// <returns>True if the member is inherited without overriding, false if the member isn't inherited,
/// or is inherited but overridden in this class.</returns>
private static bool IsInherited(MethodInfo memberInfo)
{
// If this isn't the declaring type, it's inherited
if (memberInfo.DeclaringType != memberInfo.ReflectedType)
{
if ((memberInfo.Attributes & MethodAttributes.NewSlot) == 0)
{
// If the method isn't virtual and doesn't take up a new slot, meaning it's inherited, not override
return true;
}
if ((memberInfo.Name.Equals("get_TypeId") || memberInfo.Name.Equals("set_TypeId"))
&& memberInfo.ReturnType == typeof(Object))
{
// Special case, this is always implemented on each object so ignore it
return true;
}
}
return false;
}
/// <summary>
/// Checks whether the field is declared in the current type.
/// </summary>
/// <param name="memberInfo">The field's FieldInfo.</param>
/// <returns>True if the field is inherited, false if it is declared on the current type.</returns>
private static bool IsInherited(FieldInfo memberInfo)
{
// If this isn't the declaring type, it's inherited
return memberInfo.DeclaringType != memberInfo.ReflectedType;
}
private static string GetOutputPathForType(string outputFolder, Type type)
{
if (type.Namespace != null)
return outputFolder + Path.DirectorySeparatorChar + type.Namespace.Replace('.', Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
return outputFolder + Path.DirectorySeparatorChar;
}
private static bool IsDelegate(Type type)
{
return type.BaseType == typeof(MulticastDelegate);
}
}
}