/// <summary> /// Convert a type into an Object Visitor <br /> /// 将一个类型转换为对象访问器 /// </summary> /// <param name="type"></param> /// <param name="kind"></param> /// <param name="repeatable"></param> /// <param name="strictMode"></param> /// <returns></returns> public static IObjectVisitor ToVisitor(this Type type, AlgorithmKind kind = AlgorithmKind.Precision, bool repeatable = RpMode.REPEATABLE, bool strictMode = StMode.NORMALE) { return(ObjectVisitor.Create(type, kind, repeatable, strictMode)); }
/// <summary> /// Convert a dictionary into an Object Visitor according to the given type <br /> /// 将一个字典根据给定的类型转换为一个对象访问器 /// </summary> /// <param name="type"></param> /// <param name="initialValues"></param> /// <param name="kind"></param> /// <param name="repeatable"></param> /// <param name="strictMode"></param> /// <returns></returns> public static IObjectVisitor ToVisitor(this Type type, IDictionary <string, object> initialValues, AlgorithmKind kind = AlgorithmKind.Precision, bool repeatable = RpMode.REPEATABLE, bool strictMode = StMode.NORMALE) { return(ObjectVisitor.Create(type, initialValues, kind, repeatable, strictMode)); }
/// <summary> /// Convert an object into an Object Visitor <br /> /// 将一个对象实例转换为对象访问器 /// </summary> /// <param name="instanceObj"></param> /// <param name="kind"></param> /// <param name="repeatable"></param> /// <param name="strictMode"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IObjectVisitor <T> ToVisitor <T>(this T instanceObj, AlgorithmKind kind = AlgorithmKind.Precision, bool repeatable = RpMode.REPEATABLE, bool strictMode = StMode.NORMALE) where T : class { return(ObjectVisitor.Create(instanceObj, kind, repeatable, strictMode)); }
/// <summary> /// Create for ExpandoObject <br /> /// 为 ExpandoObject 创建对象访问器 /// </summary> /// <param name="initialValues"></param> /// <param name="repeatable"></param> /// <param name="strictMode"></param> /// <returns></returns> public static IObjectVisitor CreateForExpandoObject(IDictionary <string, object> initialValues, bool repeatable = RpMode.REPEATABLE, bool strictMode = StMode.NORMALE) { var type = typeof(ExpandoObject); var options = ObjectVisitor.FillWith(AlgorithmKind.Precision, repeatable, strictMode); var handler = (ExpandoObjectSlimObjectCaller)DynamicServiceTypeHelper.Create(type); return(new FutureInstanceVisitor(handler, type, options, initialValues)); }
/// <summary> /// Create for ExpandoObject <br /> /// 为 ExpandoObject 创建对象访问器 /// </summary> /// <param name="instance"></param> /// <param name="repeatable"></param> /// <param name="strictMode"></param> /// <returns></returns> public static IObjectVisitor CreateForExpandoObject(ExpandoObject instance, bool repeatable = RpMode.REPEATABLE, bool strictMode = StMode.NORMALE) { var type = typeof(ExpandoObject); var options = ObjectVisitor.FillWith(AlgorithmKind.Precision, repeatable, strictMode); var handler = ((ExpandoObjectSlimObjectCaller)DynamicServiceTypeHelper.Create(type)).AndSetExpandoObject(instance); return(new InstanceVisitor(handler, type, options)); }
/// <summary> /// Create for ExpandoObject <br /> /// 为 DynamicObject 创建对象访问器 /// </summary> /// <param name="type"></param> /// <param name="initialValues"></param> /// <param name="repeatable"></param> /// <param name="strictMode"></param> /// <returns></returns> public static IObjectVisitor CreateForDynamicObject(Type type, IDictionary <string, object> initialValues, bool repeatable = RpMode.REPEATABLE, bool strictMode = StMode.NORMALE) { var options = ObjectVisitor.FillWith(AlgorithmKind.Precision, repeatable, strictMode); var handler = DynamicServiceTypeHelper.Create(type); if (type.IsAbstract && type.IsSealed) { return(new StaticTypeObjectVisitor(handler, type, options)); } return(new FutureInstanceVisitor(handler, type, options, initialValues)); }
/// <summary> /// Create for ExpandoObject <br /> /// 为 DynamicObject 创建对象访问器 /// </summary> /// <param name="repeatable"></param> /// <param name="strictMode"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IObjectVisitor CreateForDynamicObject <T>(bool repeatable = RpMode.REPEATABLE, bool strictMode = StMode.NORMALE) where T : DynamicObject, new() { var options = ObjectVisitor.FillWith(AlgorithmKind.Precision, repeatable, strictMode); 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)); }
/// <summary> /// According to the given type, create an object of the corresponding type, /// and fill the object with the data provided in the dictionary <br /> /// 根据给定的类型,创建对应类型的对象,并使用字典中提供的数据填充该对象 /// </summary> /// <param name="keyValueCollections"></param> /// <param name="visitor"></param> /// <param name="kind"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T Create <T>(IDictionary <string, object> keyValueCollections, out IObjectVisitor <T> visitor, AlgorithmKind kind = AlgorithmKind.Precision) { visitor = ObjectVisitor.Create <T>(keyValueCollections, kind); return(visitor.Instance); }
/// <summary> /// According to the given type, create an object of the corresponding type, /// and fill the object with the data provided in the dictionary <br /> /// 根据给定的类型,创建对应类型的对象,并使用字典中提供的数据填充该对象 /// </summary> /// <param name="type"></param> /// <param name="keyValueCollections"></param> /// <param name="visitor"></param> /// <param name="kind"></param> /// <returns></returns> public static object Create(Type type, IDictionary <string, object> keyValueCollections, out IObjectVisitor visitor, AlgorithmKind kind = AlgorithmKind.Precision) { visitor = ObjectVisitor.Create(type, keyValueCollections, kind); return(visitor.Instance); }