Click here to Skip to main content
15,913,685 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I Give Up Pin
Kevin Marois8-Apr-19 12:43
professionalKevin Marois8-Apr-19 12:43 
QuestionRe: I Give Up Pin
megaadam7-Apr-19 9:00
professionalmegaadam7-Apr-19 9:00 
AnswerRe: I Give Up Pin
#realJSOP7-Apr-19 9:07
professional#realJSOP7-Apr-19 9:07 
GeneralRe: I Give Up Pin
Mycroft Holmes7-Apr-19 12:46
professionalMycroft Holmes7-Apr-19 12:46 
GeneralRe: I Give Up Pin
#realJSOP7-Apr-19 13:27
professional#realJSOP7-Apr-19 13:27 
GeneralRe: I Give Up Pin
Matthew Dennis7-Apr-19 15:59
sysadminMatthew Dennis7-Apr-19 15:59 
GeneralRe: I Give Up Pin
#realJSOP7-Apr-19 21:25
professional#realJSOP7-Apr-19 21:25 
GeneralMake your damn mind up Visual Studio! Pin
OriginalGriff7-Apr-19 0:53
mveOriginalGriff7-Apr-19 0:53 
OK, VS2019 is installed, and I loaded a small test project into it - the one I use for checking code before I answer a QA question, as it happens.

And the first thing I notice (once I've got all the windows where they belong, and found where to turn off the line numbers anyway) is that it "suggests" changes: using an expression bodied constructor instead of the older style:
public frmMain()
    {
    InitializeComponent();
    }
IS out, and this is in:
public frmMain() => InitializeComponent();
Hmmm ... OK, I can learn to live with that.
Then: "Replace GetWindowsInstallationDateTime with a property":
public static DateTime GetWindowsInstallationDateTime()
    {
    Microsoft.Win32.RegistryKey key = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
    key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
    if (key != null)
        {
        DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        Int64 regVal = Convert.ToInt64(key.GetValue("InstallDate").ToString());
        DateTime installDate = startDate.AddSeconds(regVal);
        return installDate;
        }

    return DateTime.MinValue;
    }
Is out, this is in:
public static DateTime WindowsInstallationDateTime
    {
    get
        {
        Microsoft.Win32.RegistryKey key = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
        key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
        if (key != null)
            {
            DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            Int64 regVal = Convert.ToInt64(key.GetValue("InstallDate").ToString());
            DateTime installDate = startDate.AddSeconds(regVal);
            return installDate;
            }

        return DateTime.MinValue;
        }
    }
Hmmm. Less sure about this, but I can see why. Kinda. OK. Do it.
What's next?
Oh, right: "Replace WindowsInstallationDateTime with a method".

Hang on a moment ... you want to replace
public static DateTime WindowsInstallationDateTime
    {
    get
        {
        Microsoft.Win32.RegistryKey key = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
        key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
        if (key != null)
            {
            DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            Int64 regVal = Convert.ToInt64(key.GetValue("InstallDate").ToString());
            DateTime installDate = startDate.AddSeconds(regVal);
            return installDate;
            }

        return DateTime.MinValue;
        }
    }
With
public static DateTime GetWindowsInstallationDateTime()
    {
    Microsoft.Win32.RegistryKey key = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
    key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
    if (key != null)
        {
        DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        Int64 regVal = Convert.ToInt64(key.GetValue("InstallDate").ToString());
        DateTime installDate = startDate.AddSeconds(regVal);
        return installDate;
        }

    return DateTime.MinValue;
    }
That's exactly what I started with! This is going to get annoying, isn't it ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Make your damn mind up Visual Studio! Pin
Eddy Vluggen7-Apr-19 1:26
professionalEddy Vluggen7-Apr-19 1:26 
GeneralRe: Make your damn mind up Visual Studio! Pin
OriginalGriff7-Apr-19 1:40
mveOriginalGriff7-Apr-19 1:40 
GeneralRe: Make your damn mind up Visual Studio! Pin
Eddy Vluggen7-Apr-19 3:04
professionalEddy Vluggen7-Apr-19 3:04 
GeneralRe: Make your damn mind up Visual Studio! Pin
Kornfeld Eliyahu Peter7-Apr-19 2:50
professionalKornfeld Eliyahu Peter7-Apr-19 2:50 
GeneralRe: Make your damn mind up Visual Studio! Pin
Minion no. 57-Apr-19 5:23
Minion no. 57-Apr-19 5:23 
GeneralRe: Make your damn mind up Visual Studio! Pin
User 110609797-Apr-19 5:55
User 110609797-Apr-19 5:55 
GeneralRe: Make your damn mind up Visual Studio! Pin
Dave Kreskowiak7-Apr-19 5:39
mveDave Kreskowiak7-Apr-19 5:39 
GeneralRe: Make your damn mind up Visual Studio! Pin
phil.o7-Apr-19 5:54
professionalphil.o7-Apr-19 5:54 
GeneralRe: Make your damn mind up Visual Studio! Pin
Chris Maunder7-Apr-19 6:43
cofounderChris Maunder7-Apr-19 6:43 
GeneralRe: Make your damn mind up Visual Studio! Pin
Michael Martin7-Apr-19 11:12
professionalMichael Martin7-Apr-19 11:12 
GeneralRe: Make your damn mind up Visual Studio! Pin
Chris Maunder7-Apr-19 14:29
cofounderChris Maunder7-Apr-19 14:29 
GeneralRe: Make your damn mind up Visual Studio! Pin
Michael Martin7-Apr-19 16:31
professionalMichael Martin7-Apr-19 16:31 
GeneralRe: Make your damn mind up Visual Studio! Pin
Ravi Bhavnani7-Apr-19 15:45
professionalRavi Bhavnani7-Apr-19 15:45 
GeneralRe: Make your damn mind up Visual Studio! Pin
Ravi Bhavnani7-Apr-19 15:43
professionalRavi Bhavnani7-Apr-19 15:43 
GeneralRe: Make your damn mind up Visual Studio! Pin
OriginalGriff7-Apr-19 20:26
mveOriginalGriff7-Apr-19 20:26 
GeneralRe: Make your damn mind up Visual Studio! Pin
CPallini7-Apr-19 23:25
mveCPallini7-Apr-19 23:25 
GeneralRemoving things isn't as easy as it should be... Pin
OriginalGriff6-Apr-19 23:01
mveOriginalGriff6-Apr-19 23:01 

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.