From 5e652606b2ef706188ef0da23ab13e66fc629aee Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Wed, 8 Nov 2017 01:08:02 +0100 Subject: [PATCH] Re-factoring / boilerplate code --- Il2CppInspector/Reflection/Assembly.cs | 3 +- Il2CppInspector/Reflection/FieldInfo.cs | 9 +++-- Il2CppInspector/Reflection/MemberInfo.cs | 3 +- Il2CppInspector/Reflection/MethodBase.cs | 20 ++++++++++ Il2CppInspector/Reflection/MethodInfo.cs | 19 ++++++++++ .../Reflection/ReflectionClasses.cs | 22 ++++------- Il2CppInspector/Reflection/TypeInfo.cs | 38 +++++++++---------- 7 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 Il2CppInspector/Reflection/MethodBase.cs create mode 100644 Il2CppInspector/Reflection/MethodInfo.cs diff --git a/Il2CppInspector/Reflection/Assembly.cs b/Il2CppInspector/Reflection/Assembly.cs index 28db020..a401839 100644 --- a/Il2CppInspector/Reflection/Assembly.cs +++ b/Il2CppInspector/Reflection/Assembly.cs @@ -4,6 +4,7 @@ All rights reserved. */ +using System; using System.Collections.Generic; using System.Linq; @@ -21,7 +22,7 @@ namespace Il2CppInspector.Reflection { public string FullName { get; } // Entry point method for the assembly - //public MethodInfo EntryPoint { get; } // TODO + public MethodInfo EntryPoint => throw new NotImplementedException(); // List of types defined in the assembly public List DefinedTypes { get; } = new List(); diff --git a/Il2CppInspector/Reflection/FieldInfo.cs b/Il2CppInspector/Reflection/FieldInfo.cs index c1dc0a2..72716b9 100644 --- a/Il2CppInspector/Reflection/FieldInfo.cs +++ b/Il2CppInspector/Reflection/FieldInfo.cs @@ -4,6 +4,7 @@ All rights reserved. */ +using System; using System.Reflection; namespace Il2CppInspector.Reflection { @@ -29,16 +30,16 @@ namespace Il2CppInspector.Reflection { // https://docs.microsoft.com/en-us/dotnet/api/system.reflection.fieldinfo.isfamilyandassembly?view=netframework-4.7.1#System_Reflection_FieldInfo_IsFamilyAndAssembly // True if the field is declared as internal - public bool IsAssembly { get; } // TODO + public bool IsAssembly => throw new NotImplementedException(); // True if the field is declared as protected - public bool IsFamily { get; } // TODO + public bool IsFamily => throw new NotImplementedException(); // True if the field is declared as 'protected private' (always false) public bool IsFamilyAndAssembly => false; // True if the field is declared as protected public - public bool IsFamilyOrAssembly { get; } // TODO + public bool IsFamilyOrAssembly => throw new NotImplementedException(); // True if the field is declared as readonly public bool IsInitOnly => (Attributes & FieldAttributes.InitOnly) == FieldAttributes.InitOnly; @@ -52,7 +53,7 @@ namespace Il2CppInspector.Reflection { // True if the field is declared as static public bool IsStatic => (Attributes & FieldAttributes.Static) == FieldAttributes.Static; - public override MemberTypes MemberType { get; } + public override MemberTypes MemberType => MemberTypes.Field; public FieldInfo(Il2CppInspector pkg, int fieldIndex, TypeInfo declaringType) : base(declaringType) { diff --git a/Il2CppInspector/Reflection/MemberInfo.cs b/Il2CppInspector/Reflection/MemberInfo.cs index d3591ca..3855209 100644 --- a/Il2CppInspector/Reflection/MemberInfo.cs +++ b/Il2CppInspector/Reflection/MemberInfo.cs @@ -4,6 +4,7 @@ All rights reserved. */ +using System; using System.Collections.Generic; using System.Reflection; @@ -14,7 +15,7 @@ namespace Il2CppInspector.Reflection { public Assembly Assembly { get; } // Custom attributes for this member - public IEnumerable CustomAttributes { get; } // TODO + public IEnumerable CustomAttributes => throw new NotImplementedException(); // Type that this type is declared in for nested types public TypeInfo DeclaringType { get; } diff --git a/Il2CppInspector/Reflection/MethodBase.cs b/Il2CppInspector/Reflection/MethodBase.cs new file mode 100644 index 0000000..16bf41d --- /dev/null +++ b/Il2CppInspector/Reflection/MethodBase.cs @@ -0,0 +1,20 @@ +/* + Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + + All rights reserved. +*/ + +using System.Reflection; + +namespace Il2CppInspector.Reflection +{ + public abstract class MethodBase : MemberInfo + { + // (not code attributes) + public MethodAttributes Attributes { get; set; } + + // TODO: ContainsGenericParameters + + protected MethodBase(TypeInfo declaringType) : base(declaringType) { } + } +} \ No newline at end of file diff --git a/Il2CppInspector/Reflection/MethodInfo.cs b/Il2CppInspector/Reflection/MethodInfo.cs new file mode 100644 index 0000000..a26fad0 --- /dev/null +++ b/Il2CppInspector/Reflection/MethodInfo.cs @@ -0,0 +1,19 @@ +/* + Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + + All rights reserved. +*/ + +using System.Reflection; + +namespace Il2CppInspector.Reflection +{ + public class MethodInfo : MethodBase + { + // TODO + public override MemberTypes MemberType => MemberTypes.Method; + + public MethodInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : + base(declaringType) { } + } +} \ No newline at end of file diff --git a/Il2CppInspector/Reflection/ReflectionClasses.cs b/Il2CppInspector/Reflection/ReflectionClasses.cs index 27ffa1d..8970082 100644 --- a/Il2CppInspector/Reflection/ReflectionClasses.cs +++ b/Il2CppInspector/Reflection/ReflectionClasses.cs @@ -4,35 +4,29 @@ All rights reserved. */ +using System.Reflection; + namespace Il2CppInspector.Reflection { - /* - public abstract class MethodBase : MemberInfo - { - // (not code attributes) - public MethodAttributes Attributes { get; set; } - - // TODO: ContainsGenericParameters - } - public class ConstructorInfo : MethodBase { // TODO - } + public override MemberTypes MemberType => MemberTypes.Constructor | MemberTypes.Method; - public class MethodInfo : MethodBase - { - // TODO + public ConstructorInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : + base(declaringType) { } } public class PropertyInfo : MemberInfo { // TODO + public override MemberTypes MemberType => MemberTypes.Property | MemberTypes.Method; + public PropertyInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : + base(declaringType) { } } public class CustomAttributeData { // TODO } - */ } diff --git a/Il2CppInspector/Reflection/TypeInfo.cs b/Il2CppInspector/Reflection/TypeInfo.cs index 78dcf5a..1d0066b 100644 --- a/Il2CppInspector/Reflection/TypeInfo.cs +++ b/Il2CppInspector/Reflection/TypeInfo.cs @@ -18,10 +18,10 @@ namespace Il2CppInspector.Reflection { // Information/flags about the type // Undefined if the Type represents a generic type parameter - public TypeAttributes Attributes { get; } // TODO + public TypeAttributes Attributes => throw new NotImplementedException(); // Type that this type inherits from - public TypeInfo BaseType { get; } // TODO + public TypeInfo BaseType => throw new NotImplementedException(); // True if the type contains unresolved generic type parameters public bool ContainsGenericParameters { get; } @@ -39,16 +39,16 @@ namespace Il2CppInspector.Reflection { } } - public List DeclaredConstructors { get; } // TODO - public List DeclaredEvents { get; } // TODO + public List DeclaredConstructors => throw new NotImplementedException(); + public List DeclaredEvents => throw new NotImplementedException(); public List DeclaredFields { get; } = new List(); - public List DeclaredMembers { get; } // TODO - public List DeclaredMethods { get; } // TODO - public List DeclaredNestedTypes { get; } // TODO - public List DeclaredProperties { get; } // TODO + public List DeclaredMembers => throw new NotImplementedException(); + public List DeclaredMethods => throw new NotImplementedException(); + public List DeclaredNestedTypes => throw new NotImplementedException(); + public List DeclaredProperties => throw new NotImplementedException(); // Method that the type is declared in if this is a type parameter of a generic method - public MethodBase DeclaringMethod { get; } // TODO + public MethodBase DeclaringMethod => throw new NotImplementedException(); // Gets the type of the object encompassed or referred to by the current array, pointer or reference type public TypeInfo ElementType { get; } @@ -68,22 +68,22 @@ namespace Il2CppInspector.Reflection { public bool HasElementType => ElementType != null; public bool IsAbstract { get; } public bool IsArray { get; } - public bool IsByRef { get; } // TODO + public bool IsByRef => throw new NotImplementedException(); public bool IsClass { get; } - public bool IsEnum { get; } // TODO + public bool IsEnum => throw new NotImplementedException(); public bool IsGenericParameter { get; } - public bool IsGenericType { get; } // TODO - public bool IsGenericTypeDefinition { get; } // TODO + public bool IsGenericType => throw new NotImplementedException(); + public bool IsGenericTypeDefinition => throw new NotImplementedException(); public bool IsInterface { get; } - public bool IsNested { get; } // TODO - public bool IsNestedPrivate { get; } // TODO - public bool IsNestedPublic { get; } // TODO - public bool IsPointer { get; } // TODO - public bool IsPrimitive { get; } // TODO + public bool IsNested { get; } // TODO: Partially implemented + public bool IsNestedPrivate => throw new NotImplementedException(); + public bool IsNestedPublic => throw new NotImplementedException(); + public bool IsPointer { get; } + public bool IsPrimitive => throw new NotImplementedException(); public bool IsPublic { get; } public bool IsSealed { get; } public bool IsSerializable { get; } - public bool IsValueType { get; } // TODO + public bool IsValueType => throw new NotImplementedException(); public override MemberTypes MemberType { get; }