/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/OneScript.Core/Contexts/BslLambdaConstructorInfo.cs
96 строк
3 KB
Andrey Ovsiankin
Вынес отдельный неймспейс для Internal
30 авг 2021, 16:37
30 авг 2021, 16:37
a82c20e
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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.Collections.Generic; using System.Globalization; using System.Linq; using System.Reflection; using OneScript.Contexts.Internal; using OneScript.Types; using OneScript.Values; namespace OneScript.Contexts { public delegate BslValue InstanceConstructor(TypeActivationContext context, BslValue[] arguments); public class BslLambdaConstructorInfo : BslConstructorInfo, IBuildableMethod { private readonly InstanceConstructor _implementation; private Type _declaringType; internal BslLambdaConstructorInfo(InstanceConstructor implementation) { _implementation = implementation; } internal List<BslParameterInfo> Parameters { get; } = new List<BslParameterInfo>(); public override Type DeclaringType => _declaringType; public override string Name => ConstructorName; public override Type ReflectedType => _declaringType; public override ParameterInfo[] GetParameters() { return Parameters.Cast<ParameterInfo>().ToArray(); } public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { throw new NotImplementedException(); } public override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { if (parameters.Length > 1) { if (parameters[0] is TypeActivationContext activationContext) { return _implementation(activationContext, parameters.Skip(1).Cast<BslValue>().ToArray()); } } var context = new TypeActivationContext(); return _implementation(context, parameters.Cast<BslValue>().ToArray()); } void IBuildableMember.SetDeclaringType(Type type) { _declaringType = type; } void IBuildableMember.SetName(string name) { } void IBuildableMember.SetAlias(string alias) { } void IBuildableMember.SetExportFlag(bool isExport) { } void IBuildableMember.SetDataType(Type type) { } void IBuildableMember.SetAnnotations(IEnumerable<object> annotations) { } void IBuildableMember.SetDispatchIndex(int index) { } void IBuildableMethod.SetParameters(IEnumerable<BslParameterInfo> parameters) { Parameters.Clear(); Parameters.AddRange(parameters); } } }