public static InstanceVisitor CreateForInstance(Type type, object instance, ObjectVisitorOptions options) { options ??= ObjectVisitorOptions.Default; var handler = SafeObjectHandleSwitcher.Switch(options.AlgorithmKind)(type).AndSetInstance(instance); return(new InstanceVisitor(handler, type, options)); }
public static StaticTypeObjectVisitor CreateForStaticType(Type type, ObjectVisitorOptions options) { options ??= ObjectVisitorOptions.Default; var handler = SafeObjectHandleSwitcher.Switch(options.AlgorithmKind)(type); return(new StaticTypeObjectVisitor(handler, type, options)); }
public static StaticTypeObjectVisitor <T> CreateForStaticType <T>(ObjectVisitorOptions options) { options ??= ObjectVisitorOptions.Default; var handler = UnsafeObjectHandleSwitcher.Switch <T>(options.AlgorithmKind)().With <T>(); return(new StaticTypeObjectVisitor <T>(handler, options)); }
public static FutureInstanceVisitor <T> CreateForFutureInstance <T>(ObjectVisitorOptions options, IDictionary <string, object> initialValues = null) { options ??= ObjectVisitorOptions.Default; var handler = UnsafeObjectHandleSwitcher.Switch <T>(options.AlgorithmKind)().With <T>(); return(new FutureInstanceVisitor <T>(handler, options, initialValues)); }
public static FutureInstanceVisitor CreateForFutureInstance(Type type, ObjectVisitorOptions options, IDictionary <string, object> initialValues = null) { options ??= ObjectVisitorOptions.Default; var handler = SafeObjectHandleSwitcher.Switch(options.AlgorithmKind)(type); return(new FutureInstanceVisitor(handler, type, options, initialValues)); }
public static InstanceVisitor <T> CreateForInstance <T>(T instance, ObjectVisitorOptions options) { options ??= ObjectVisitorOptions.Default; var handler = UnsafeObjectHandleSwitcher.Switch <T>(options.AlgorithmKind)().AndSetInstance(instance).With <T>(); return(new InstanceVisitor <T>(handler, options)); }
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 StaticTypeObjectVisitor <T> CreateForStaticType <T, TStrategy>(ObjectVisitorOptions options) where TStrategy : class, IValidationStrategy <T>, new() { options ??= ObjectVisitorOptions.Default; var handler = UnsafeObjectHandleSwitcher.Switch <T>(options.AlgorithmKind)().With <T>(); var visitor = new StaticTypeObjectVisitor <T>(handler, options); visitor.VerifiableEntry.SetStrategy <TStrategy>(); return(visitor); }
public static IPropertyNodeVisitor Create( ObjectMember member, ObjectCallerBase parentHandlerPtr, ObjectVisitorOptions options, PropertyNodeVisitor rootVisitor, PropertyNodeVisitor parentVisitor, List <int> rootSignatureCacheRef, List <int> parentSignatureCacheRef, int deep) { 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, rootVisitor, parentVisitor, visitor, options, MemberValueSyncHandler, rootSignatureCacheRef, parentSignatureCacheRef, deep + 1)); }
public static bool ReadOnly(ObjectOwn own, ObjectVisitorOptions options) { if (!own.IsReadOnly) { return(false); } if (options.SilenceIfNotWritable) { return(true); } throw new InvalidOperationException($"This type ({own.Type.GetFriendlyName()}) is read only."); }
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); }
//root public PropertyNodeVisitor( ObjectMember member, InstanceVisitor visitor, ObjectVisitorOptions options, Action <object> memberValueSyncHandler) { _options = options ?? throw new ArgumentNullException(nameof(options)); _member = member ?? throw new ArgumentNullException(nameof(member)); Deep = 0; Root = this; Parent = null; _visitor = visitor ?? throw new ArgumentNullException(nameof(visitor)); _signature = visitor.Signature; _rootSignatureCached = new() { _signature }; _parentSignatureCached = default; _signatureCached = new() { _signature }; _childrenNodes = new(); MemberValueSyncHandler = memberValueSyncHandler ?? throw new ArgumentNullException(nameof(memberValueSyncHandler)); }
//child public PropertyNodeVisitor( ObjectMember member, PropertyNodeVisitor rootVisitor, PropertyNodeVisitor parentVisitor, InstanceVisitor visitor, ObjectVisitorOptions options, Action <object> memberValueSyncHandler, List <int> rootSignatureCacheRef, List <int> parentSignatureCacheRef, int deep) { _member = member ?? throw new ArgumentNullException(nameof(member)); Deep = deep; Root = rootVisitor ?? throw new ArgumentNullException(nameof(rootVisitor)); Parent = parentVisitor ?? throw new ArgumentNullException(nameof(parentVisitor)); _visitor = visitor ?? throw new ArgumentNullException(nameof(visitor)); _signature = visitor.Signature; _rootSignatureCached = rootSignatureCacheRef; _parentSignatureCached = parentSignatureCacheRef; _signatureCached = new() { _signature }; _childrenNodes = new(); MemberValueSyncHandler = memberValueSyncHandler ?? throw new ArgumentNullException(nameof(memberValueSyncHandler)); _rootSignatureCached.Add(_signature); _parentSignatureCached.Add(_signature); }
public FluentGetterBuilder(Type type, ObjectVisitorOptions options) { _type = type; _options = options; }
public static FutureInstanceVisitor <T> CreateForFutureInstance <T, TStrategy>(ObjectVisitorOptions options, IDictionary <string, object> initialValues = null) where TStrategy : class, IValidationStrategy <T>, new() { options ??= ObjectVisitorOptions.Default; var handler = UnsafeObjectHandleSwitcher.Switch <T>(options.AlgorithmKind)().With <T>(); var visitor = new FutureInstanceVisitor <T>(handler, options, initialValues); visitor.VerifiableEntry.SetStrategy <TStrategy>(); return(visitor); }
public static StaticTypeObjectVisitor CreateForStaticType <TStrategy>(Type type, ObjectVisitorOptions options, TStrategy strategy) where TStrategy : class, IValidationStrategy, new() { options ??= ObjectVisitorOptions.Default; var handler = SafeObjectHandleSwitcher.Switch(options.AlgorithmKind)(type); var visitor = new StaticTypeObjectVisitor(handler, type, options); visitor.VerifiableEntry.SetStrategy(strategy); return(visitor); }
public static FutureInstanceVisitor CreateForFutureInstance <TStrategy>(Type type, ObjectVisitorOptions options, TStrategy strategy, IDictionary <string, object> initialValues = null) where TStrategy : class, IValidationStrategy, new() { options ??= ObjectVisitorOptions.Default; var handler = SafeObjectHandleSwitcher.Switch(options.AlgorithmKind)(type); var visitor = new FutureInstanceVisitor(handler, type, options, initialValues); visitor.VerifiableEntry.SetStrategy(strategy); return(visitor); }
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); }