Salient Solutions

wrasslin ones and nones for fun and profit - Sky Sanders' Blog
posts - 96, comments - 70, trackbacks - 0

Release: DeadSimpleDTO 2.01

 

You can find the code @ DeadSimpleDTO.codeplex.com

New in 2.01

  • INotifyPropertyChanged option
  • One-to-many and many-to-one relationships optionally rendered

Examples:

 

Default options:  basic property bag dto

/*
	DeadSimpleDTO 
		default options
		
		basic property bag dto
		
*/

using System;
using Northwind;
namespace Northwind
{
    public partial class Orders
    {
        #region Properties
        private Int32 _orderID;
        public virtual Int32 OrderID
        {
            get { return _orderID; }
            set
            {
                if (value == _orderID)
                    return;
                _orderID = value;
            }
        }
        
  			// ... SNIPPED FOR BEVITY
  			
        private String _shipCountry;
        public virtual String ShipCountry
        {
            get { return _shipCountry; }
            set
            {
                if (value == _shipCountry)
                    return;
                _shipCountry = value;
            }
        }
        #endregion
    }

}

 

Basic property bag dto with many-to-one and  one-to-many relationships

/*
	DeadSimpleDTO - 
		@options_render_relationships = 1
		
		basic property bag dto with many-to-one and  one-to-many relationships 
*/

using System;
using Northwind;
namespace Northwind
{

    public partial class OrdersCollection : List<Orders> { }
    public partial class Orders
    {
        #region Properties
        private Int32 _orderID;
        public virtual Int32 OrderID
        {
            get { return _orderID; }
            set
            {
                if (value == _orderID)
                    return;
                _orderID = value;
            }
        }
        
				// ... SNIPPED FOR BEVITY
				
        private String _shipCountry;
        public virtual String ShipCountry
        {
            get { return _shipCountry; }
            set
            {
                if (value == _shipCountry)
                    return;
                _shipCountry = value;
            }
        }
        #endregion
        #region Relations
        // many to one
        // on dbo.FK_Orders_Customers
        private Customers _customers;
        public virtual Customers Customers
        {
            get { return _customers; }
            set
            {
                if (ReferenceEquals(value, _customers))
                    return;
                _customers = value;
            }
        }
        
				// ... SNIPPED FOR BEVITY
				
        // one to many
        // on dbo.FK_Order_Details_Orders
        private Order_DetailsCollection _order_Details;
        public virtual Order_DetailsCollection Order_Details
        {
            get { return _order_Details; }
            set
            {
                if (ReferenceEquals(value, _order_Details))
                    return;
                _order_Details = value;
            }
        }

        #endregion

    }
}
    

 

Basic property bag dto with collection classes and custom attributes to enable basic data loading by DeadSimpleLoader.cs

 

/*
	DeadSimpleDTO - 
		@options_render_collections = 1
		@options_render_loader_attributes = 1
				
		basic property bag dto with collection classes and custom attributes to enable basic data loading by DeadSimpleLoader.cs
		
*/


using System;
using System.Collections.Generic;
using DeadSimpleDTO;
using Northwind;
namespace Northwind
{
    public partial class OrdersCollection : List<Orders> { }
    [Table("dbo.Orders", KeyColumns = new[] { "OrderID" }, SelectStatement = "SELECT [OrderID], /*SNIPPED FOR BEVITY*/ [ShipCountry] FROM [dbo].[Orders]")]
    public partial class Orders
    {
        #region Properties
        private Int32 _orderID;
        [Column("OrderID", IsPK = true, DbType = "int", MaxLength = 4, IsNullable = false)]
        public virtual Int32 OrderID
        {
            get { return _orderID; }
            set
            {
                if (value == _orderID)
                    return;
                _orderID = value;
            }
        }

				// ... SNIPPED FOR BEVITY
				
        private String _shipCountry;
        [Column("ShipCountry", IsPK = false, DbType = "nvarchar(30)", MaxLength = 30, IsNullable = true)]
        public virtual String ShipCountry
        {
            get { return _shipCountry; }
            set
            {
                if (value == _shipCountry)
                    return;
                _shipCountry = value;
            }
        }
        #endregion
    }
}
        


 

