/// <summary>
            /// Create for ExpandoObject <br />
            /// 为 ExpandoObject 创建对象访问器
            /// </summary>
            /// <param name="options"></param>
            /// <returns></returns>
            public static IObjectVisitor CreateForExpandoObject(ObjectVisitorOptions options)
            {
                var type    = typeof(ExpandoObject);
                var handler = (ExpandoObjectSlimObjectCaller)DynamicServiceTypeHelper.Create(type);

                return(new FutureInstanceVisitor(handler, type, options));
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Create an Object Visitor instance for the given type <br />
 /// 为给定的类型创建一个 Object Visitor 实例
 /// </summary>
 /// <param name="type"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IObjectVisitor Create(Type type, ObjectVisitorOptions options)
 {
     TypeAmGuard.RejectSimpleType(type);
     if (type.IsAbstract && type.IsSealed)
     {
         return(ObjectVisitorFactoryCore.CreateForStaticType(type, options));
     }
     return(ObjectVisitorFactoryCore.CreateForFutureInstance(type, options));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create an Object Visitor instance for the given type and use the specified verification strategy <br />
 /// 为给定的类型创建一个 Object Visitor 实例,并使用指定的验证策略
 /// </summary>
 /// <param name="options"></param>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TStrategy"></typeparam>
 /// <returns></returns>
 public static IObjectVisitor <T> Create <T, TStrategy>(ObjectVisitorOptions options)
     where TStrategy : class, IValidationStrategy <T>, new()
 {
     TypeAmGuard.RejectSimpleType <T>(out var type);
     if (type.IsAbstract && type.IsSealed)
     {
         return(ObjectVisitorFactoryCore.CreateForStaticType <T, TStrategy>(options));
     }
     return(ObjectVisitorFactoryCore.CreateForFutureInstance <T, TStrategy>(options));
 }
            /// <summary>
            /// Create for ExpandoObject <br />
            /// 为 DynamicObject 创建对象访问器
            /// </summary>
            /// <param name="type"></param>
            /// <param name="options"></param>
            /// <returns></returns>
            public static IObjectVisitor CreateForDynamicObject(Type type, ObjectVisitorOptions options)
            {
                var handler = DynamicServiceTypeHelper.Create(type);

                if (type.IsAbstract && type.IsSealed)
                {
                    return(new StaticTypeObjectVisitor(handler, type, options));
                }
                return(new FutureInstanceVisitor(handler, type, options));
            }
            /// <summary>
            /// Create for ExpandoObject <br />
            /// 为 DynamicObject 创建对象访问器
            /// </summary>
            /// <param name="options"></param>
            /// <typeparam name="T"></typeparam>
            /// <returns></returns>
            public static IObjectVisitor CreateForDynamicObject <T>(ObjectVisitorOptions options)
                where T : DynamicObject, new()
            {
                var handler = DynamicServiceTypeHelper.Create <T>();
                var type    = typeof(T);

                if (type.IsAbstract && type.IsSealed)
                {
                    return(new StaticTypeObjectVisitor <T>(handler, options));
                }
                return(new FutureInstanceVisitor <T>(handler, options));
            }
Ejemplo n.º 6
0
 /// <summary>
 /// Create an Object Visitor instance for the given object instance,
 /// use the specified verification strategy,
 /// and initialize it with the given dictionary <br />
 /// 为给定的对象实例创建一个 Object Visitor 实例,使用指定的验证策略,并通过给定的字典对其进行初始化
 /// </summary>
 /// <param name="type"></param>
 /// <param name="initialValues"></param>
 /// <param name="validationStrategy"></param>
 /// <param name="options"></param>
 /// <typeparam name="TStrategy"></typeparam>
 /// <returns></returns>
 public static IObjectVisitor Create <TStrategy>(Type type, IDictionary <string, object> initialValues, TStrategy validationStrategy, ObjectVisitorOptions options)
     where TStrategy : class, IValidationStrategy, new()
 {
     TypeAmGuard.RejectSimpleType(type);
     if (type.IsAbstract && type.IsSealed)
     {
         return(ObjectVisitorFactoryCore.CreateForStaticType(type, options, validationStrategy));
     }
     return(ObjectVisitorFactoryCore.CreateForFutureInstance(type, options, validationStrategy, initialValues));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Create an Object Visitor instance for a given object instance and use the specified verification strategy <br />
 /// 为给定的对象实例创建一个 Object Visitor 实例,并使用指定的验证策略
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="options"></param>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TStrategy"></typeparam>
 /// <returns></returns>
 public static IObjectVisitor <T> Create <T, TStrategy>(T instance, ObjectVisitorOptions options)
     where TStrategy : class, IValidationStrategy <T>, new()
 {
     TypeAmGuard.RejectSimpleType <T>();
     return(ObjectVisitorFactoryCore.CreateForInstance <T, TStrategy>(instance, options));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Create an Object Visitor instance for a given object instance and use the specified verification strategy <br />
 /// 为给定的对象实例创建一个 Object Visitor 实例,并使用指定的验证策略
 /// </summary>
 /// <param name="type"></param>
 /// <param name="instance"></param>
 /// <param name="validationStrategy"></param>
 /// <param name="options"></param>
 /// <typeparam name="TStrategy"></typeparam>
 /// <returns></returns>
 public static IObjectVisitor Create <TStrategy>(Type type, object instance, TStrategy validationStrategy, ObjectVisitorOptions options)
     where TStrategy : class, IValidationStrategy, new()
 {
     TypeAmGuard.RejectSimpleType(type);
     return(ObjectVisitorFactoryCore.CreateForInstance(type, instance, options, validationStrategy));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Create an Object Visitor instance for the given object instance and initialize it with the given dictionary <br />
 /// 为给定的对象实例创建一个 Object Visitor 实例,并通过给定的字典对其进行初始化
 /// </summary>
 /// <param name="initialValues"></param>
 /// <param name="options"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static IObjectVisitor <T> Create <T>(IDictionary <string, object> initialValues, ObjectVisitorOptions options)
 {
     TypeAmGuard.RejectSimpleType <T>(out var type);
     if (type.IsAbstract && type.IsSealed)
     {
         return(ObjectVisitorFactoryCore.CreateForStaticType <T>(options));
     }
     return(ObjectVisitorFactoryCore.CreateForFutureInstance <T>(options, initialValues));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Create an Object Visitor instance for the given object instance <br />
 /// 为给定的对象实例创建一个 Object Visitor 实例
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="options"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static IObjectVisitor <T> Create <T>(T instance, ObjectVisitorOptions options)
 {
     TypeAmGuard.RejectSimpleType <T>();
     return(ObjectVisitorFactoryCore.CreateForInstance(instance, options));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Create an Object Visitor instance for the given object instance <br />
 /// 为给定的对象实例创建一个 Object Visitor 实例
 /// </summary>
 /// <param name="type"></param>
 /// <param name="instance"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IObjectVisitor Create(Type type, object instance, ObjectVisitorOptions options)
 {
     TypeAmGuard.RejectSimpleType(type);
     return(ObjectVisitorFactoryCore.CreateForInstance(type, instance, options));
 }
            /// <summary>
            /// Create for ExpandoObject <br />
            /// 为 ExpandoObject 创建对象访问器
            /// </summary>
            /// <param name="initialValues"></param>
            /// <param name="options"></param>
            /// <returns></returns>
            public static IObjectVisitor CreateForExpandoObject(IDictionary <string, object> initialValues, ObjectVisitorOptions options)
            {
                var type    = typeof(ExpandoObject);
                var handler = (ExpandoObjectSlimObjectCaller)DynamicServiceTypeHelper.Create(type);

                return(new FutureInstanceVisitor(handler, type, options, initialValues));
            }
 /// <summary>
 /// Set type <br />
 /// 设置类型
 /// </summary>
 /// <param name="options"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static IFluentGetter <T> Type <T>(ObjectVisitorOptions options)
 => new FluentGetterBuilder <T>(options ?? ObjectVisitorOptions.Default);
 /// <summary>
 /// Set type <br />
 /// 设置类型
 /// </summary>
 /// <param name="declaringType"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IFluentGetter Type(Type declaringType, ObjectVisitorOptions options)
 => new FluentGetterBuilder(declaringType, options ?? ObjectVisitorOptions.Default);
Ejemplo n.º 15
0
 /// <summary>
 /// Set type <br />
 /// 设置类型
 /// </summary>
 /// <param name="type"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IFluentSetter Type(Type type, ObjectVisitorOptions options)
 => new FluentSetterBuilder(type, options ?? ObjectVisitorOptions.Default);