/
smwwiki
/
OneScript_fork
Обзор
Документация
Войти
/
smwwiki
/
OneScript_fork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/OneScript.Core/Contexts/ContextMethodInfo.cs
106 строк
4 KB
EvilBeaver
Поправил мелкие замечания сонара
24 апр 2024, 13:50
24 апр 2024, 13:50
ebfc286
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; using System.Globalization; using System.Linq; using System.Reflection; using OneScript.Commons; namespace OneScript.Contexts { /// <summary> /// Информация о методе, объявленном в классе .NET и помеченном атрибутом ContextMethod /// </summary> public sealed class ContextMethodInfo : BslMethodInfo, IObjectWrapper { private readonly MethodInfo _realMethod; private readonly ContextMethodAttribute _scriptMark; public ContextMethodInfo(MethodInfo realMethod) { _realMethod = realMethod; try { _scriptMark = (ContextMethodAttribute) GetCustomAttributes(typeof(ContextMethodAttribute), false).First(); } catch (InvalidOperationException e) { throw new ArgumentException("Method is not marked with ContextMethodAttribute", e); } } public ContextMethodInfo(MethodInfo realMethod, ContextMethodAttribute binding) { _realMethod = realMethod; _scriptMark = binding; } public override Type ReturnType => _realMethod.ReturnType; public override ParameterInfo ReturnParameter => _realMethod.ReturnParameter; public bool IsDeprecated => _scriptMark.IsDeprecated; public bool IsForbiddenToUse => _scriptMark.ThrowOnUse; public override object[] GetCustomAttributes(bool inherit) { return _realMethod.GetCustomAttributes(inherit); } public override object[] GetCustomAttributes(Type attributeType, bool inherit) { return _realMethod.GetCustomAttributes(attributeType, inherit); } public override bool IsDefined(Type attributeType, bool inherit) { return _realMethod.IsDefined(attributeType, inherit); } public override ParameterInfo[] GetParameters() { return _realMethod.GetParameters(); } public override MethodImplAttributes GetMethodImplementationFlags() { return _realMethod.GetMethodImplementationFlags(); } public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { return _realMethod.Invoke(obj, invokeAttr, binder, parameters, culture); } public override MethodInfo GetBaseDefinition() { return _realMethod.GetBaseDefinition(); } public override ICustomAttributeProvider ReturnTypeCustomAttributes => _realMethod.ReturnTypeCustomAttributes; public override string Name => _scriptMark.GetName(); public override string Alias => _scriptMark.GetAlias(); public override Type DeclaringType => _realMethod.DeclaringType; public override Type ReflectedType => _realMethod.ReflectedType; public override RuntimeMethodHandle MethodHandle => _realMethod.MethodHandle; public override MethodAttributes Attributes => _realMethod.Attributes; public object UnderlyingObject => _realMethod; public MethodInfo GetWrappedMethod() => _realMethod; } }