Basic property bag dto with many-to-one and  one-to-many relationships  and a common base class.

/*
	DeadSimpleDTO - 
		@options_render_relationships = 1
		@options_render_common_base = 1
		
		basic property bag dto with many-to-one and  one-to-many relationships  and a common base class.
*/

using System;
using System.Collections.Generic;
using Northwind;
namespace Northwind
{
    public partial class OrdersCollection : List<Orders> { }
    public partial class Orders : DeadSimpleDTO
    {
        #region Properties
        private Int32 _orderID;
        public virtual Int32 OrderID
        {
            get { return _orderID; }
            set
            {
                if (value == _orderID)
                    return;
                _orderID = value;
            }
        }

				// ... SNIPPED FOR BEVITY
				    
        private String _shipCountry;
        public virtual String ShipCountry
        {
            get { return _shipCountry; }
            set
            {
                if (value == _shipCountry)
                    return;
                _shipCountry = value;
            }
        }
        #endregion
        #region Relations
        // many to one
        // on dbo.FK_Orders_Customers
        private Customers _customers;
        public virtual Customers Customers
        {
            get { return _customers; }
            set
            {
                if (ReferenceEquals(value, _customers))
                    return;
                _customers = value;
            }
        }

				// ... SNIPPED FOR BEVITY
				
        // one to many
        // on dbo.FK_Order_Details_Orders
        private Order_DetailsCollection _order_Details;
        public virtual Order_DetailsCollection Order_Details
        {
            get { return _order_Details; }
            set
            {
                if (ReferenceEquals(value, _order_Details))
                    return;
                _order_Details = value;
            }
        }

        #endregion

    }
    public abstract partial class DeadSimpleDTO
    {
        protected static bool ByteArrayCompare(byte[] a1, byte[] a2)
        {
            if (a1 == null || a2 == null || a1.Length != a2.Length)
                return false;
            for (int i = 0; i < a1.Length; i++)
                if (a1[i] != a2[i])
                    return false;
            return true;
        }
    }
}

 

Basic WCF serializable property bag dto with many-to-one and  one-to-many relationships

/*
	DeadSimpleDTO - 
		@options_render_relationships = 1
		@options_render_data_contract = 1 (@options_render_serializable for System.SerializableAttribute)
		
		basic WCF serializable property bag dto with many-to-one and  one-to-many relationships 
*/


using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Northwind;
namespace Northwind
{
    [CollectionDataContract]
    public partial class OrdersCollection : List<Orders> { }
    [DataContract]
    public partial class Orders
    {
        #region Properties
        private Int32 _orderID;
        [DataMember]
        public virtual Int32 OrderID
        {
            get { return _orderID; }
            set
            {
                if (value == _orderID)
                    return;
                _orderID = value;
            }
        }

				// ... SNIPPED FOR BEVITY
				
        private String _shipCountry;
        [DataMember]
        public virtual String ShipCountry
        {
            get { return _shipCountry; }
            set
            {
                if (value == _shipCountry)
                    return;
                _shipCountry = value;
            }
        }
        #endregion
        #region Relations
        // many to one
        // on dbo.FK_Orders_Customers
        private Customers _customers;
        [DataMember]
        public virtual Customers Customers
        {
            get { return _customers; }
            set
            {
                if (ReferenceEquals(value, _customers))
                    return;
                _customers = value;
            }
        }
       
       	// ... SNIPPED FOR BEVITY
       	
        // one to many
        // on dbo.FK_Order_Details_Orders
        private Order_DetailsCollection _order_Details;
        [DataMember]
        public virtual Order_DetailsCollection Order_Details
        {
            get { return _order_Details; }
            set
            {
                if (ReferenceEquals(value, _order_Details))
                    return;
                _order_Details = value;
            }
        }

        #endregion

    }
}    

 

Basic WCF serializable property bag dto with many-to-one and  one-to-many relationships and INotifyPropertyChanged implementation

