|
| 1 | +using System.Reflection; |
| 2 | +using Smdn.Reflection.ReverseGenerating; |
| 3 | + |
| 4 | +var options = new GeneratorOptions(); |
| 5 | + |
| 6 | +// Generates the type declaration of int(Int32) |
| 7 | +Console.WriteLine(Generator.GenerateTypeDeclaration(typeof(int), null, options)); |
| 8 | +Console.WriteLine(); |
| 9 | + |
| 10 | +// Generates the type declaration of Func<T1, T2, T3, TResult> |
| 11 | +Console.WriteLine(Generator.GenerateTypeDeclaration(typeof(Func<,,,>), null, options)); |
| 12 | +Console.WriteLine(); |
| 13 | + |
| 14 | +// Generates the type declaration of Dictionary<TKey, TValue> |
| 15 | +Console.WriteLine(Generator.GenerateTypeDeclaration(typeof(Dictionary<,>), null, options)); |
| 16 | +Console.WriteLine(); |
| 17 | + |
| 18 | +// Generates the base interfaces of Dictionary<TKey, TValue> |
| 19 | +options.TypeDeclaration.WithNamespace = true; |
| 20 | + |
| 21 | +foreach (var decl in Generator.GenerateExplicitBaseTypeAndInterfaces(typeof(Dictionary<,>), null, options)) { |
| 22 | + Console.WriteLine(decl); |
| 23 | +} |
| 24 | +Console.WriteLine(); |
| 25 | + |
| 26 | +// Generates the type declaration of Dictionary<,> with base type, interfaces and generic parameter constraints |
| 27 | +foreach (var decl in Generator.GenerateTypeDeclarationWithExplicitBaseTypeAndInterfaces(typeof(Stream), null, options)) { |
| 28 | + Console.WriteLine(decl); |
| 29 | +} |
| 30 | +Console.WriteLine(); |
| 31 | + |
| 32 | +// Generates the member declaration of int.TryParse |
| 33 | +var intTryParse = typeof(int).GetMethods().First(m => m.Name == "TryParse"); |
| 34 | + |
| 35 | +Console.WriteLine(Generator.GenerateMemberDeclaration(intTryParse, null, options)); |
| 36 | + |
| 37 | +options.MemberDeclaration.MethodBody = MethodBodyOption.ThrowNull; |
| 38 | +options.MemberDeclaration.WithDeclaringTypeName = true; |
| 39 | +options.AttributeDeclaration.TypeFilter = (Type attributeType, ICustomAttributeProvider attributeProvider) => false; |
| 40 | + |
| 41 | +Console.WriteLine(Generator.GenerateMemberDeclaration(intTryParse, null, options)); |
| 42 | + |
| 43 | +options.MemberDeclaration.MethodBody = MethodBodyOption.None; |
| 44 | +options.MemberDeclaration.NullabilityInfoContext = null; |
| 45 | + |
| 46 | +Console.WriteLine(Generator.GenerateMemberDeclaration(intTryParse, null, options)); |
| 47 | +Console.WriteLine(); |
| 48 | + |
| 49 | +// Generates the attribute declarations of List<> |
| 50 | +options.AttributeDeclaration.TypeFilter = (Type attributeType, ICustomAttributeProvider attributeProvider) => true; |
| 51 | + |
| 52 | +Console.WriteLine(string.Join(", ", Generator.GenerateAttributeList(typeof(List<>), null, options))); |
| 53 | + |
| 54 | +options.AttributeDeclaration.WithNamespace = true; |
| 55 | +options.AttributeDeclaration.OmitAttributeSuffix = false; |
| 56 | + |
| 57 | +Console.WriteLine(string.Join(", ", Generator.GenerateAttributeList(typeof(List<>), null, options))); |
| 58 | + |
| 59 | +Console.WriteLine(); |
0 commit comments