/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/OneScript.Core/Contexts/ContextPropertyInfo.cs
107 строк
4 KB
EvilBeaver
Удален устаревший метод OnAttach и массово исправлены неиспользуемые using
02 дек 2025, 11:20
02 дек 2025, 11:20
0301fed
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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.Reflection; using OneScript.Commons; namespace OneScript.Contexts { /// <summary> /// Свойство, объявленое в CLR-классе через атрибут ContextProperty /// </summary> public class ContextPropertyInfo : BslPropertyInfo, IObjectWrapper, ISupportsDeprecation { private readonly PropertyInfo _realProperty; private readonly ContextPropertyAttribute _scriptMark; public ContextPropertyInfo(PropertyInfo wrappedInfo) : this(wrappedInfo, wrappedInfo.GetCustomAttribute<ContextPropertyAttribute>(false)) { } public ContextPropertyInfo(PropertyInfo wrappedInfo, ContextPropertyAttribute binding) { _realProperty = wrappedInfo; _scriptMark = binding; } public override object[] GetCustomAttributes(bool inherit) { return _realProperty.GetCustomAttributes(inherit); } public override object[] GetCustomAttributes(Type attributeType, bool inherit) { return _realProperty.GetCustomAttributes(attributeType, inherit); } public override bool IsDefined(Type attributeType, bool inherit) { return _realProperty.IsDefined(attributeType, inherit); } public override bool Equals(BslPropertyInfo other) { return (other is ContextPropertyInfo ctxProp) && ctxProp._realProperty.Equals(_realProperty); } public override Type DeclaringType => _realProperty.DeclaringType; public override Type ReflectedType => _realProperty.ReflectedType; public override string Name => _scriptMark.Name; public override string Alias => _scriptMark.Alias; public override MethodInfo[] GetAccessors(bool nonPublic) { var getter = GetGetMethod(nonPublic); var setter = GetSetMethod(nonPublic); if (getter != null && setter != null) { return new [] {getter, setter}; } return setter == null ? new [] {getter} : new [] {setter}; } public override MethodInfo GetGetMethod(bool nonPublic) { return CanRead ? _realProperty.GetGetMethod(nonPublic) : null; } public override ParameterInfo[] GetIndexParameters() { return Array.Empty<ParameterInfo>(); } public override MethodInfo GetSetMethod(bool nonPublic) { return CanWrite ? _realProperty.GetSetMethod(nonPublic) : null; } public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) { throw new NotImplementedException(); } public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) { throw new NotImplementedException(); } public override PropertyAttributes Attributes => _realProperty.Attributes; public override bool CanRead => _scriptMark.CanRead; public override bool CanWrite => _scriptMark.CanWrite; public override Type PropertyType => _realProperty.PropertyType; public object UnderlyingObject => _realProperty; public bool IsDeprecated => _scriptMark.IsDeprecated; public bool IsForbiddenToUse => _scriptMark.ThrowOnUse; } }