public static bool Check(Type type, out ObjectCallerBase caller) { if (type is null) { throw new ArgumentNullException(nameof(type)); } caller = default; if (DynamicServiceTypeHelper.IsSupportedDynamicType(type)) { caller = DynamicServiceSlimObjectCallerBuilder.Ctor(type); return(true); } if (TupleServiceTypeHelper.IsSupportedTupleType(type)) { caller = TupleServiceSlimObjectCallerBuilder.Ctor(type); return(true); } #if !NETFRAMEWORK if (AnonymousServiceTypeHelper.IsSupportedAnonymousType(type)) { caller = AnonymousServiceSlimObjectCallerBuilder.Ctor(type); return(true); } #endif return(false); }
public static Dictionary <string, Lazy <IPropertyNodeVisitor> > New(ObjectCallerBase handler, ObjectVisitorOptions options) { var result = new Dictionary <string, Lazy <IPropertyNodeVisitor> >(); foreach (var member in handler.GetMembers()) { if (member is null) { continue; } if (member.MemberType.IsBasicType()) { result[member.MemberName] = null; } else { result[member.MemberName] = new(() => PropertyNodeFactory.Create(member, handler, options)); } } return(result); }
public FutureInstanceVisitor(ObjectCallerBase <T> handler, ObjectVisitorOptions options, IDictionary <string, object> initialValues = null) { _options = options?.Clone() ?? ObjectVisitorOptions.Default; _handler = handler ?? throw new ArgumentNullException(nameof(handler)); SourceType = typeof(T); _handler.New(); GenericHistoricalContext = _options.Repeatable ? new HistoricalContext <T>(_options.AlgorithmKind) : null; _objectOwnInfo = ObjectOwn.Of <T>(); _lazyMemberHandler = MemberHandler.Lazy(_handler, SourceType, _options.LiteMode); _correctnessContext = _options.StrictMode ? new CorrectnessContext <T>(this, true) : null; if (initialValues is not null) { SetValue(initialValues); } LazyPropertyNodes = RootNode.New(_handler, _options); }
public static IPropertyNodeVisitor Create(ObjectMember member, ObjectCallerBase parentHandlerPtr, ObjectVisitorOptions options) { void MemberValueSyncHandler(object instance) => parentHandlerPtr[member.MemberName] = instance; var handler = SafeObjectHandleSwitcher.Switch(options.AlgorithmKind)(member.MemberType).AndSetInstance(parentHandlerPtr.GetObject(member.MemberName)); var visitor = new InstanceVisitor(handler, member.MemberType, options); return(new PropertyNodeVisitor(member, visitor, options, MemberValueSyncHandler)); }
public StaticTypeObjectVisitor(ObjectCallerBase handler, Type targetType, ObjectVisitorOptions options) { _options = options?.Clone() ?? ObjectVisitorOptions.Default; _handler = handler ?? throw new ArgumentNullException(nameof(handler)); SourceType = targetType ?? throw new ArgumentNullException(nameof(targetType)); _objectOwnInfo = ObjectOwn.Of(targetType); _lazyMemberHandler = MemberHandler.Lazy(_handler, SourceType, _options.LiteMode); _correctnessContext = _options.StrictMode ? new CorrectnessContext(this, true) : null; LazyPropertyNodes = RootNode.New(_handler, _options.Clone(x => x.Repeatable = RpMode.NON_REPEATABLE)); }
public InstanceVisitor(ObjectCallerBase handler, Type sourceType, ObjectVisitorOptions options) { _options = options?.Clone() ?? ObjectVisitorOptions.Default; _handler = handler ?? throw new ArgumentNullException(nameof(handler)); SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); NormalHistoricalContext = _options.Repeatable ? new HistoricalContext(sourceType, _options.AlgorithmKind) : null; _objectOwnInfo = ObjectOwn.Of(sourceType); _lazyMemberHandler = MemberHandler.Lazy(_handler, SourceType, _options.LiteMode); _correctnessContext = _options.StrictMode ? new CorrectnessContext(this, true) : null; LazyPropertyNodes = RootNode.New(_handler, _options); }
public static Lazy <MemberHandler> Lazy(ObjectCallerBase handler, Type sourceType, bool liteMode) { return(liteMode ? default : new Lazy <MemberHandler>(() => new MemberHandler(handler, sourceType))); }
public MemberHandler(ObjectCallerBase handler, Type sourceType) { SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); _handler = handler ?? throw new ArgumentNullException(nameof(handler)); _memberNames = handler.GetMemberNames().ToList(); }
public static ObjectCallerBase <T> AndSetDynamicObject <T>(this ObjectCallerBase <T> handler, T instance) where T : DynamicObject, new() { handler.SetObjInstance(instance); return(handler); }
public static ObjectCallerBase AndSetDynamicObject(this ObjectCallerBase handler, DynamicObject instance) { handler.SetObjInstance(instance); return(handler); }