Deutsch
Germany.ruФорумы → Архив Досок→ Программирование

​VB vs C#

129  
Murr патриот11.05.18 12:52
Murr
11.05.18 12:52 

VB vs C#


В общем - потерялись несколько исходников - пришлось декомпилировать.

Потом удалось часть найти и сравнить что получается по туда-и-обратно...


исходный код:

Private Function loadButtonColour(ByVal DTItems As DataTable, ByVal errTime As Integer) As String
Dim lastItemScannedAt As Date
Dim minSinceLastScan As Integer
Dim returnValue As String = "Red"
Try
lastItemScannedAt = DTItems.Compute("MAX(timestamp)", "")
minSinceLastScan = DTItems(0).Item("presentTime").Subtract(lastItemScannedAt).Days * 1440 + _
DTItems(0).Item("presentTime").Subtract(lastItemScannedAt).Hours * 60 + _
DTItems(0).Item("presentTime").Subtract(lastItemScannedAt).Minutes


If minSinceLastScan < errTime Then
returnValue = "Green"
End If


Catch ex As Exception
email.SendMailMessage(_senderAddress, My.Settings.emailErrorRecipient, "", "", _
My.Computer.Name.ToString & ": " & _
"error in: " & MyClass.GetType.Name & "." & _
System.Reflection.MethodBase.GetCurrentMethod.Name.ToString, _
ControlChars.CrLf & _
ex.ToString)
End Try
Return returnValue
End Function



Восстановленный код

private string loadButtonColour(DataTable DTItems, int errTime)
{
string returnValue = "Red";
try
{
DateTime lastItemScannedAt = Conversions.ToDate(DTItems.Compute("MAX(timestamp)", ""));
object item = DTItems.AsEnumerable().ElementAtOrDefault<DataRow>(0)["presentTime"];
object[] objArray = new object[] { lastItemScannedAt };
bool[] flagArray = new bool[] { true };
object obj = NewLateBinding.LateGet(item, null, "Subtract", objArray, null, null, flagArray);
if (flagArray[0])
{
lastItemScannedAt = (DateTime)Conversions.ChangeType(RuntimeHelpers.GetObjectValue(objArray[0]), typeof(DateTime));
}
object obj1 = Microsoft.VisualBasic.CompilerServices.Operators.MultiplyObject(NewLateBinding.LateGet(obj, null, "Days", new object[0], null, null, null), 1440);
object item1 = DTItems.AsEnumerable().ElementAtOrDefault<DataRow>(0)["presentTime"];
object[] objArray1 = new object[] { lastItemScannedAt };
bool[] flagArray1 = new bool[] { true };
object obj2 = NewLateBinding.LateGet(item1, null, "Subtract", objArray1, null, null, flagArray1);
if (flagArray1[0])
{
lastItemScannedAt = (DateTime)Conversions.ChangeType(RuntimeHelpers.GetObjectValue(objArray1[0]), typeof(DateTime));
}
object obj3 = Microsoft.VisualBasic.CompilerServices.Operators.AddObject(obj1, Microsoft.VisualBasic.CompilerServices.Operators.MultiplyObject(NewLateBinding.LateGet(obj2, null, "Hours", new object[0], null, null, null), 60));
object item2 = DTItems.AsEnumerable().ElementAtOrDefault<DataRow>(0)["presentTime"];
object[] objArray2 = new object[] { lastItemScannedAt };
bool[] flagArray2 = new bool[] { true };
object obj4 = NewLateBinding.LateGet(item2, null, "Subtract", objArray2, null, null, flagArray2);
if (flagArray2[0])
{
lastItemScannedAt = (DateTime)Conversions.ChangeType(RuntimeHelpers.GetObjectValue(objArray2[0]), typeof(DateTime));
}
if (Conversions.ToInteger(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(obj3, NewLateBinding.LateGet(obj4, null, "Minutes", new object[0], null, null, null))) < errTime)
{
returnValue = "Green";
}
}
catch (Exception exception)
{
ProjectData.SetProjectError(exception);
Exception ex = exception;
string str = this._senderAddress;
string settings = MySettingsProperty.Settings.emailErrorRecipient;
string[] strArrays = new string[] { MyProject.Computer.Name.ToString(), ": error in: ", this.GetType().Name, ".", MethodBase.GetCurrentMethod().Name.ToString() };
Email.SendMailMessage(str, settings, "", "", string.Concat(strArrays), string.Concat("\r\n", ex.ToString()));
ProjectData.ClearProjectError();
}
return returnValue;
}



Требуемое решение:

private string loadButtonColour(TItems.Table DTItems, int errTime)
{
string returnValue = "Red";
try
{
if ((DTItems.PresentTime - DTItems.MaxTimestamp).TotalMinutes < errTime)
{
returnValue = "Green";

}

}
catch (Exception ex)
{
TExceptionHandler.Error(ex);
}
return returnValue;

}

Не поименование переменных можно не смотреть - оно такое какое дадено...


П.С. Теперь Я точно знаю почему Я не люблю Васикa...

#1