Click here to Skip to main content
12,241,949 members (45,362 online)
Click here to Skip to main content

Tagged as

Stats

17.5K views
298 downloads
32 bookmarked
Posted

Building an MVP Framework for .NET. Part 4: Strongly Typed Associations

, 25 Apr 2008 Ms-PL
In this article we continue developing a Model-View-Presenter framework for .NET platform. The new features we are implementing here are strongly typed asscoiations between controllers, views and tasks for higher convenience and type safety.
MVCSharp
API Docs
CleanUpAll.proj
Examples
ASP.NET MVC Store
ApplicationLogic
Model
NorthwindDataSet.xsc
NorthwindDataSet.xss
Presentation
App_Data
Nwind.mdb
Global.asax
Properties
Tests
Properties
TestApplicationLogic
Tests.csproj.user
Basics
Basics (generics used)
ApplicationLogic
Model
Presentation
Web
Global.asax
Win
Properties
ApplicationLogic
Model
Presentation
Web
Global.asax
Win
Properties
SimpleFormsViewsManager
Properties
TestSimpleFormsViewsManager
ApplicationLogic
Presentation
Properties
TasksInteraction
ApplicationLogic
Model
Presentation
Web
Global.asax
Win
Properties
WindowsFormsExample
ApplicationLogic
Presentation
Properties
MVCSharp
MVCSharp.Tests
Core
Configuration
Tasks
Views
Tasks
MVCSharp.Tests.csproj.user
Properties
Webforms
Configuration
Winforms
Configuration
Core
Configuration
Tasks
Views
Tasks
Views
Properties
Webforms
Configuration
Winforms
Configuration
//===========================================
// MVC# Framework | www.MVCSharp.org        |
// ------------------------------------------
// Copyright (C) 2008 www.MVCSharp.org      |
// All rights reserved.                     |
//===========================================

using System;
using System.Text;

namespace MVCSharp.Core.Configuration.Tasks
{
    #region Documentation
    /// <summary>
    /// Attribute for describing interaction points within a task.
    /// </summary>
    /// <remarks>Should be used with <see cref="TaskInfoByAttributesProvider"/> or
    /// <see cref="DefaultTaskInfoProvider"/> task info providers. They
    /// convert this attribute occurrences into <see cref="TaskInfo"/>
    /// objects.</remarks>
    /// <example>
    /// Here is an example of how this attribute may be used:
    /// <code>
    /// class MyTask
    /// {
    ///     [InteractionPoint(typeof(MyController1))]
    ///     public const string iPoint1 = "View1";
    /// 
    ///     [IPoint(typeof(MyController2), true, iPoint1)]
    ///     public const string iPoint2 = "View2";
    /// 
    ///     [InteractionPoint(typeof(MyController1), iPoint1, iPoint2)]
    ///     public const string iPoint3 = "View3";
    /// 
    ///     [InteractionPoint(typeof(MyController1), true)]
    ///     [NavTarget("Next", iPoint3)]
    ///     [NavTarget("Previous", iPoint2)]
    ///     public const string iPoint4 = "View4";
    /// }
    /// </code>
    /// </example>
    #endregion
    [AttributeUsage(AttributeTargets.Field)]
    public class InteractionPointAttribute : Attribute
    {
        private bool isCommonTarget;
        private Type controllerType;
        private string[] navTargets;

        #region Documentation
        /// <summary>
        /// Constructor taking the controller type and an array of
        /// navigation targets for this interation point.
        /// </summary>
        #endregion
        public InteractionPointAttribute(Type controllerType,
                                         params string[] navTargets)
                : this (controllerType, false, navTargets){ }

        #region Documentation
        /// <summary>
        /// Constructor taking the controller type and a parameter specifying
        /// whether the interaction point is a common target for other points.
        /// </summary>
        #endregion
        public InteractionPointAttribute(Type controllerType,
                                         bool isCommonTarget)
                : this(controllerType, isCommonTarget, new string[0]) { }

        #region Documentation
        /// <summary>
        /// Constructor taking the controller type, a parameter specifying
        /// whether the interaction point is a common target for other points
        /// and an array of navigation targets for this interation point.
        /// </summary>
        #endregion
        public InteractionPointAttribute(Type controllerType, bool isCommonTarget,
                                                        params string[] navTargets)
        {
            this.controllerType = controllerType;
            this.isCommonTarget = isCommonTarget;
            this.navTargets = navTargets;
        }

        #region Documentation
        /// <summary>
        /// Specifies the type of the controller for the interaction point.
        /// </summary>
        #endregion
        public Type ControllerType
        {
            get { return controllerType; }
            set { controllerType = value; }
        }

        #region Documentation
        /// <summary>
        /// Specifies whether the interaction point should be a common target
        /// (i.e. a navigation can be done from any other interaction point to this one).
        /// </summary>
        #endregion
        public bool IsCommonTarget
        {
            get { return isCommonTarget; }
            set { isCommonTarget = value; }
        }

        #region Documentation
        /// <summary>
        /// Gets or sets an array of target navigation points represented by
        /// their view names. Any of these interaction points can be navigated
        /// to with the trigger name equal to the target view name.
        /// </summary>
        #endregion
        public string[] NavTargets
        {
            get { return navTargets; }
            set { navTargets = value; }
        }
    }

    #region Documentation
    /// <summary>
    /// Equivalent to the <see cref="InteractionPointAttribute"/> attribute.
    /// </summary>
    #endregion
    [AttributeUsage(AttributeTargets.Field)]
    public class IPointAttribute : InteractionPointAttribute
    {
        #region Documentation
        /// <summary>
        /// See <see cref="InteractionPointAttribute"/> equivalent constructor.
        /// </summary>
        #endregion
        public IPointAttribute(Type controllerType, params string[] navTargets)
            : base(controllerType, navTargets)
        { }

        #region Documentation
        /// <summary>
        /// See <see cref="InteractionPointAttribute"/> equivalent constructor.
        /// </summary>
        #endregion
        public IPointAttribute(Type controllerType,
                               bool isCommonTarget)
            : base(controllerType, isCommonTarget) { }

        #region Documentation
        /// <summary>
        /// See <see cref="InteractionPointAttribute"/> equivalent constructor.
        /// </summary>
        #endregion
        public IPointAttribute(Type controllerType, bool isCommonTarget,
            params string[] navTargets) : base(controllerType, isCommonTarget, navTargets)
        { }
    }
}

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, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Oleg Zhukov
Team Leader
Russian Federation Russian Federation
Oleg Zhukov, born and living in Russia is Lead Engineer and Project Manager in a company which provides business software solutions. He has graduated from Moscow Institute of Physics and Technology (MIPT) (department of system programming) and has got a M.S. degree in applied physics and mathematics. His research and development work concerns architectural patterns, domain-driven development and systems analysis. Being the adherent of agile methods he applies them extensively in the projects managed by him.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 25 Apr 2008
Article Copyright 2008 by Oleg Zhukov
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid