public static bool TryConvertTo(ISsslConverter converter, SsslObject sssl, Type type, ObjectConversionOptions options, [NotNullWhen(true)] out object result) { var allowUnknownMember = options.HasFlag(ObjectConversionOptions.AllowUnknownMember); var allowMissingMember = options.HasFlag(ObjectConversionOptions.AllowMissingMember); result = null !; if (!(sssl is SsslRecord record)) { return(false); } if (record.Name != "" && !type.IsSealed && record.Name != type.GetFullName()) { if (type.Assembly.GetType(record.Name) is { } assemblyInnerType&& type.IsAssignableFrom(assemblyInnerType)) { type = assemblyInnerType; } if (Type.GetType(record.Name) is { } coreType&& type.IsAssignableFrom(coreType)) { type = coreType; } else if (AppDomain.CurrentDomain .GetAssemblies() .Select(x => x.GetType(record.Name)) .FirstOrDefault(x => x is { } && type.IsAssignableFrom(x)) is { } otherType&&
public static T ConvertTo <T>(this ISsslConverter converter, SsslObject ssslObject) { if (converter is null) { throw new ArgumentNullException(nameof(converter)); } return((T)converter.ConvertTo(ssslObject, typeof(T)) !); }
public static object?ConvertTo(this ISsslConverter converter, SsslObject ssslObject, Type type) { if (converter is null) { throw new ArgumentNullException(nameof(converter)); } return(converter.TryConvertTo(ssslObject, type, out var result) ? result : throw new InvalidCastException()); }
public static SsslObject ConvertFrom(this ISsslConverter converter, object?value) { if (converter is null) { throw new ArgumentNullException(nameof(converter)); } return(converter.TryConvertFrom(value, out var result) ? result : throw new InvalidCastException()); }
public static bool TryConvertTo <T>(this ISsslConverter converter, SsslObject ssslObject, [MaybeNull] out T result) { if (converter is null) { throw new ArgumentNullException(nameof(converter)); } if (converter.TryConvertTo(ssslObject, typeof(T), out var obj)) { result = (T)obj !; return(true); } result = default !;
public static bool TryConvertFrom(ISsslConverter converter, object value, [NotNullWhen(true)] out SsslObject result) { var type = value.GetType(); var obj = new SsslRecord(SsslRecordType.Braces, type.GetFullName()); var values = GetModelInfo(type).ConvertFrom(value); foreach (var(name, val) in values) { if (!converter.TryConvertFrom(val, out var ssslVal)) { result = null !; return(false); } obj[name] = ssslVal; } result = obj; return(true); }
public dynamic ToDynamic(ISsslConverter converter) => new SsslDynamicProvider(this, converter);
internal SsslDynamicProvider(SsslObject ssslObject, ISsslConverter converter) { _ssslObject = ssslObject; _converter = converter; }
internal SsslDynamicProvider(SsslObject ssslObject) { _ssslObject = ssslObject; _converter = SsslConverter.Default; }