Code reformatting
This commit is contained in:
@@ -12,7 +12,8 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Il2CppInspector.Reflection {
|
namespace Il2CppInspector.Reflection
|
||||||
|
{
|
||||||
public class TypeInfo : MemberInfo
|
public class TypeInfo : MemberInfo
|
||||||
{
|
{
|
||||||
// IL2CPP-specific data
|
// IL2CPP-specific data
|
||||||
@@ -100,7 +101,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
get {
|
get {
|
||||||
if (declaredConstructors != null)
|
if (declaredConstructors != null)
|
||||||
return declaredConstructors.AsReadOnly();
|
return declaredConstructors.AsReadOnly();
|
||||||
if(genericTypeDefinition != null) {
|
if (genericTypeDefinition != null) {
|
||||||
var result = genericTypeDefinition.DeclaredConstructors.Select(c => new ConstructorInfo(c, this)).ToList();
|
var result = genericTypeDefinition.DeclaredConstructors.Select(c => new ConstructorInfo(c, this)).ToList();
|
||||||
declaredConstructors = result;
|
declaredConstructors = result;
|
||||||
return result.AsReadOnly();
|
return result.AsReadOnly();
|
||||||
@@ -374,7 +375,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
return null;
|
return null;
|
||||||
if (HasElementType) {
|
if (HasElementType) {
|
||||||
var n = ElementType.FullName;
|
var n = ElementType.FullName;
|
||||||
if(n == null)
|
if (n == null)
|
||||||
return null;
|
return null;
|
||||||
if (IsArray)
|
if (IsArray)
|
||||||
n += "[" + new string(',', GetArrayRank() - 1) + "]";
|
n += "[" + new string(',', GetArrayRank() - 1) + "]";
|
||||||
@@ -439,7 +440,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
|
|
||||||
// If the scope of usage is inside the scope in which the type is declared, no additional scope is needed
|
// If the scope of usage is inside the scope in which the type is declared, no additional scope is needed
|
||||||
// but we still need to check for ancestor conflicts below
|
// but we still need to check for ancestor conflicts below
|
||||||
usingScopeIsChildOfDeclaringScope? declaringScope
|
usingScopeIsChildOfDeclaringScope ? declaringScope
|
||||||
|
|
||||||
// Check to see if there is a namespace in our using directives which brings this type into scope
|
// Check to see if there is a namespace in our using directives which brings this type into scope
|
||||||
// Sort by descending order of length to search the deepest namespaces first
|
// Sort by descending order of length to search the deepest namespaces first
|
||||||
@@ -453,8 +454,8 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// The first two must be checked in this order to avoid a . at the start
|
// The first two must be checked in this order to avoid a . at the start
|
||||||
// when the mutual root scope and declaring scope are both empty
|
// when the mutual root scope and declaring scope are both empty
|
||||||
var minimallyScopedName =
|
var minimallyScopedName =
|
||||||
declaringScope == mutualRootScope? base.Name :
|
declaringScope == mutualRootScope ? base.Name :
|
||||||
string.IsNullOrEmpty(mutualRootScope)? declaringScope + '.' + base.Name :
|
string.IsNullOrEmpty(mutualRootScope) ? declaringScope + '.' + base.Name :
|
||||||
declaringScope.Substring(mutualRootScope.Length + 1) + '.' + base.Name;
|
declaringScope.Substring(mutualRootScope.Length + 1) + '.' + base.Name;
|
||||||
|
|
||||||
// Find the outermost type name if the wanted type is a nested type (if we need it below)
|
// Find the outermost type name if the wanted type is a nested type (if we need it below)
|
||||||
@@ -469,16 +470,16 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// If the using scope is a child of the declaring scope, we can try every parent scope until we find one that doesn't hide the type
|
// If the using scope is a child of the declaring scope, we can try every parent scope until we find one that doesn't hide the type
|
||||||
// Otherwise, we just try the unqualified outer (least nested) type name to make sure it's accessible
|
// Otherwise, we just try the unqualified outer (least nested) type name to make sure it's accessible
|
||||||
// and revert to the fully qualified name if it's hidden
|
// and revert to the fully qualified name if it's hidden
|
||||||
var nsAndTypeHierarchy = usingScopeIsChildOfDeclaringScope?
|
var nsAndTypeHierarchy = usingScopeIsChildOfDeclaringScope ?
|
||||||
usingDirective.Split('.').Append(minimallyScopedName).ToArray()
|
usingDirective.Split('.').Append(minimallyScopedName).ToArray()
|
||||||
: new [] {outerTypeName};
|
: new[] { outerTypeName };
|
||||||
|
|
||||||
var hidden = true;
|
var hidden = true;
|
||||||
var foundTypeInAncestorScope = false;
|
var foundTypeInAncestorScope = false;
|
||||||
string testTypeName = "";
|
string testTypeName = "";
|
||||||
|
|
||||||
for (var depth = nsAndTypeHierarchy.Length - 1; depth >= 0 && hidden; depth--) {
|
for (var depth = nsAndTypeHierarchy.Length - 1; depth >= 0 && hidden; depth--) {
|
||||||
testTypeName = nsAndTypeHierarchy[depth] + (testTypeName.Length > 0? "." : "") + testTypeName;
|
testTypeName = nsAndTypeHierarchy[depth] + (testTypeName.Length > 0 ? "." : "") + testTypeName;
|
||||||
|
|
||||||
hidden = false;
|
hidden = false;
|
||||||
for (var d = scope.Current; d != null && !hidden && !foundTypeInAncestorScope; d = d.DeclaringType) {
|
for (var d = scope.Current; d != null && !hidden && !foundTypeInAncestorScope; d = d.DeclaringType) {
|
||||||
@@ -491,7 +492,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// For a child scope, use the shortest found scope
|
// For a child scope, use the shortest found scope
|
||||||
// Otherwise, we've confirmed the outer nested type name is not hidden so go ahead and use the nested type name without a namespace
|
// Otherwise, we've confirmed the outer nested type name is not hidden so go ahead and use the nested type name without a namespace
|
||||||
if (!hidden)
|
if (!hidden)
|
||||||
minimallyScopedName = usingScopeIsChildOfDeclaringScope? testTypeName : Name.Replace('+', '.');
|
minimallyScopedName = usingScopeIsChildOfDeclaringScope ? testTypeName : Name.Replace('+', '.');
|
||||||
|
|
||||||
// If the wanted type is an unhidden ancestor, we don't need any additional scope at all
|
// If the wanted type is an unhidden ancestor, we don't need any additional scope at all
|
||||||
if (foundTypeInAncestorScope)
|
if (foundTypeInAncestorScope)
|
||||||
@@ -548,7 +549,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// for generic type parameters
|
// for generic type parameters
|
||||||
var outerScope = usingScope;
|
var outerScope = usingScope;
|
||||||
if (isPartOfTypeDeclaration)
|
if (isPartOfTypeDeclaration)
|
||||||
outerScope = new Scope {Current = usingScope.Current?.DeclaringType, Namespaces = usingScope.Namespaces};
|
outerScope = new Scope { Current = usingScope.Current?.DeclaringType, Namespaces = usingScope.Namespaces };
|
||||||
|
|
||||||
var g = string.Join(", ", getGenericTypeParameters(usingScope).Select(x => x.GetScopedCSharpName(outerScope)));
|
var g = string.Join(", ", getGenericTypeParameters(usingScope).Select(x => x.GetScopedCSharpName(outerScope)));
|
||||||
if (!string.IsNullOrEmpty(g))
|
if (!string.IsNullOrEmpty(g))
|
||||||
@@ -562,7 +563,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
if (HasElementType)
|
if (HasElementType)
|
||||||
n = ElementType.GetScopedCSharpName(usingScope);
|
n = ElementType.GetScopedCSharpName(usingScope);
|
||||||
|
|
||||||
return (IsByRef && !omitRef? "ref " : "") + n + (IsArray ? "[" + new string(',', GetArrayRank() - 1) + "]" : "") + (IsPointer ? "*" : "");
|
return (IsByRef && !omitRef ? "ref " : "") + n + (IsArray ? "[" + new string(',', GetArrayRank() - 1) + "]" : "") + (IsPointer ? "*" : "");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -675,7 +676,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
private readonly int arrayRank;
|
private readonly int arrayRank;
|
||||||
public int GetArrayRank() => arrayRank;
|
public int GetArrayRank() => arrayRank;
|
||||||
|
|
||||||
public string[] GetEnumNames() => IsEnum? DeclaredFields.Where(x => x.Name != "value__").Select(x => x.Name).ToArray() : throw new InvalidOperationException("Type is not an enumeration");
|
public string[] GetEnumNames() => IsEnum ? DeclaredFields.Where(x => x.Name != "value__").Select(x => x.Name).ToArray() : throw new InvalidOperationException("Type is not an enumeration");
|
||||||
|
|
||||||
// The underlying type of an enumeration (int by default)
|
// The underlying type of an enumeration (int by default)
|
||||||
private readonly TypeRef enumUnderlyingTypeReference = null;
|
private readonly TypeRef enumUnderlyingTypeReference = null;
|
||||||
@@ -686,7 +687,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
return enumUnderlyingTypeReference.Value;
|
return enumUnderlyingTypeReference.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array GetEnumValues() => IsEnum? DeclaredFields.Where(x => x.Name != "value__").Select(x => x.DefaultValue).ToArray() : throw new InvalidOperationException("Type is not an enumeration");
|
public Array GetEnumValues() => IsEnum ? DeclaredFields.Where(x => x.Name != "value__").Select(x => x.DefaultValue).ToArray() : throw new InvalidOperationException("Type is not an enumeration");
|
||||||
|
|
||||||
// Initialize type from TypeDef using specified index in metadata
|
// Initialize type from TypeDef using specified index in metadata
|
||||||
public TypeInfo(int typeIndex, Assembly owner) : base(owner) {
|
public TypeInfo(int typeIndex, Assembly owner) : base(owner) {
|
||||||
@@ -811,8 +812,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
if (pairedEip.FirstOrDefault(pe => pe.get == null && pe.set.Name == p.Name.Replace(".get_", ".set_")) is (MethodInfo get, MethodInfo set) method) {
|
if (pairedEip.FirstOrDefault(pe => pe.get == null && pe.set.Name == p.Name.Replace(".get_", ".set_")) is (MethodInfo get, MethodInfo set) method) {
|
||||||
pairedEip.Remove(method);
|
pairedEip.Remove(method);
|
||||||
pairedEip.Add((p, method.set));
|
pairedEip.Add((p, method.set));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
pairedEip.Add((p, null));
|
pairedEip.Add((p, null));
|
||||||
|
|
||||||
// Find getter with no matching setter
|
// Find getter with no matching setter
|
||||||
@@ -820,8 +820,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
if (pairedEip.FirstOrDefault(pe => pe.set == null && pe.get.Name == p.Name.Replace(".set_", ".get_")) is (MethodInfo get, MethodInfo set) method) {
|
if (pairedEip.FirstOrDefault(pe => pe.set == null && pe.get.Name == p.Name.Replace(".set_", ".get_")) is (MethodInfo get, MethodInfo set) method) {
|
||||||
pairedEip.Remove(method);
|
pairedEip.Remove(method);
|
||||||
pairedEip.Add((method.get, p));
|
pairedEip.Add((method.get, p));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
pairedEip.Add((null, p));
|
pairedEip.Add((null, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -882,9 +881,9 @@ namespace Il2CppInspector.Reflection {
|
|||||||
return typeArguments[GenericParameterPosition];
|
return typeArguments[GenericParameterPosition];
|
||||||
else if (IsGenericMethodParameter)
|
else if (IsGenericMethodParameter)
|
||||||
return methodArguments[GenericParameterPosition];
|
return methodArguments[GenericParameterPosition];
|
||||||
else if(IsGenericTypeDefinition)
|
else if (IsGenericTypeDefinition)
|
||||||
return MakeGenericType(typeArguments);
|
return MakeGenericType(typeArguments);
|
||||||
else if(HasElementType) {
|
else if (HasElementType) {
|
||||||
var elementType = ElementType.SubstituteGenericArguments(typeArguments, methodArguments);
|
var elementType = ElementType.SubstituteGenericArguments(typeArguments, methodArguments);
|
||||||
if (IsArray)
|
if (IsArray)
|
||||||
return elementType.MakeArrayType(GetArrayRank());
|
return elementType.MakeArrayType(GetArrayRank());
|
||||||
@@ -1074,7 +1073,8 @@ namespace Il2CppInspector.Reflection {
|
|||||||
return refList.ToList();
|
return refList.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetAccessModifierString() => this switch {
|
public string GetAccessModifierString() => this switch
|
||||||
|
{
|
||||||
{ IsPublic: true } => "public ",
|
{ IsPublic: true } => "public ",
|
||||||
{ IsNotPublic: true } => "internal ",
|
{ IsNotPublic: true } => "internal ",
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user