示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataExchangeFactory"/> class.
        /// </summary>
        /// <param name="typeHandlerFactory">The type handler factory.</param>
        /// <param name="objectFactory">The object factory.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
		public DataExchangeFactory(TypeHandlerFactory typeHandlerFactory,
			IObjectFactory objectFactory,
            AccessorFactory accessorFactory)
		{
			_objectFactory = objectFactory;
			_typeHandlerFactory = typeHandlerFactory;
            _accessorFactory = accessorFactory;

			_primitiveDataExchange = new PrimitiveDataExchange(this);
			_complexDataExchange = new ComplexDataExchange(this);
			_listDataExchange = new ListDataExchange(this);
			_dictionaryDataExchange = new DictionaryDataExchange(this);
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="ConditionalTagHandler"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 protected ConditionalTagHandler(AccessorFactory accessorFactory)
     : base(accessorFactory)
 {
     _tagPropertyProbe = new TagPropertyProbe(AccessorFactory);
 }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsNotNull"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsNotNull(AccessorFactory accessorFactory)
		{
            this.Handler = new IsNotNullTagHandler(accessorFactory);
		}
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsEmptyDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsEmptyDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 { }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public BindDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 { }
        /// <summary>
        /// Initializes a new instance of the <see cref="IsPropertyAvailable"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsPropertyAvailable(AccessorFactory accessorFactory)
		{
            this.Handler = new IsPropertyAvailableTagHandler(accessorFactory);
		}
示例#7
0
        /// <summary>
        /// Sets the member.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="memberValue">The member value.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
		public static void SetMember(object obj, string memberName, object memberValue,
            AccessorFactory accessorFactory)
		{
			try 
			{
				if (memberName.IndexOf("[") > -1) 
				{
                    SetArrayMember(obj, memberName, memberValue, accessorFactory);
				} 
				else 
				{
					if (obj is IDictionary) 
					{
						((IDictionary) obj)[memberName] = memberValue;
					} 
					else 
					{
						Type targetType = obj.GetType();
                        ISetAccessorFactory setAccessorFactory = accessorFactory.SetAccessorFactory;
                        ISetAccessor setAccessor = setAccessorFactory.CreateSetAccessor(targetType, memberName);

                        if (setAccessor == null) 
						{
							throw new ProbeException("No Set method for member " + memberName + " on instance of " + obj.GetType().Name);
						}
						try 
						{
                            setAccessor.Set(obj, memberValue);
						}
						catch (Exception ex) 
						{
							throw new ProbeException(ex);
						}					
					}
				}
			}
			catch (ProbeException pe) 
			{
				throw;
			} 
			catch (Exception e) 
			{
				throw new ProbeException("Could not Get property '" + memberName + "' for " + obj.GetType().Name + ".  Cause: " + e.Message, e);
			}
		}
示例#8
0
	    /// <summary>
        /// Gets the member's value on the specified object.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
        /// <returns>The member's value</returns>
		public static object GetMember(object obj, string memberName,
            AccessorFactory accessorFactory)
		{
			try 
			{
				object value = null;

				if (memberName.IndexOf("[") > -1) 
				{
                    value = GetArrayMember(obj, memberName, accessorFactory);
				} 
				else 
				{
					if (obj is IDictionary) 
					{
						value = ((IDictionary) obj)[memberName];
					} 
					else 
					{
						Type targetType = obj.GetType();
                        IGetAccessorFactory getAccessorFactory = accessorFactory.GetAccessorFactory;
                        IGetAccessor getAccessor = getAccessorFactory.CreateGetAccessor(targetType, memberName);

                        if (getAccessor == null) 
						{
							throw new ProbeException("No Get method for member " + memberName + " on instance of " + obj.GetType().Name);
						}
						try 
						{
                            value = getAccessor.Get(obj);
						} 
						catch (Exception ae) 
						{
							throw new ProbeException(ae);
						}					
					}
				}
				return value;
			} 
			catch (ProbeException pe) 
			{
				throw;
			} 
			catch(Exception e)
			{
				throw new ProbeException("Could not Set property '" + memberName + "' for " + obj.GetType().Name + ".  Cause: " + e.Message, e);
			}
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="IsNotNullDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsNotNullDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="IsLessThanTagHandler"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsLessThanTagHandler(AccessorFactory accessorFactory)
            : base(accessorFactory)
		{
		}
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsLessEqualDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsLessEqualDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 { }
 /// <summary>
 /// Initializes a new instance of the <see cref="IsParameterPresentDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsParameterPresentDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 { }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsEqual"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public Bind(AccessorFactory accessorFactory)
 {
     this.Handler = new BindTagHandler(accessorFactory);
 }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicTagHandler"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public DynamicTagHandler(AccessorFactory accessorFactory)
            : base(accessorFactory)
		{
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="IsNotParameterPresentTagHandler"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsNotParameterPresentTagHandler(AccessorFactory accessorFactory)
            : base(accessorFactory)
		{
		}
示例#16
0
        /// <summary>
        /// Sets the array member.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="indexedName">Name of the indexed.</param>
        /// <param name="value">The value.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
		private static void SetArrayMember(object obj, string indexedName, object value,
            AccessorFactory accessorFactory)
        {
			try 
			{
				int startIndex  = indexedName.IndexOf("[");
				int length = indexedName.IndexOf("]");
				string name = indexedName.Substring(0, startIndex);
				string index = indexedName.Substring( startIndex+1, length-(startIndex+1));
				int i = Convert.ToInt32(index);
				
				object list = null;
				if (name.Length > 0)
				{
                    list = GetMember(obj, name, accessorFactory);
				}
				else
				{
					list = obj;
				}

				if (list is IList) 
				{
					((IList) list)[i] = value;
				} 
				else 
				{
					throw new ProbeException("The '" + name + "' member of the " + obj.GetType().Name + " class is not a List or Array.");
				}
			} 
			catch (ProbeException pe) 
			{
				throw pe;
			} 
			catch (Exception e) 
			{
				throw new ProbeException("Error getting ordinal value from .net object. Cause" + e.Message, e);
			}
		}
示例#17
0
        /// <summary>
        /// Return the specified member on an object. 
        /// </summary>
        /// <param name="obj">The Object on which to invoke the specified property.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
        /// <returns>An Object representing the return value of the invoked property.</returns>
		public static object GetMemberValue(object obj, string memberName,
            AccessorFactory accessorFactory)
        {
            if (memberName.IndexOf('.') > -1) 
			{
				StringTokenizer parser = new StringTokenizer(memberName, ".");
				IEnumerator enumerator = parser.GetEnumerator();
				object value = obj;

			    while (enumerator.MoveNext()) 
				{
					string token = (string)enumerator.Current;
                    value = GetMember(value, token, accessorFactory);

					if (value == null) 
					{
						break;
					}
				}
				return value;
			}
            return GetMember(obj, memberName, accessorFactory);
        }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public DynamicDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 { }
示例#19
0
        /// <summary>
        /// Sets the member value.
        /// </summary>
        /// <param name="obj">he Object on which to invoke the specified mmber.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="memberValue">The member value.</param>
        /// <param name="objectFactory">The object factory.</param>
        /// <param name="accessorFactory">The accessor factory.</param>
        public static void SetMemberValue(object obj, string memberName, object memberValue,
			IObjectFactory objectFactory,
            AccessorFactory accessorFactory)
		{
			if (memberName.IndexOf('.') > -1) 
			{
				StringTokenizer parser = new StringTokenizer(memberName, ".");
				IEnumerator enumerator = parser.GetEnumerator();
				enumerator.MoveNext();

				string currentPropertyName = (string)enumerator.Current;
				object child = obj;
      
				while (enumerator.MoveNext()) 
				{
					Type type = GetMemberTypeForSetter(child, currentPropertyName);
					object parent = child;
                    child = GetMember(parent, currentPropertyName, accessorFactory);
					if (child == null) 
					{
						try 
						{
							IFactory factory = objectFactory.CreateFactory(type, Type.EmptyTypes);
							child = factory.CreateInstance(Type.EmptyTypes);

                            SetMemberValue(parent, currentPropertyName, child, objectFactory, accessorFactory);
						} 
						catch (Exception e) 
						{
							throw new ProbeException("Cannot set value of property '" + memberName + "' because '" + currentPropertyName + "' is null and cannot be instantiated on instance of " + type.Name + ". Cause:" + e.Message, e);
						}
					}
					currentPropertyName = (string)enumerator.Current;
				}
                SetMember(child, currentPropertyName, memberValue, accessorFactory);
			} 
			else 
			{
                SetMember(obj, memberName, memberValue, accessorFactory);
			}
		}
示例#20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsNullTagHandler"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsNullTagHandler(AccessorFactory accessorFactory)
            : base(accessorFactory)
		{
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="IsGreaterEqualTagHandler"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsGreaterEqualTagHandler(AccessorFactory accessorFactory)
            : base(accessorFactory)
		{
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="IsPropertyAvailableTagHandler"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsPropertyAvailableTagHandler(AccessorFactory accessorFactory)
     : base(accessorFactory)
 {
 }
示例#23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsParameterPresent"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsParameterPresent(AccessorFactory accessorFactory)
		{
            this.Handler = new IsParameterPresentTagHandler(accessorFactory);
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="IsLessEqualTagHandler"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsLessEqualTagHandler(AccessorFactory accessorFactory)
            : base(accessorFactory)
		{
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="IsGreaterEqualDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsGreaterEqualDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 { }
示例#26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsEmptyTagHandler"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsEmptyTagHandler(AccessorFactory accessorFactory)
     : base(accessorFactory)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="IsPropertyAvailableDeSerializer"/> class.
 /// </summary>
 /// <param name="accessorFactory">The accessor factory.</param>
 public IsPropertyAvailableDeSerializer(AccessorFactory accessorFactory)
     : base(accessorFactory)
 { }
示例#28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsLessThan"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsLessThan(AccessorFactory accessorFactory)
		{
            this.Handler = new IsLessThanTagHandler(accessorFactory);
		}
示例#29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseTagHandler"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        protected BaseTagHandler(AccessorFactory accessorFactory)
		{
            _accessorFactory = accessorFactory;
		}
示例#30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsGreaterEqual"/> class.
        /// </summary>
        /// <param name="accessorFactory">The accessor factory.</param>
        public IsGreaterEqual(AccessorFactory accessorFactory)
		{
            this.Handler = new IsGreaterEqualTagHandler(accessorFactory);
		}