Author Topic: Windows - Command line and Dialog driven command  (Read 15591 times)

0 Members and 1 Guest are viewing this topic.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Windows - Command line and Dialog driven command
« Reply #15 on: October 01, 2008, 02:01:44 PM »

Ahh...Tim...what's the purpose of your IsLaterThan() function?

Just to make sure that the file that is going to be copied over is later than the one that is there now.  If it isn't a newer version, then don't copy it.  This is a one way copy, not syncing.


Hi Tim.

I think what Glenn was getting at is, why write a function that is essentially a reinvention of the DateTime's overloaded > (is-greater-than) operator ?


Code: [Select]

public bool IsLaterThan( DateTime thisDate, thatDate b )
{
    return thisDate > thatDate;
}



That's where I was going Tony - thanks. the overloading of operators or overloading in general is definately part of the OOP world.
Me

TonyT

  • Guest
Re: Windows - Command line and Dialog driven command
« Reply #16 on: October 01, 2008, 07:21:24 PM »
Those who are new to OOP and C# often find themselves reinventing things that already exist, merely because they did not know they were there. So, when one is just starting out, they can probably avoid reinventing many things that already exist if they were to just spend some time becoming more familiar with some of the basic principles and concepts of an OOP language and C# in particular, like operators and operator overloading.
Logical operators are considered OOP? I submit not.

You seem to have relational and logical operators confused, but regardless of that, it isn't operators that are 'oop', it is the ability of a type to overload/override the default operators, that is 'oop', and that's what we're talking about - overloading operators, not operators in general.


TonyT

  • Guest
Re: Windows - Command line and Dialog driven command
« Reply #17 on: October 01, 2008, 07:26:47 PM »
Tim:

While TonyT's explanation is correct, it doesn't provide the correct solution to your problem. When doing a comparison of a local copy to a remote/backup copy the only correct what to do it is compare a SHA1 hash of the local file to a SHA1 hash of the remote file. If they are different then the local copy needs to be moved to the remote location.

You seem to be confusing two very different questions:

1.  Are two files different?

2.  Which of two files was more recently changed?


tjr

  • Guest
Re: Windows - Command line and Dialog driven command
« Reply #18 on: October 01, 2008, 09:25:13 PM »
Those who are new to OOP and C# often find themselves reinventing things that already exist, merely because they did not know they were there. So, when one is just starting out, they can probably avoid reinventing many things that already exist if they were to just spend some time becoming more familiar with some of the basic principles and concepts of an OOP language and C# in particular, like operators and operator overloading.
Logical operators are considered OOP? I submit not.

You seem to have relational and logical operators confused, but regardless of that, it isn't operators that are 'oop', it is the ability of a type to overload/override the default operators, that is 'oop', and that's what we're talking about - overloading operators, not operators in general.
I'll admit I was confused. you are correct. statement retracted.

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Windows - Command line and Dialog driven command
« Reply #19 on: October 02, 2008, 03:25:35 PM »
I had some time to look into 'operator overload', but I didn't how one would know that the class DateTime does overload an operator?  I did notice that DateTime has a Compare method that I should have used.  Is it just common sense ( to a seasoned programming ) that the operator will be overloaded by default when comparing two like objects?

Off to see if my Inet searches will return better results than before for this topic.  Thanks again.  I really do appreciate it.

Edit:  All searches so far have shown how to make an overload for a custom class, not how to tell if a class has one.  That is the problem with my searching so far.
« Last Edit: October 02, 2008, 03:29:48 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Windows - Command line and Dialog driven command
« Reply #20 on: October 02, 2008, 03:43:26 PM »
Have you looked at DateTime through reflector? It might shed some light on whats available for you to party on.

Code: [Select]
   public static int Compare(DateTime t1, DateTime t2)
    {
        long internalTicks = t1.InternalTicks;
        long num2 = t2.InternalTicks;
        if (internalTicks > num2)
        {
            return 1;
        }
        if (internalTicks < num2)
        {
            return -1;
        }
        return 0;
    }

    public int CompareTo(DateTime value)
    {
        long internalTicks = value.InternalTicks;
        long num2 = this.InternalTicks;
        if (num2 > internalTicks)
        {
            return 1;
        }
        if (num2 < internalTicks)
        {
            return -1;
        }
        return 0;
    }

    public int CompareTo(object value)
    {
        if (value == null)
        {
            return 1;
        }
        if (!(value is DateTime))
        {
            throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDateTime"));
        }
        DateTime time = (DateTime) value;
        long internalTicks = time.InternalTicks;
        long num2 = this.InternalTicks;
        if (num2 > internalTicks)
        {
            return 1;
        }
        if (num2 < internalTicks)
        {
            return -1;
        }
        return 0;
    }


