Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

##Conventions

Conventions

  • Use meaningful and camel-cased names var GI1 GIUS ..
  • Use var when the instance type is the same as the declaring type CimSession session =

##Design

Design

I suggest to create a class to store the info you require from the cim interface.

 class CimInfo
 {
 public CimInfo(CimInstance cim)
 {
 UserName = GetProperty(cim, "UserName");
 BootUpState = GetProperty(cim, "BootUpState");
 Manufacturer = GetProperty(cim, "Manufacturer");
 Model = GetProperty(cim, "Model");
 }
 private static string GetProperty(CimInstance cim, string name)
 {
 if (cim == null) throw new ArgumentNullException(nameof(cim));
 return cim.CimInstanceProperties[name].Value.ToString();
 }
 public string UserName { get; }
 public string BootUpState { get; }
 public string Manufacturer { get; }
 public string Model { get; }
 }

The async operations can be merged and rewritten using the new class. Since you only have need of one cim instance, we could also avoid looping all queried results.

Notes:

  • Perhaps there is an alternative available for QueryInstances that only returns the first result.
  • If CimSession implements IDisposable, use a using block for it.

snippet

var cimInfo = await Task.Run(() =>
 {
 var session = CimSession.Create(computerHostName);
 var queryResults = session.QueryInstances(nameSpace, WQL, 
 "SELECT Username, BootUpState, Manufacturer, Model FROM Win32_ComputerSystem");
 return new CimInfo(queryResults.FirstOrDefault());
 });

And the output could be

TextBoxUserName.Text = cimInfo.UserName;
TextBoxBootUpState.Text = cimInfo.BootUpState;
TextBoxManufacturer.Text = cimInfo.Manufacturer;
TextBoxModel.Text = cimInfo.Model;

##Conventions

  • Use meaningful and camel-cased names var GI1 GIUS ..
  • Use var when the instance type is the same as the declaring type CimSession session =

##Design

I suggest to create a class to store the info you require from the cim interface.

 class CimInfo
 {
 public CimInfo(CimInstance cim)
 {
 UserName = GetProperty(cim, "UserName");
 BootUpState = GetProperty(cim, "BootUpState");
 Manufacturer = GetProperty(cim, "Manufacturer");
 Model = GetProperty(cim, "Model");
 }
 private static string GetProperty(CimInstance cim, string name)
 {
 if (cim == null) throw new ArgumentNullException(nameof(cim));
 return cim.CimInstanceProperties[name].Value.ToString();
 }
 public string UserName { get; }
 public string BootUpState { get; }
 public string Manufacturer { get; }
 public string Model { get; }
 }

The async operations can be merged and rewritten using the new class. Since you only have need of one cim instance, we could also avoid looping all queried results.

Notes:

  • Perhaps there is an alternative available for QueryInstances that only returns the first result.
  • If CimSession implements IDisposable, use a using block for it.

snippet

var cimInfo = await Task.Run(() =>
 {
 var session = CimSession.Create(computerHostName);
 var queryResults = session.QueryInstances(nameSpace, WQL, 
 "SELECT Username, BootUpState, Manufacturer, Model FROM Win32_ComputerSystem");
 return new CimInfo(queryResults.FirstOrDefault());
 });

And the output could be

TextBoxUserName.Text = cimInfo.UserName;
TextBoxBootUpState.Text = cimInfo.BootUpState;
TextBoxManufacturer.Text = cimInfo.Manufacturer;
TextBoxModel.Text = cimInfo.Model;

Conventions

  • Use meaningful and camel-cased names var GI1 GIUS ..
  • Use var when the instance type is the same as the declaring type CimSession session =

Design

I suggest to create a class to store the info you require from the cim interface.

 class CimInfo
 {
 public CimInfo(CimInstance cim)
 {
 UserName = GetProperty(cim, "UserName");
 BootUpState = GetProperty(cim, "BootUpState");
 Manufacturer = GetProperty(cim, "Manufacturer");
 Model = GetProperty(cim, "Model");
 }
 private static string GetProperty(CimInstance cim, string name)
 {
 if (cim == null) throw new ArgumentNullException(nameof(cim));
 return cim.CimInstanceProperties[name].Value.ToString();
 }
 public string UserName { get; }
 public string BootUpState { get; }
 public string Manufacturer { get; }
 public string Model { get; }
 }

