Allow short member names for static resolvers (#145)

This commit is contained in:
Govorunb 2023-11-08 17:53:02 +11:00 committed by GitHub
parent 7eb8291c31
commit 86fed7a830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 26 deletions

View File

@ -12,17 +12,23 @@ namespace TriInspector.Resolvers
public static bool TryResolve(TriPropertyDefinition propertyDefinition, string expression,
out ValueResolver<T> resolver)
{
if (expression.IndexOf('.') == -1)
{
resolver = null;
return false;
}
var type = propertyDefinition.OwnerType;
var fieldName = expression;
var separatorIndex = expression.LastIndexOf('.');
var className = expression.Substring(0, separatorIndex);
var methodName = expression.Substring(separatorIndex + 1);
if (separatorIndex >= 0)
{
var className = expression.Substring(0, separatorIndex);
fieldName = expression.Substring(separatorIndex + 1);
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out var type))
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out type))
{
resolver = null;
return false;
}
}
if (type == null)
{
resolver = null;
return false;
@ -32,7 +38,7 @@ namespace TriInspector.Resolvers
foreach (var fieldInfo in type.GetFields(flags))
{
if (fieldInfo.Name == methodName &&
if (fieldInfo.Name == fieldName &&
typeof(T).IsAssignableFrom(fieldInfo.FieldType))
{
resolver = new StaticFieldValueResolver<T>(fieldInfo);

View File

@ -12,17 +12,23 @@ namespace TriInspector.Resolvers
public static bool TryResolve(TriPropertyDefinition propertyDefinition, string expression,
out ValueResolver<T> resolver)
{
if (expression.IndexOf('.') == -1)
{
resolver = null;
return false;
}
var type = propertyDefinition.OwnerType;
var methodName = expression;
var separatorIndex = expression.LastIndexOf('.');
var className = expression.Substring(0, separatorIndex);
var methodName = expression.Substring(separatorIndex + 1);
if (separatorIndex >= 0)
{
var className = expression.Substring(0, separatorIndex);
methodName = expression.Substring(separatorIndex + 1);
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out var type))
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out type))
{
resolver = null;
return false;
}
}
if (type == null)
{
resolver = null;
return false;

View File

@ -12,17 +12,23 @@ namespace TriInspector.Resolvers
public static bool TryResolve(TriPropertyDefinition propertyDefinition, string expression,
out ValueResolver<T> resolver)
{
if (expression.IndexOf('.') == -1)
{
resolver = null;
return false;
}
var type = propertyDefinition.OwnerType;
var propertyName = expression;
var separatorIndex = expression.LastIndexOf('.');
var className = expression.Substring(0, separatorIndex);
var methodName = expression.Substring(separatorIndex + 1);
if (separatorIndex >= 0)
{
var className = expression.Substring(0, separatorIndex);
propertyName = expression.Substring(separatorIndex + 1);
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out var type))
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out type))
{
resolver = null;
return false;
}
}
if (type == null)
{
resolver = null;
return false;
@ -32,7 +38,7 @@ namespace TriInspector.Resolvers
foreach (var propertyInfo in type.GetProperties(flags))
{
if (propertyInfo.Name == methodName &&
if (propertyInfo.Name == propertyName &&
typeof(T).IsAssignableFrom(propertyInfo.PropertyType) &&
propertyInfo.CanRead)
{