/*
	DeadSimpleDTO - 
		@options_render_relationships = 1
		@options_render_data_contract = 1 (@options_render_serializable for System.SerializableAttribute)
		@options_render_inotify = 1
				
		basic WCF serializable property bag dto with many-to-one and  one-to-many relationships and INotifyPropertyChanged implementation
*/

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using Northwind;
namespace Northwind
{
    [CollectionDataContract]
    public partial class OrdersCollection : List<Orders> { }
    [DataContract]
    public partial class Orders : DeadSimpleDTO
    {
        #region Properties
        private Int32 _orderID;
        [DataMember]
        public virtual Int32 OrderID
        {
            get { return _orderID; }
            set
            {
                if (value == _orderID)
                    return;
                _orderID = value;
                RaisePropertyChanged("OrderID");
            }
        }

				// ... SNIPPED FOR BEVITY

        private String _shipCountry;
        [DataMember]
        public virtual String ShipCountry
        {
            get { return _shipCountry; }
            set
            {
                if (value == _shipCountry)
                    return;
                _shipCountry = value;
                RaisePropertyChanged("ShipCountry");
            }
        }
        #endregion
        #region Relations
        // many to one
        // on dbo.FK_Orders_Customers
        private Customers _customers;
        [DataMember]
        public virtual Customers Customers
        {
            get { return _customers; }
            set
            {
                if (ReferenceEquals(value, _customers))
                    return;
                _customers = value;
                RaisePropertyChanged("Customers");
            }
        }

				// ... SNIPPED FOR BEVITY

        // one to many
        // on dbo.FK_Order_Details_Orders
        private Order_DetailsCollection _order_Details;
        [DataMember]
        public virtual Order_DetailsCollection Order_Details
        {
            get { return _order_Details; }
            set
            {
                if (ReferenceEquals(value, _order_Details))
                    return;
                _order_Details = value;
                RaisePropertyChanged("Order_Details");
            }
        }

        #endregion

    }
    
    public abstract partial class DeadSimpleDTO : INotifyPropertyChanged
    {
        private const string ERROR_MSG = "{0} is not a public property of {1}";
        private static readonly Dictionary<string, PropertyChangedEventArgs> eventArgCache;
        static DeadSimpleDTO()
        {
            eventArgCache = new Dictionary<string, PropertyChangedEventArgs>();
        }

        protected DeadSimpleDTO() { }
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;
        public static PropertyChangedEventArgs GetPropertyChangedEventArgs(string propertyName)
        {
            if (String.IsNullOrEmpty(propertyName))
                throw new ArgumentException("propertyName cannot be null or empty.");
            PropertyChangedEventArgs args;
            lock (typeof(DeadSimpleDTO))
            {
                bool isCached = eventArgCache.ContainsKey(propertyName);
                if (!isCached)
                {
                    eventArgCache.Add(propertyName, new PropertyChangedEventArgs(propertyName));
                }
                args = eventArgCache[propertyName];
            }
            return args;
        }
        protected virtual void AfterPropertyChanged(string propertyName) { }
        protected void RaisePropertyChanged(string propertyName)
        {
            VerifyProperty(propertyName);
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                PropertyChangedEventArgs args = GetPropertyChangedEventArgs(propertyName);
                handler(this, args);
            }
            AfterPropertyChanged(propertyName);
        }
        [Conditional("DEBUG")]
        private void VerifyProperty(string propertyName)
        {
            Type type = GetType();
            PropertyInfo propInfo = type.GetProperty(propertyName);
            if (propInfo == null)
            {
                string msg = string.Format(ERROR_MSG, propertyName, type.FullName);
                Debug.Fail(msg);
            }
        }
        protected static bool ByteArrayCompare(byte[] a1, byte[] a2)
        {
            if (a1 == null || a2 == null || a1.Length != a2.Length)
                return false;
            for (int i = 0; i < a1.Length; i++)
                if (a1[i] != a2[i])
                    return false;
            return true;
        }
    }    
}    

Technorati tags: , , ,

Print | posted on Tuesday, January 26, 2010 11:56 AM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 1 and type the answer here:

Powered by: