예제 #1
0
        public bool SetField <T>(string myPropertyName, T myNewValue)
        {
            ItemColumn col = this.Table.Columns.FirstOrDefault <ItemColumn>((column) => column.ColumnName == myPropertyName);

            if (null != col)
            {
                int    index     = this.Table.Columns.IndexOf(col);
                object currValue = this.PropertyBlob[index];

                if ((null != myNewValue) &&
                    (null != currValue) &&
                    (currValue.Equals(myNewValue)))
                {
                    return(false);
                }
                else
                {
                    this.PropertyBlob[index] = myNewValue;
                    if (this.RowState == ItemRowState.Unchanged)
                    {
                        this.RowState = ItemRowState.Modified;
                    }

                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        public T Field <T>(string myPropertyName)
        {
            T value = default(T);

            ItemColumn col = this.Table.Columns.FirstOrDefault <ItemColumn>((column) => column.ColumnName == myPropertyName);

            if (null != col)
            {
                int index = this.Table.Columns.IndexOf(col);
                if (index < this.PropertyBlob.Count)
                {
                    // We may have arrived here as a result of serialization/deserialization.
                    // Coerce some types back into their correct type and assignment them
                    // back to the blob so they have the right type on output.
                    if ((typeof(T) != typeof(Int64)) && (PropertyBlob[index] is Int64))
                    {
                        Int32 result = Convert.ToInt32(PropertyBlob[index]);
                        PropertyBlob[index] = result;
                    }
                    else if ((typeof(T) == typeof(Int64)) && (PropertyBlob[index] is Int32))
                    {
                        Int64 result = Convert.ToInt64(PropertyBlob[index]);
                        PropertyBlob[index] = result;
                    }
                    else if ((typeof(T) == typeof(double)) && (PropertyBlob[index] is float))
                    {
                        double result = Convert.ToDouble(PropertyBlob[index]);
                        PropertyBlob[index] = result;
                    }
                    else if ((typeof(T) == typeof(float)) && (PropertyBlob[index] is double))
                    {
                        float result = Convert.ToSingle(PropertyBlob[index]);
                        PropertyBlob[index] = result;
                    }
                    else if ((typeof(T) == typeof(Guid)) && (PropertyBlob[index] is string))
                    {
                        Guid result = Guid.Parse((string)PropertyBlob[index]);
                        PropertyBlob[index] = result;
                    }
                    else if ((typeof(T) == typeof(uint)) && (PropertyBlob[index] is Int32))
                    {
                        uint result = Convert.ToUInt32(PropertyBlob[index]);
                        PropertyBlob[index] = result;
                    }

                    value = (T)this.PropertyBlob[index];
                }
            }

            return((T)value);
        }
예제 #3
0
        /// <summary>
        /// Stores the new value for the names property. If the property does not exist in the blob
        /// a new column will be created. Property names are case insensitive.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propName"></param>
        /// <param name="value"></param>
        public void Set <T>(string propertyName, T value)
        {
            lock (_lock)
            {
                if (!PropertyNameList.Contains(propertyName))
                {
                    PropertyNameList.Add(propertyName, typeof(T));
                }

                ItemColumn column = PropertyNameList[propertyName];
                PropertyValueList.Insert(PropertyNameList.IndexOf(column), value);

                IsDirty = true;

                RaisePropertyChanged(propertyName);
            }
        }
예제 #4
0
        /// <summary>
        /// Get the current value of a property. If the property does not exist, the default value
        /// for the type will be returned and the function returns FALSE. Property names are
        /// case insensitive.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Get <T>(string propertyName, out T value)
        {
            lock (_lock)
            {
                value = default(T);

                if (PropertyNameList.Contains(propertyName) &&
                    PropertyNameList[propertyName].DataType == typeof(T))
                {
                    ItemColumn column = PropertyNameList[propertyName];
                    int        index  = PropertyNameList.IndexOf(column);

                    value = (T)PropertyValueList[index];

                    return(true);
                }
            }

            return(false);
        }