The async operations can be merged and rewritten using the new class. Since you only have need of one cim instance, we could also avoid looping all queried results.

Notes:

  • Perhaps there is an alternative available for QueryInstances that only returns the first result.
  • If CimSession implements IDisposable, use a using block for it.

snippet

var cimInfo = await Task.Run(() =>
 {
 var session = CimSession.Create(computerHostName);
 var queryResults = session.QueryInstances(nameSpace, WQL, 
 "SELECT Username, BootUpState, Manufacturer, Model FROM Win32_ComputerSystem");
 return new CimInfo(queryResults.FirstOrDefault());
 });

And the output could be

TextBoxUserName.Text = cimInfo.UserName;
TextBoxBootUpState.Text = cimInfo.BootUpState;
TextBoxManufacturer.Text = cimInfo.Manufacturer;
TextBoxModel.Text = cimInfo.Model;
added 200 characters in body
Source Link
dfhwze
  • 14.1k
  • 3
  • 40
  • 101

##Conventions

  • Use meaningful and camel-cased names var GI1 GIUS ..
  • Use var when the instance type is the same as the declaring type CimSession session =

##Design

I suggest to create a class to store the info you require from the cim interface.

 class CimInfo
 {
 public CimInfo(CimInstance cim)
 {
 UserName = GetProperty(cim, "UserName");
 BootUpState = GetProperty(cim, "BootUpState");
 Manufacturer = GetProperty(cim, "Manufacturer");
 Model = GetProperty(cim, "Model");
 }
 private static string GetProperty(CimInstance cim, string name)
 {
 if (cim == null) throw new ArgumentNullException(nameof(cim));
 return cim.CimInstanceProperties[name].Value.ToString();
 }
 public string UserName { get; }
 public string BootUpState { get; }
 public string Manufacturer { get; }
 public string Model { get; }
 }

The async operations can be merged and rewritten using the new class. Since you only have need of one cim instance, we could also avoid looping all queried results.

Notes:

  • Perhaps there is an alternative available for QueryInstances that only returns the first result.
  • If CimSession implements IDisposable, use a using block for it.

snippet

var cimInfo = await Task.Run(() =>
 {
 var session = CimSession.Create(computerHostName);
 var queryResults = session.QueryInstances(nameSpace, WQL, 
 "SELECT Username, BootUpState, Manufacturer, Model FROM Win32_ComputerSystem");
 return new CimInfo(queryResults.FirstOrDefault());
 });

And the output could be

TextBoxUserName.Text = cimInfo.UserName;
TextBoxBootUpState.Text = cimInfo.BootUpState;
TextBoxManufacturer.Text = cimInfo.Manufacturer;
TextBoxModel.Text = cimInfo.Model;

##Conventions

  • Use meaningful and camel-cased names var GI1 GIUS ..
  • Use var when the instance type is the same as the declaring type CimSession session =

##Design

I suggest to create a class to store the info you require from the cim interface.

 class CimInfo
 {
 public CimInfo(CimInstance cim)
 {
 UserName = GetProperty(cim, "UserName");
 BootUpState = GetProperty(cim, "BootUpState");
 Manufacturer = GetProperty(cim, "Manufacturer");
 Model = GetProperty(cim, "Model");
 }
 private static string GetProperty(CimInstance cim, string name)
 {
 if (cim == null) throw new ArgumentNullException(nameof(cim));
 return cim.CimInstanceProperties[name].Value.ToString();
 }
 public string UserName { get; }
 public string BootUpState { get; }
 public string Manufacturer { get; }
 public string Model { get; }
 }

The async operations can be merged and rewritten using the new class. Since you only have need of one cim instance, we could also avoid looping all queried results.

