Implement ParameterInfo and return parameters

This commit is contained in:
Katy Coe
2017-11-08 06:34:12 +01:00
parent fdeb85aaff
commit f5b6f66f35
3 changed files with 50 additions and 12 deletions

View File

@@ -17,14 +17,15 @@ namespace Il2CppInspector.Reflection
// TODO: CustomAttributes
// True if the parameter has a default value
public bool HasDefaultValue { get; }
public bool HasDefaultValue => (Attributes & ParameterAttributes.HasDefault) != 0;
// Default value for the parameter
public object DefaultValue { get; }
public object DefaultValue => throw new NotImplementedException();
public bool IsIn { get; }
public bool IsOptional { get; }
public bool IsOut { get; }
public bool IsIn => (Attributes & ParameterAttributes.In) != 0;
public bool IsOptional => (Attributes & ParameterAttributes.Optional) != 0;
public bool IsOut => (Attributes & ParameterAttributes.Out) != 0;
public bool IsRetval => (Attributes & ParameterAttributes.Retval) != 0;
// The member in which the parameter is defined
public MemberInfo Member { get; }
@@ -33,9 +34,39 @@ namespace Il2CppInspector.Reflection
public string Name { get; }
// Type of this parameter
public TypeInfo ParameterType { get; }
private readonly Il2CppType paramType;
public TypeInfo ParameterType => Member.Assembly.Model.GetType(paramType, MemberTypes.TypeInfo);
// Zero-indexed position of the parameter in parameter list
public int Position { get; }
public int Position { get; private set; }
// Create a parameter. Specify paramIndex == -1 for a return type parameter
public ParameterInfo(Il2CppInspector pkg, int paramIndex, MethodInfo declaringMethod) {
Member = declaringMethod;
if (paramIndex == -1) {
Position = -1;
paramType = pkg.TypeUsages[declaringMethod.Definition.returnType];
Attributes |= ParameterAttributes.Retval;
return;
}
var param = pkg.Metadata.Params[paramIndex];
Name = pkg.Metadata.Strings[param.nameIndex];
Position = paramIndex - declaringMethod.Definition.parameterStart;
paramType = pkg.TypeUsages[param.typeIndex];
if ((paramType.attrs & DefineConstants.PARAM_ATTRIBUTE_OPTIONAL) != 0)
Attributes |= ParameterAttributes.Optional;
if ((paramType.attrs & DefineConstants.PARAM_ATTRIBUTE_OUT) != 0)
Attributes |= ParameterAttributes.Out;
if (Position == -1)
Attributes |= ParameterAttributes.Retval;
else if (!IsOut)
Attributes |= ParameterAttributes.In;
// TODO: DefaultValue/HasDefaultValue
}
}
}