Code: [Select]
public static bool operator ==(DateTime d1, DateTime d2)
    {
        return (d1.InternalTicks == d2.InternalTicks);
    }

    public static bool operator >(DateTime t1, DateTime t2)
    {
        return (t1.InternalTicks > t2.InternalTicks);
    }

    public static bool operator >=(DateTime t1, DateTime t2)
    {
        return (t1.InternalTicks >= t2.InternalTicks);
    }

    public static bool operator !=(DateTime d1, DateTime d2)
    {
        return (d1.InternalTicks != d2.InternalTicks);
    }

    public static bool operator <(DateTime t1, DateTime t2)
    {
        return (t1.InternalTicks < t2.InternalTicks);
    }

    public static bool operator <=(DateTime t1, DateTime t2)
    {
        return (t1.InternalTicks <= t2.InternalTicks);
    }


Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Windows - Command line and Dialog driven command
« Reply #21 on: October 02, 2008, 03:49:07 PM »
Placing your cursor in the word/type definition 'DateTime' in Visual Studio and hitting F1 will take you to the help for a given object. When I do this, it takes me to MSDN and it gives Constructors, Methods, Fields, Properties and Overloads for the the type in question.

I guess, at the end of the day, even though you know there is a DateTime class/struct (struct in this case), it's up to you to investigate...or get several good books.
It's all part of the learning process Tim - keep at it, but keep at it. :D
Me

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Windows - Command line and Dialog driven command
« Reply #22 on: October 02, 2008, 03:52:34 PM »
...and Dan's disassembly shows, that in this case, using 'Compare' would be a more expensive operation than just using the overloaded operator >, as it just compares the internal long values...
Me

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Windows - Command line and Dialog driven command
« Reply #23 on: October 02, 2008, 03:57:15 PM »
Have you looked at DateTime through reflector? It might shed some light on whats available for you to party on.

<snip>
Didn't think of that Daniel.  Thanks for the idea.

Placing your cursor in the word/type definition 'DateTime' in Visual Studio and hitting F1 will take you to the help for a given object. When I do this, it takes me to MSDN and it gives Constructors, Methods, Fields, Properties and Overloads for the the type in question.

I guess, at the end of the day, even though you know there is a DateTime class/struct (struct in this case), it's up to you to investigate...or get several good books.
It's all part of the learning process Tim - keep at it, but keep at it. :D
Didn't know about the 'F1' taking you to MSDN.  That is a good tip, and it even works in SharpDevelop.  I don't see the 'Overloads' though on the page that pops up for me.  Can you post a link Glenn?  Maybe I can see why I wasn't sent to that page.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Windows - Command line and Dialog driven command
« Reply #24 on: October 02, 2008, 04:16:35 PM »
... I don't see the 'Overloads' though ...

It seems those operators are not overloaded

Spike Wilbury

  • Guest
Re: Windows - Command line and Dialog driven command
« Reply #25 on: October 02, 2008, 04:31:18 PM »
I don't see the 'Overloads' though on the page that pops up for me.  Can you post a link Glenn?  Maybe I can see why I wasn't sent to that page.

I am in a mac world now... but I guess Glenn was refering to the already overloaded list, if you open the DateTime structure it will show all the ones available.

maybe?

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Windows - Command line and Dialog driven command
« Reply #26 on: October 02, 2008, 04:54:38 PM »
I don't see the 'Overloads' though on the page that pops up for me.  Can you post a link Glenn?  Maybe I can see why I wasn't sent to that page.

I am in a mac world now... but I guess Glenn was refering to the already overloaded list, if you open the DateTime structure it will show all the ones available.

maybe?
I see that some methods and properties have been overload'ed, but I didn't see anything about operators.  Maybe the disassembly is the way to go for that.  I learned something new.   :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Spike Wilbury

  • Guest
Re: Windows - Command line and Dialog driven command
« Reply #27 on: October 02, 2008, 04:58:55 PM »
I see that some methods and properties have been overload'ed, but I didn't see anything about operators.  Maybe the disassembly is the way to go for that.  I learned something new.   :-)

I see, sorry did not read the whole thread.... next time - slap on my face -

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Windows - Command line and Dialog driven command
« Reply #28 on: October 02, 2008, 05:58:51 PM »
Look at the operators section.
Me

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Windows - Command line and Dialog driven command
« Reply #29 on: October 02, 2008, 06:08:51 PM »
Look at the operators section.

That is the same page I get, but when I changed it the .Net2.0 language it doesn't show the operators anymore.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.