Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions Editor/Resolvers/StaticFieldValueResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ public class StaticFieldValueResolver<T> : ValueResolver<T>
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 type))
{
resolver = null;
return false;
}
}

if (!TriReflectionUtilities.TryFindTypeByFullName(className, out var type))
if (type == null)
{
resolver = null;
return false;
Expand All @@ -32,7 +38,7 @@ public static bool TryResolve(TriPropertyDefinition propertyDefinition, string e

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);
Expand Down
22 changes: 14 additions & 8 deletions Editor/Resolvers/StaticMethodValueResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ public class StaticMethodValueResolver<T> : ValueResolver<T>
public static bool TryResolve(TriPropertyDefinition propertyDefinition, string expression,
out ValueResolver<T> resolver)
{
if (expression.IndexOf('.') == -1)
var type = propertyDefinition.OwnerType;
var methodName = expression;

var separatorIndex = expression.LastIndexOf('.');
if (separatorIndex >= 0)
{
resolver = null;
return false;
}
var className = expression.Substring(0, separatorIndex);
methodName = expression.Substring(separatorIndex + 1);

var separatorIndex = expression.LastIndexOf('.');
var className = expression.Substring(0, separatorIndex);
var methodName = expression.Substring(separatorIndex + 1);
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out type))
{
resolver = null;
return false;
}
}

if (!TriReflectionUtilities.TryFindTypeByFullName(className, out var type))
if (type == null)
{
resolver = null;
return false;
Expand Down
24 changes: 15 additions & 9 deletions Editor/Resolvers/StaticPropertyValueResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ public class StaticPropertyValueResolver<T> : ValueResolver<T>
public static bool TryResolve(TriPropertyDefinition propertyDefinition, string expression,
out ValueResolver<T> resolver)
{
if (expression.IndexOf('.') == -1)
var type = propertyDefinition.OwnerType;
var propertyName = expression;

var separatorIndex = expression.LastIndexOf('.');
if (separatorIndex >= 0)
{
resolver = null;
return false;
}
var className = expression.Substring(0, separatorIndex);
propertyName = expression.Substring(separatorIndex + 1);

var separatorIndex = expression.LastIndexOf('.');
var className = expression.Substring(0, separatorIndex);
var methodName = expression.Substring(separatorIndex + 1);
if (!TriReflectionUtilities.TryFindTypeByFullName(className, out type))
{
resolver = null;
return false;
}
}

if (!TriReflectionUtilities.TryFindTypeByFullName(className, out var type))
if (type == null)
{
resolver = null;
return false;
Expand All @@ -32,7 +38,7 @@ public static bool TryResolve(TriPropertyDefinition propertyDefinition, string e

foreach (var propertyInfo in type.GetProperties(flags))
{
if (propertyInfo.Name == methodName &&
if (propertyInfo.Name == propertyName &&
typeof(T).IsAssignableFrom(propertyInfo.PropertyType) &&
propertyInfo.CanRead)
{
Expand Down