Skip to content

Commit 10b97bc

Browse files
committed
проверка метода объекта и откат на динамическое определение
1 parent 33dbfe2 commit 10b97bc

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

src/OneScript.Native/Compiler/MethodCompiler.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,20 +1131,21 @@ private Expression CreateObjectMethodCall(BslSyntaxNode node, bool asFunction =
11311131
var targetType = target.Type;
11321132
var name = call.Identifier.GetIdentifier();
11331133

1134-
if (targetType.IsObjectValue())
1134+
if (targetType.IsObjectValue()
1135+
&& TryFindMethodOfType(targetType, name, out var methodInfo))
11351136
{
1136-
var methodInfo = FindMethodOfType(node, targetType, name);
1137-
if (asFunction && methodInfo.ReturnType == typeof(void))
1138-
{
1139-
throw new NativeCompilerException(BilingualString.Localize(
1140-
$"Метод {targetType}.{name} не является функцией",
1141-
$"Method {targetType}.{name} is not a function"), ToCodePosition(node.Location));
1142-
}
1143-
1144-
var args = PrepareCallArguments(call.ArgumentList, methodInfo.GetParameters(), InjectedProcessNeeded(methodInfo));
1145-
return Expression.Call(target, methodInfo, args);
1137+
if (asFunction && methodInfo?.ReturnType == typeof(void))
1138+
{
1139+
throw new NativeCompilerException(BilingualString.Localize(
1140+
$"Метод {targetType}.{name} не является функцией",
1141+
$"Method {targetType}.{name} is not a function"), ToCodePosition(node.Location));
1142+
}
1143+
1144+
var args = PrepareCallArguments(call.ArgumentList, methodInfo.GetParameters(), InjectedProcessNeeded(methodInfo));
1145+
return Expression.Call(target, methodInfo, args);
11461146
}
1147-
else if (targetType.IsContext())
1147+
1148+
if (targetType.IsContext())
11481149
{
11491150
return ExpressionHelpers.CallContextMethod(target, name, _processParameter,
11501151
PrepareDynamicCallArguments(call.ArgumentList));
@@ -1200,6 +1201,21 @@ private MethodInfo FindMethodOfType(BslSyntaxNode node, Type targetType, string
12001201
return methodInfo;
12011202
}
12021203

1204+
private bool TryFindMethodOfType(Type targetType, string name, out MethodInfo methodInfo)
1205+
{
1206+
try
1207+
{
1208+
methodInfo = _methodsCache.GetOrAdd(targetType, name);
1209+
}
1210+
catch (InvalidOperationException)
1211+
{
1212+
methodInfo = null;
1213+
return false;
1214+
}
1215+
1216+
return true;
1217+
}
1218+
12031219
private PropertyInfo TryFindPropertyOfType(BslSyntaxNode node, Type targetType, string name)
12041220
{
12051221
PropertyInfo propertyInfo;

0 commit comments

Comments
 (0)