Skip to content

Commit

Permalink
fix EvilBeaver#1464: если алиас не указан, то им будет имя метода
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Rm committed Oct 28, 2024
1 parent 99e2ca3 commit 8498477
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/OneScript.Core/Contexts/ClassBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ClassBuilder ExportClassMethod(MethodInfo nativeMethod)
}
else
{
var markup = new ContextMethodAttribute(nativeMethod.Name);
var markup = new ContextMethodAttribute(nativeMethod.Name, null); // no alias
_methods.Add(new ContextMethodInfo(nativeMethod, markup));
}

Expand Down
30 changes: 9 additions & 21 deletions src/OneScript.Core/Contexts/ContextMethodAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This Source Code Form is subject to the terms of the
----------------------------------------------------------*/

using System;
using System.Runtime.CompilerServices;
using OneScript.Commons;

namespace OneScript.Contexts
Expand All @@ -16,40 +17,27 @@ public class ContextMethodAttribute : Attribute
private readonly string _name;
private readonly string _alias;

public ContextMethodAttribute(string name, string alias = null)
public ContextMethodAttribute(string name, string alias)
{
if (!Utils.IsValidIdentifier(name))
throw new ArgumentException("Name must be a valid identifier");
throw new ArgumentException($"Name '{name}' must be a valid identifier");

if (!string.IsNullOrEmpty(alias) && !Utils.IsValidIdentifier(alias))
throw new ArgumentException("Alias must be a valid identifier");
throw new ArgumentException($"Alias '{alias}' must be a valid identifier");

_name = name;
_alias = alias;
}

public string GetName()
public ContextMethodAttribute(string name, string _ = null,
[CallerMemberName] string nativeMethodName = null)
: this(name, nativeMethodName)
{
return _name;
}

public string GetAlias()
{
return _alias;
}
public string GetName() => _name;

public string GetAlias(string nativeMethodName)
{
if (!string.IsNullOrEmpty(_alias))
{
return _alias;
}
if (!IsDeprecated)
{
return nativeMethodName;
}
return null;
}
public string GetAlias() => _alias;

public bool IsDeprecated { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/ScriptEngine/Machine/Contexts/ContextMethodMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static MethodSignature CreateMetadata(MethodInfo target, ContextMethodAt
scriptMethInfo.IsDeprecated = binding.IsDeprecated;
scriptMethInfo.ThrowOnUseDeprecated = binding.ThrowOnUse;
scriptMethInfo.Name = binding.GetName();
scriptMethInfo.Alias = binding.GetAlias(target.Name);
scriptMethInfo.Alias = binding.GetAlias();

scriptMethInfo.Params = paramDefs;

Expand Down

0 comments on commit 8498477

Please sign in to comment.