Click here to Skip to main content
15,886,362 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to change Input values Pin
waghniteen13-Apr-17 5:10
professionalwaghniteen13-Apr-17 5:10 
GeneralRe: How to change Input values Pin
OriginalGriff13-Apr-17 5:17
mveOriginalGriff13-Apr-17 5:17 
AnswerRe: How to change Input values Pin
jsc4225-Apr-17 0:43
professionaljsc4225-Apr-17 0:43 
QuestionEmail Attachment Downloader Pin
RonB8612-Apr-17 12:02
RonB8612-Apr-17 12:02 
AnswerRe: Email Attachment Downloader Pin
OriginalGriff12-Apr-17 21:35
mveOriginalGriff12-Apr-17 21:35 
GeneralRe: Email Attachment Downloader Pin
RonB8613-Apr-17 3:59
RonB8613-Apr-17 3:59 
GeneralRe: Email Attachment Downloader Pin
OriginalGriff13-Apr-17 4:26
mveOriginalGriff13-Apr-17 4:26 
QuestionGeneric usage is not clear in one program Pin
Tridip Bhattacharjee12-Apr-17 4:40
professionalTridip Bhattacharjee12-Apr-17 4:40 
see this class code
C#
public class ShipperFactory
    {
        private static TShip Create<TShip>()
            where TShip : IShip, // interface contract constraint
            new() // public parameter-less constructor constraint
        {
            return new TShip();
        }

        public static readonly IDictionary<Shipper, Func<IShip>> Creators =
            new Dictionary<Shipper, Func<IShip>>()
        {
            { Shipper.UPS, () => Create<ShipperUPS>() },
            { Shipper.FedEx, () => Create<ShipperFedEx>() },
            { Shipper.Purolator, () => Create<ShipperPurolator>() }
        };

        public static IShip CreateInstance(Shipper enumModuleName)
        {
            return Creators[enumModuleName]();
        }
    }


specially the below code is not clear where
C#
public static readonly IDictionary<Shipper, Func<IShip>> Creators =
            new Dictionary<Shipper, Func<IShip>>()
        {
            { Shipper.UPS, () => Create<ShipperUPS>() },
            { Shipper.FedEx, () => Create<ShipperFedEx>() },
            { Shipper.Purolator, () => Create<ShipperPurolator>() }
        };


1) see this line whose meaning is not clea. what is the meaning of Func<iship> ?

new Dictionary<shipper, func<iship="">>()

Dictionary usage is not clear. help me to understand the code of Dictionary and as well as ShipperFactory class.

it is required to use both interface and abstract class ? is it not redundant here ?

here giving the full code which show how i am using ShipperFactory class

calling like this way
--------------------------
C#
private void btnUPS_Click(object sender, EventArgs e)
        {
            ShipperFactory.CreateInstance(Shipper.UPS).Ship();
        }

        private void btnFedEx_Click(object sender, EventArgs e)
        {
            ShipperFactory.CreateInstance(Shipper.FedEx).Ship();
        }

        private void btnPurolator_Click(object sender, EventArgs e)
        {
            ShipperFactory.CreateInstance(Shipper.Purolator).Ship();
        }

    public enum Shipper
    {
        UPS,
        FedEx,
        Purolator
    }

    public interface IShip
    {
        void Ship();
    }

    public abstract class ShipperBase : IShip
    {
        //Etc
        public abstract void Ship();

    }

    public class ShipperUPS : ShipperBase
    {
        public override void Ship()
        {
            //-- code logic to implement shipping method for Purolator
            MessageBox.Show("UPS ship start");
        }
    }

    public class ShipperFedEx : ShipperBase
    {
        public override void Ship()
        {
            //-- code logic to implement shipping method for Purolator
            MessageBox.Show("FedEX ship start");
        }
    }

    public class ShipperPurolator : ShipperBase
    {
        public override void Ship()
        {
            //-- code logic to implement shipping method for Purolator
            MessageBox.Show("Purolator ship start");
        }
    }

    public class ShipperFactory
    {
        private static TShip Create<TShip>()
            where TShip : IShip, // interface contract constraint
            new() // public parameter-less constructor constraint
        {
            return new TShip();
        }

        public static readonly IDictionary<Shipper, Func<IShip>> Creators =
            new Dictionary<Shipper, Func<IShip>>()
        {
            { Shipper.UPS, () => Create<ShipperUPS>() },
            { Shipper.FedEx, () => Create<ShipperFedEx>() },
            { Shipper.Purolator, () => Create<ShipperPurolator>() }
        };

        public static IShip CreateInstance(Shipper enumModuleName)
        {
            return Creators[enumModuleName]();
        }
    }

looking for help. thanks
tbhattacharjee

AnswerRe: Generic usage is not clear in one program Pin
Gerry Schmitz12-Apr-17 4:57
mveGerry Schmitz12-Apr-17 4:57 
GeneralRe: Generic usage is not clear in one program Pin
OriginalGriff12-Apr-17 5:04
mveOriginalGriff12-Apr-17 5:04 
GeneralRe: Generic usage is not clear in one program Pin
Gerry Schmitz12-Apr-17 5:06
mveGerry Schmitz12-Apr-17 5:06 
GeneralRe: Generic usage is not clear in one program Pin
OriginalGriff12-Apr-17 5:43
mveOriginalGriff12-Apr-17 5:43 
AnswerRe: Generic usage is not clear in one program Pin
Richard MacCutchan12-Apr-17 22:00
mveRichard MacCutchan12-Apr-17 22:00 
Questiondynamic Crystal report ASP.NET MVC 5 Pin
Member 1021805212-Apr-17 2:26
Member 1021805212-Apr-17 2:26 
AnswerRe: dynamic Crystal report ASP.NET MVC 5 Pin
Afzaal Ahmad Zeeshan12-Apr-17 9:18
professionalAfzaal Ahmad Zeeshan12-Apr-17 9:18 
QuestionUser name and pasword from web page. Pin
Lubos111-Apr-17 5:09
Lubos111-Apr-17 5:09 
AnswerRe: User name and pasword from web page. Pin
Dave Kreskowiak11-Apr-17 5:30
mveDave Kreskowiak11-Apr-17 5:30 
GeneralRe: User name and pasword from web page. Pin
Lubos111-Apr-17 5:37
Lubos111-Apr-17 5:37 
GeneralRe: User name and pasword from web page. Pin
Lubos111-Apr-17 5:40
Lubos111-Apr-17 5:40 
GeneralRe: User name and pasword from web page. Pin
Lubos111-Apr-17 5:49
Lubos111-Apr-17 5:49 
GeneralRe: User name and pasword from web page. Pin
OriginalGriff11-Apr-17 5:59
mveOriginalGriff11-Apr-17 5:59 
GeneralRe: User name and pasword from web page. Pin
Lubos111-Apr-17 6:16
Lubos111-Apr-17 6:16 
GeneralRe: User name and pasword from web page. Pin
OriginalGriff11-Apr-17 6:25
mveOriginalGriff11-Apr-17 6:25 
GeneralRe: User name and pasword from web page. Pin
Lubos111-Apr-17 6:54
Lubos111-Apr-17 6:54 
GeneralRe: User name and pasword from web page. Pin
Gerry Schmitz11-Apr-17 7:18
mveGerry Schmitz11-Apr-17 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.