-
Notifications
You must be signed in to change notification settings - Fork 112
Конвертеры CLR-BSL #1566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akpaevj
wants to merge
8
commits into
EvilBeaver:develop
Choose a base branch
from
akpaevj:feature/clr-objects-wrappers
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+446
−69
Open
Конвертеры CLR-BSL #1566
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7c6e30e
Добавлено автоматическое оборачивание не AutoContext объекта во врапп…
akpaevj 8f8badf
Исправлена ошибка передачи NonBslWrapper в качестве параметра метода
akpaevj b70bc6e
Добавлены шапки лицензии
akpaevj 246c18b
Исправлена ошибка передачи NotВslWrapper в свойство NotВslWrapper. ак…
akpaevj 2c193be
В обертку добавлен конвертер возвращаемого значения
akpaevj bed0b39
Правки по ревью
akpaevj 36af65e
Добавлено кеширование свойств и методов для нижележащего типа в целом…
akpaevj 55eeeb3
Локер инициализации NotBslValueWrapper исправлен на статический экзем…
akpaevj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /*---------------------------------------------------------- | ||
| 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.Linq; | ||
| using ScriptEngine.Machine; | ||
|
|
||
| namespace OneScript.Contexts | ||
| { | ||
| public interface IContextValueConverter<TClr> | ||
| { | ||
| IValue ToIValue(TClr obj); | ||
|
|
||
| TClr ToClr(IValue obj); | ||
|
|
||
| public static bool ImplementsIt(Type type) | ||
| => type.GetInterfaces() | ||
| .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IContextValueConverter<>)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,8 @@ namespace ScriptEngine.Machine.Contexts | |
| { | ||
| public class PropertyTarget<TInstance> | ||
| { | ||
| private readonly BslPropertyInfo _propertyInfo; | ||
|
|
||
| private readonly ContextPropertyInfo _propertyInfo; | ||
| public PropertyTarget(PropertyInfo propInfo) | ||
| { | ||
| _propertyInfo = new ContextPropertyInfo(propInfo); | ||
|
|
@@ -27,16 +27,6 @@ public PropertyTarget(PropertyInfo propInfo) | |
| if (string.IsNullOrEmpty(Alias)) | ||
| Alias = propInfo.Name; | ||
|
|
||
| IValue CantReadAction(TInstance inst) | ||
| { | ||
| throw PropertyAccessException.PropIsNotReadableException(Name); | ||
| } | ||
|
|
||
| void CantWriteAction(TInstance inst, IValue val) | ||
| { | ||
| throw PropertyAccessException.PropIsNotWritableException(Name); | ||
| } | ||
|
|
||
| if (_propertyInfo.CanRead) | ||
| { | ||
| var getMethodInfo = propInfo.GetGetMethod(); | ||
|
|
@@ -84,6 +74,18 @@ void CantWriteAction(TInstance inst, IValue val) | |
| { | ||
| Setter = CantWriteAction; | ||
| } | ||
|
|
||
| return; | ||
|
|
||
| void CantWriteAction(TInstance inst, IValue val) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а чем помешали в качестве локальных методов? |
||
| { | ||
| throw PropertyAccessException.PropIsNotWritableException(Name); | ||
| } | ||
|
|
||
| IValue CantReadAction(TInstance inst) | ||
| { | ||
| throw PropertyAccessException.PropIsNotReadableException(Name); | ||
| } | ||
| } | ||
|
|
||
| public Func<TInstance, IValue> Getter { get; } | ||
|
|
@@ -108,19 +110,18 @@ private Func<TInstance, IValue> CreateGetter<T>(MethodInfo methInfo) | |
| private Action<TInstance, IValue> CreateSetter<T>(MethodInfo methInfo) | ||
| { | ||
| var method = (Action<TInstance, T>)Delegate.CreateDelegate(typeof(Action<TInstance, T>), methInfo); | ||
| return (inst, val) => method(inst, ConvertParam<T>(val)); | ||
| return (inst, val) => method(inst, ConvertValue<T>(val)); | ||
| } | ||
|
|
||
| private static T ConvertParam<T>(IValue value) | ||
| { | ||
| return ContextValuesMarshaller.ConvertValueStrict<T>(value); | ||
| } | ||
|
|
||
| private static IValue ConvertReturnValue<TRet>(TRet param) | ||
| { | ||
| return ContextValuesMarshaller.ConvertReturnValue(param); | ||
| } | ||
| private T ConvertValue<T>(IValue value) | ||
| => _propertyInfo.TryGetStrictConverter<T>(out var converter) ? | ||
| converter.ToClr(value) | ||
| : ContextValuesMarshaller.ConvertValueStrict<T>(value); | ||
|
|
||
| private IValue ConvertReturnValue<TRet>(TRet param) | ||
| => _propertyInfo.TryGetStrictConverter<TRet>(out var converter) | ||
| ? converter!.ToIValue(param) | ||
| : ContextValuesMarshaller.ConvertReturnValue(param); | ||
| } | ||
|
|
||
| public class ContextPropertyMapper<TInstance> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не совсем понял, какой смысл в этом методе, что если я укажу в атрибуте в качестве конвертера typeof(Int32) и получу тут число? Может он должен быть private?