var cimInfo = await Task.Run(() =>
 {
 var session = CimSession.Create(computerHostName);
 var queryResults = session.QueryInstances(nameSpace, WQL, 
 "SELECT Username, BootUpState, Manufacturer, Model FROM Win32_ComputerSystem");
 return new CimInfo(queryResults.FirstOrDefault());
 });

And the output could be

TextBoxUserName.Text = cimInfo.UserName;
TextBoxBootUpState.Text = cimInfo.BootUpState;
TextBoxManufacturer.Text = cimInfo.Manufacturer;
TextBoxModel.Text = cimInfo.Model;

##Conventions

  • Use meaningful and camel-cased names var GI1 GIUS ..
  • Use var when the instance type is the same as the declaring type CimSession session =

##Design

I suggest to create a class to store the info you require from the cim interface.

 class CimInfo
 {
 public CimInfo(CimInstance cim)
 {
 UserName = GetProperty(cim, "UserName");
 BootUpState = GetProperty(cim, "BootUpState");
 Manufacturer = GetProperty(cim, "Manufacturer");
 Model = GetProperty(cim, "Model");
 }
 private static string GetProperty(CimInstance cim, string name)
 {
 if (cim == null) throw new ArgumentNullException(nameof(cim));
 return cim.CimInstanceProperties[name].Value.ToString();
 }
 public string UserName { get; }
 public string BootUpState { get; }
 public string Manufacturer { get; }
 public string Model { get; }
 }

The async operations can be merged and rewritten using the new class. Since you only have need of one cim instance, we could also avoid looping all queried results.

Notes:

  • Perhaps there is an alternative available for QueryInstances that only returns the first result.
  • If CimSession implements IDisposable, use a using block for it.

snippet

var cimInfo = await Task.Run(() =>
 {
 var session = CimSession.Create(computerHostName);
 var queryResults = session.QueryInstances(nameSpace, WQL, 
 "SELECT Username, BootUpState, Manufacturer, Model FROM Win32_ComputerSystem");
 return new CimInfo(queryResults.FirstOrDefault());
 });

And the output could be

TextBoxUserName.Text = cimInfo.UserName;
TextBoxBootUpState.Text = cimInfo.BootUpState;
TextBoxManufacturer.Text = cimInfo.Manufacturer;
TextBoxModel.Text = cimInfo.Model;
Source Link
dfhwze
  • 14.1k
  • 3
  • 40
  • 101

##Conventions

  • Use meaningful and camel-cased names var GI1 GIUS ..
  • Use var when the instance type is the same as the declaring type CimSession session =

##Design

I suggest to create a class to store the info you require from the cim interface.

 class CimInfo
 {
 public CimInfo(CimInstance cim)
 {
 UserName = GetProperty(cim, "UserName");
 BootUpState = GetProperty(cim, "BootUpState");
 Manufacturer = GetProperty(cim, "Manufacturer");
 Model = GetProperty(cim, "Model");
 }
 private static string GetProperty(CimInstance cim, string name)
 {
 if (cim == null) throw new ArgumentNullException(nameof(cim));
 return cim.CimInstanceProperties[name].Value.ToString();
 }
 public string UserName { get; }
 public string BootUpState { get; }
 public string Manufacturer { get; }
 public string Model { get; }
 }

The async operations can be merged and rewritten using the new class. Since you only have need of one cim instance, we could also avoid looping all queried results.

var cimInfo = await Task.Run(() =>
 {
 var session = CimSession.Create(computerHostName);
 var queryResults = session.QueryInstances(nameSpace, WQL, 
 "SELECT Username, BootUpState, Manufacturer, Model FROM Win32_ComputerSystem");
 return new CimInfo(queryResults.FirstOrDefault());
 });

And the output could be

TextBoxUserName.Text = cimInfo.UserName;
TextBoxBootUpState.Text = cimInfo.BootUpState;
TextBoxManufacturer.Text = cimInfo.Manufacturer;
TextBoxModel.Text = cimInfo.Model;
lang-cs

AltStyle によって変換されたページ (->オリジナル) /