Click here to Skip to main content
15,896,557 members
Articles / Web Development / ASP.NET

Template-Based Code Generation with SmartCode

Rate me:
Please Sign up or sign in to vote.
4.82/5 (35 votes)
25 Dec 20067 min read 101.1K   3.5K   121  
SmartCode is a template based code generator.This tutorial describes the process of building a templates to SmartCode
/*
 * Copyright � 2005-2006 Danilo Mendez <danilo.mendez@kontac.net>
 * Adolfo Socorro <ajs@esolutionspr.com>
 * www.kontac.net 
 * All rights reserved.
 * Released under both BSD license and Lesser GPL library license.
 * Whenever there is any discrepancy between the two licenses,
 * the BSD license will take precedence.
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using SmartCode.Model.Utils;
using System.ComponentModel;

namespace SmartCode.Model
{
    public delegate void OnAddObjectDelegate(NamedObject container, NamedObject arg);
    public delegate void OnRemoveObjectDelegate(NamedObject container, NamedObject arg);

    [Serializable]
    public class NamedObject : IdentifiedObject, ISerializable
    {
        public OnAddObjectDelegate OnAddObject;
        public OnRemoveObjectDelegate OnRemoveObject;

        #region Fields
        protected RestrictedLengthString name;
        protected string caption;
        protected string code;
        protected string description;
        protected string comment;
        #endregion

        #region Constructors
        private NamedObject()
            : base()
        {

        }
        public NamedObject(string name)
            : base()
        {
            this.name = new RestrictedLengthString(name);
            this.code = this.name.Value.Replace("-","").Replace("_","").Trim();
            this.caption = this.name.Value;
        }

        public NamedObject(SerializationInfo Info, StreamingContext ctxt)
            : base(Info, ctxt)
        {
            this.name = (RestrictedLengthString)Info.GetValue("name", typeof(RestrictedLengthString));
            this.caption = (string)Info.GetValue("caption", typeof(string));
            this.code = (string)Info.GetValue("code", typeof(string));
            this.description = (string)Info.GetValue("description", typeof(string));
            this.comment = (string)Info.GetValue("comment", typeof(string));
        }

        #endregion

        #region Properties
        public string Name
        {
            get
            {
                return name.Value;
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                {
                    throw new ArgumentNullException(String.Format(SmartCode.Model.Properties.Resources.NullArgument, "Name"));
                }
                if (value != this.name.Value)
                {
                    name = new RestrictedLengthString(value);
                    NotifyPropertyChanged("Name");
                }
            }
        }

      
        /// <summary>
        /// Indicates the default user-interface caption for this column.
        /// </summary>
        public string Caption
        {
            get { return caption; }
            set
            {
                if (String.IsNullOrEmpty(value))
                {
                    throw new ArgumentNullException(String.Format(SmartCode.Model.Properties.Resources.NullArgument, "Caption"));
                }
                if (value != this.caption)
                {
                    caption = value;
                    NotifyPropertyChanged("Caption");
                }
            }
        }

        public string Code
        {
            get { return code; }
            set
            {
                if (String.IsNullOrEmpty(value))
                {
                    throw new ArgumentNullException(String.Format(SmartCode.Model.Properties.Resources.NullArgument, "Code"));
                }
                if (value != this.code)
                {
                    code = value;
                    NotifyPropertyChanged("Code");
                }
            }
        }

        public string Comment
        {
            get { return comment; }
            set
            {
                if (String.IsNullOrEmpty(value))
                {
                    throw new ArgumentNullException(String.Format(SmartCode.Model.Properties.Resources.NullArgument, "Comment"));
                }
                if (value != this.comment)
                {
                    this.comment = value;
                    NotifyPropertyChanged("Comment");
                }
            }
        }

        public string Description
        {
            get { return description; }
            set
            {
                if (String.IsNullOrEmpty(value))
                {
                    throw new ArgumentNullException(String.Format(SmartCode.Model.Properties.Resources.NullArgument, "Description"));
                }
                if (value != this.description)
                {
                    this.description = value;
                    NotifyPropertyChanged("Description");
                }
            }
        }

        #endregion

        #region Override Methods

        public override string ToString()
        {
            return this.name;
        }

        #endregion

        #region Serializable Members


        void  ISerializable.GetObjectData(SerializationInfo Info, StreamingContext ctxt)
        {
            base.GetObjectData(Info, ctxt);

        }
        #endregion


     
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Danilo is the creator of SmartRules, a Business Rules Engine. He is an industry consultant working primarily with companies interested in implementing dynamic rules programming concepts to add flexibility to their architectures on web, CE, and desktop platforms. He operates his own website, Kontac, where you will find more information.

To contact Danilo, email him at danilo.mendez@gmail.com.

Comments and Discussions