Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
AnswerRe: Drawing Text on Panel Pin
BobJanova15-Feb-12 2:02
BobJanova15-Feb-12 2:02 
GeneralRe: Drawing Text on Panel Pin
Danzy8315-Feb-12 2:10
Danzy8315-Feb-12 2:10 
GeneralRe: Drawing Text on Panel Pin
Pete O'Hanlon15-Feb-12 2:25
mvePete O'Hanlon15-Feb-12 2:25 
GeneralRe: Drawing Text on Panel Pin
BillWoodruff18-Feb-12 1:05
professionalBillWoodruff18-Feb-12 1:05 
AnswerRe: Drawing Text on Panel Pin
Montasser Ben Ouhida2-Mar-12 4:30
Montasser Ben Ouhida2-Mar-12 4:30 
QuestionHow to create method extensions but inject into them with IoC Pin
Gizz14-Feb-12 23:08
Gizz14-Feb-12 23:08 
AnswerRe: How to create method extensions but inject into them with IoC Pin
BobJanova14-Feb-12 23:24
BobJanova14-Feb-12 23:24 
GeneralRe: How to create method extensions but inject into them with IoC Pin
Gizz15-Feb-12 0:16
Gizz15-Feb-12 0:16 
I'll try again with an example:

Here is the current naive implementation:

C#
public static class DateExtension
{
    static readonly Dictionary<DateTime, Holiday> Dict;
    static DateExtension()
    {
        Dict = new Dictionary<DateTime, Holiday>();
    }

    public static void SetHoliday(Holiday holidayToAdd)
    {
        Dict.Add(holidayToAdd.Date, holidayToAdd);
    }

    public static bool IsWorkingDay(this DateTime dateToCheck)
    {
        if (dateToCheck.DayOfWeek == DayOfWeek.Saturday ||
            dateToCheck.DayOfWeek == DayOfWeek.Sunday)
        {
            return false;
        }

        return !Dict.ContainsKey(dateToCheck);
    }
}

/// <summary>
/// This is the Holiday entity pulled from DB using NH or similar...
/// </summary>
public class Holiday
{
    public virtual DateTime Date { get; set; }
    public virtual string Description { get; set; }
}


To use this, you have to stuff the DateExtension with the holidays first

Holiday hol = new Holiday {Date = new DateTime(2012, 1, 2), Description = "NYD 2012"};
DateExtension.SetHoliday(hol);


So you would use it like this:
DateTime dt = new DateTime(2012, 1, 2);

Debug.Assert(!dt.IsWorkingDay());
dt = dt.AddDays(1);
Debug.Assert(dt.IsWorkingDay());


Now, the question is about, how can I nicely get CW to instantiate the holidays into the static extension, without doing something like this:

XML
var holRep = _container.Resolve<IHolidayRepository>();
DateExtension.SetAllHolidays(holRep.All());


In other words, can anyone think of a way to do this automatically within CW by simply registering the static class DateExtension in CW and have it inject the repository for me?

Thx
GeneralRe: How to create method extensions but inject into them with IoC Pin
BobJanova15-Feb-12 0:38
BobJanova15-Feb-12 0:38 
GeneralRe: How to create method extensions but inject into them with IoC Pin
Gizz15-Feb-12 1:41
Gizz15-Feb-12 1:41 
GeneralRe: How to create method extensions but inject into them with IoC Pin
BobJanova15-Feb-12 1:58
BobJanova15-Feb-12 1:58 
QuestionGive me some Suggestions for Make a Editor like Word Pin
Marlai14-Feb-12 21:15
Marlai14-Feb-12 21:15 
AnswerRe: Give me some Suggestions for Make a Editor like Word Pin
thatraja14-Feb-12 21:36
professionalthatraja14-Feb-12 21:36 
Questionpso(particle swarm optimization) Pin
nasrin6614-Feb-12 21:01
nasrin6614-Feb-12 21:01 
Questioncapturing outward traffic Pin
saneehaAamir14-Feb-12 19:14
saneehaAamir14-Feb-12 19:14 
AnswerRe: capturing outward traffic Pin
Keith Barrow14-Feb-12 21:52
professionalKeith Barrow14-Feb-12 21:52 
QuestionAbout Reflecting and generics Pin
PozzaVecia14-Feb-12 11:06
PozzaVecia14-Feb-12 11:06 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 11:19
sitebuilderLuc Pattyn14-Feb-12 11:19 
GeneralRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 11:42
PozzaVecia14-Feb-12 11:42 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 12:08
sitebuilderLuc Pattyn14-Feb-12 12:08 
GeneralRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 12:29
PozzaVecia14-Feb-12 12:29 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 12:41
sitebuilderLuc Pattyn14-Feb-12 12:41 
RantRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 12:58
PozzaVecia14-Feb-12 12:58 
GeneralRe: About Reflecting and generics Pin
GParkings14-Feb-12 23:44
GParkings14-Feb-12 23:44 
GeneralRe: About Reflecting and generics Pin
PozzaVecia15-Feb-12 0:10
PozzaVecia15-Feb-12 0:10 

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.