-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement injectable converters (#39)
implemented injectable type converters
- Loading branch information
Showing
28 changed files
with
1,229 additions
and
162 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=abap/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains 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 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,16 @@ | ||
namespace Dbosoft.YaNco.TypeMapping | ||
{ | ||
public class FieldMappingContext | ||
{ | ||
public readonly IRfcRuntime RfcRuntime; | ||
public readonly IDataContainerHandle Handle; | ||
public readonly RfcFieldInfo FieldInfo; | ||
|
||
public FieldMappingContext(IRfcRuntime rfcRuntime, IDataContainerHandle handle, RfcFieldInfo fieldInfo) | ||
{ | ||
RfcRuntime = rfcRuntime; | ||
Handle = handle; | ||
FieldInfo = fieldInfo; | ||
} | ||
} | ||
} |
This file contains 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,11 @@ | ||
using LanguageExt; | ||
|
||
namespace Dbosoft.YaNco.TypeMapping | ||
{ | ||
public interface IFieldMapper | ||
{ | ||
Either<RfcErrorInfo, Unit> SetField<T>(T value, FieldMappingContext context); | ||
Either<RfcErrorInfo, T> GetField<T>(FieldMappingContext context); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/YaNco.Abstractions/TypeMapping/IFromAbapValueConverter.cs
This file contains 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,11 @@ | ||
using LanguageExt; | ||
|
||
namespace Dbosoft.YaNco.TypeMapping | ||
{ | ||
public interface IFromAbapValueConverter<T> | ||
{ | ||
Try<T> ConvertTo(AbapValue abapValue); | ||
bool CanConvertTo(RfcType rfcType); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/YaNco.Abstractions/TypeMapping/IRfcConverterResolver.cs
This file contains 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,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Dbosoft.YaNco.TypeMapping | ||
{ | ||
public interface IRfcConverterResolver | ||
{ | ||
IEnumerable<IToAbapValueConverter<T>> GetToRfcConverters<T>(RfcType rfcType); | ||
IEnumerable<IFromAbapValueConverter<T>> GetFromRfcConverters<T>(RfcType rfcType, Type abapValueType); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/YaNco.Abstractions/TypeMapping/IToAbapValueConverter.cs
This file contains 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,11 @@ | ||
using LanguageExt; | ||
|
||
namespace Dbosoft.YaNco.TypeMapping | ||
{ | ||
public interface IToAbapValueConverter<T> | ||
{ | ||
Try<AbapValue> ConvertFrom(T value, RfcFieldInfo fieldInfo); | ||
bool CanConvertFrom(RfcType rfcType); | ||
|
||
} | ||
} |
This file contains 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 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 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 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 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,49 @@ | ||
using System; | ||
using LanguageExt; | ||
|
||
namespace Dbosoft.YaNco.TypeMapping | ||
{ | ||
public class ByteValueConverter: IToAbapValueConverter<byte[]>, IFromAbapValueConverter<byte[]> | ||
{ | ||
public Try<AbapValue> ConvertFrom(byte[] value, RfcFieldInfo fieldInfo) | ||
{ | ||
return Prelude.Try<AbapValue>(() => | ||
{ | ||
if (!IsSupportedRfcType(fieldInfo.Type)) | ||
throw new NotSupportedException($"Cannot convert from RfcType {fieldInfo.Type} to byte array."); | ||
|
||
return new AbapByteValue(fieldInfo, value); | ||
}); | ||
|
||
} | ||
|
||
public bool CanConvertFrom(RfcType rfcType) | ||
{ | ||
return IsSupportedRfcType(rfcType); | ||
} | ||
|
||
public Try<byte[]> ConvertTo(AbapValue abapValue) | ||
{ | ||
return Prelude.Try(() => (abapValue as AbapByteValue)?.Value); | ||
} | ||
|
||
public bool CanConvertTo(RfcType rfcType) | ||
{ | ||
return IsSupportedRfcType(rfcType); | ||
} | ||
|
||
private bool IsSupportedRfcType(RfcType rfcType) | ||
{ | ||
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault | ||
switch (rfcType) | ||
{ | ||
case RfcType.BYTE: | ||
case RfcType.XSTRING: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.