Skip to content

Commit

Permalink
Batches 38-40 - Fix sample output (#6784)
Browse files Browse the repository at this point in the history
* Fix sample output

* one more fix
  • Loading branch information
mairaw authored Jun 2, 2021
1 parent 46c6267 commit 54e27a3
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ int main()
// Regional Info for Sweden
RegionInfo^ ri = gcnew RegionInfo("SE");

Console::Clear();
Console::WriteLine("Region English Name: . . . {0}", ri->EnglishName);
Console::WriteLine("Native Name: . . . . . . . {0}", ri->NativeName);
Console::WriteLine("Currency English Name: . . {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public ref class TestClass
public:
// Assign an ArgumentID attribute to each parameter.
// Assign an ArgumentUsage attribute to each parameter.
void TestMethod( [ArgumentID][ArgumentUsage("Must pass an array here.")]array<String^>^strArray,
void TestMethod( [ArgumentID][ArgumentUsage("Must pass an array here.")]array<String^>^strArray,
[ArgumentID][ArgumentUsage("Can pass param list or array here.")]array<String^>^strList ){}
};

int main()
{
// Get the class type, and then get the MethodInfo object
// Get the class type, and then get the MethodInfo object
// for TestMethod to access its metadata.
Type^ clsType = TestClass::typeid;
MethodInfo^ mInfo = clsType->GetMethod( "TestMethod" );
Expand Down Expand Up @@ -105,19 +105,19 @@ int main()
}
}
/*
The example displays the following output:
The example displays an output similar to the following:
Compare a usage attribute instance to another instance of the same attribute:
"ArgumentUsageAttribute:Must pass an array here." ==
"ArgumentUsageAttribute:Must pass an array here." ? True
Compare a usage attribute to another usage attribute:
"ArgumentUsageAttribute:Must pass an array here." ==
"ArgumentUsageAttribute:Can pass param list or array here." ? False
Compare an ID attribute instance to another instance of the same attribute:
"ArgumentIDAttribute.22d1a176-4aca-427b-8230-0c1563e13187" ==
"ArgumentIDAttribute.7fa94bba-c290-48e1-a0de-e22f6c1e64f1" ? False
Compare an ID attribute to another ID attribute:
"ArgumentIDAttribute.22d1a176-4aca-427b-8230-0c1563e13187" ==
"ArgumentIDAttribute.b9eea70d-9c0f-459e-a984-19c46b6c8789" ? False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main()
SamplesStringDictionary::Main();
}
// This code produces the following output.
// VALUE
// VALUES
// verde
// rojo
// azul
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public static void Main()
{
RegionInfo ri = new RegionInfo("SE"); // Sweden

Console.Clear();
Console.WriteLine("Region English Name: . . . {0}", ri.EnglishName);
Console.WriteLine("Native Name: . . . . . . . {0}", ri.NativeName);
Console.WriteLine("Currency English Name: . . {0}", ri.CurrencyEnglishName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void Main()
}
}
/*
The example displays the following output.
The example displays an output similar to the following:
// Compare a usage attribute instance to another instance of the same attribute:
// "ArgumentUsageAttribute: Must pass an array here." ==
// "ArgumentUsageAttribute: Must pass an array here."? True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void Main()
}
}
// This code produces the following output.
// VALUE
// VALUES
// verde
// rojo
// azul
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ private static void ConvertChar()
// The example displays the following output:
// 'a' converts to 97.
// 'z' converts to 122.
// '' converts to 7.
// '?' converts to 1023.
// '?' converts to 32767.
// Unable to convert u+FFFE to a UInt16.
// '' converts to 7.
// 'Ͽ' converts to 1023.
// '翿' converts to 32767.
// Unable to convert u+FFFE to an Int16.
// </Snippet3>
}

Expand Down Expand Up @@ -298,15 +298,15 @@ private static void ConvertSingle()
}
}
// The example displays the following output:
// -3.40282346638529E+38 is outside the range of the Int16 type.
// -13799999488 is outside the range of the Int16 type.
// Converted the Double value -1023.29901123047 to the Int16 value -1023.
// Converted the Double value -12.9799995422363 to the Int16 value -13.
// Converted the Double value 0 to the Int16 value 0.
// Converted the Double value 9.11299983940444E-16 to the Int16 value 0.
// Converted the Double value 103.918998718262 to the Int16 value 104.
// Converted the Double value 17834.19140625 to the Int16 value 17834.
// 3.40282346638529E+38 is outside the range of the Int16 type.
// -3.4028235E+38 is outside the range of the Int16 type.
// -1.38E+10 is outside the range of the Int16 type.
// Converted the Single value -1023.299 to the Int16 value -1023.
// Converted the Single value -12.98 to the Int16 value -13.
// Converted the Single value 0 to the Int16 value 0.
// Converted the Single value 9.113E-16 to the Int16 value 0.
// Converted the Single value 103.919 to the Int16 value 104.
// Converted the Single value 17834.191 to the Int16 value 17834.
// 3.4028235E+38 is outside the range of the Int16 type.
// </Snippet10>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ public class RateComparer<T1, T2, T3, T4, T5, T6, T7> : IEqualityComparer
{
private int argument = 0;

public new bool Equals(object x, object y)
public new bool Equals(object x, object y)
{
argument++;
if (argument == 1) return true;

double fx, fy;
double fx, fy;
if (x is Double || x is Single)
{
fx = (double) x;
Expand All @@ -23,42 +23,42 @@ public class RateComparer<T1, T2, T3, T4, T5, T6, T7> : IEqualityComparer
return x.Equals(y);
}
}

public int GetHashCode(object obj)
{
if (obj is Single || obj is Double)
return Math.Round(((double) obj) * 1000).GetHashCode();
else
return obj.GetHashCode();
}
}
}

public class Example
{
public static void Main()
{
var rate1 = Tuple.Create("New York", -.013934, .014505,
var rate1 = Tuple.Create("New York", -.013934, .014505,
-.1042733, .0354833, .093644, .0290792);
var rate2 = Tuple.Create("Unknown City", -.013934, .014505,
var rate2 = Tuple.Create("Unknown City", -.013934, .014505,
-.1042733, .0354833, .093644, .0290792);
var rate3 = Tuple.Create("Unknown City", -.013934, .014505,
var rate3 = Tuple.Create("Unknown City", -.013934, .014505,
-.1042733, .0354833, .093644, .029079);
var rate4 = Tuple.Create("San Francisco", -.0451934, -.0332858,
var rate4 = Tuple.Create("San Francisco", -.0451934, -.0332858,
-.0512803, .0662544, .0728964, .0491912);
IStructuralEquatable eq = rate1;
// Compare first tuple with remaining two tuples.
Console.WriteLine("{0} = ", rate1.ToString());
Console.WriteLine(" {0} : {1}", rate2,
Console.WriteLine(" {0} : {1}", rate2,
eq.Equals(rate2, new RateComparer<string, double, double, double, double, double, double>()));
Console.WriteLine(" {0} : {1}", rate3,
Console.WriteLine(" {0} : {1}", rate3,
eq.Equals(rate3, new RateComparer<string, double, double, double, double, double, double>()));
Console.WriteLine(" {0} : {1}", rate4,
Console.WriteLine(" {0} : {1}", rate4,
eq.Equals(rate4, new RateComparer<string, double, double,double, double, double, double>()));
}
}
// The example displays the following output:
// (New York, 0.014505, -0.1042733, 0.0354833, 0.093644, 0.0290792) =
// (Unknown City, 0.014505, -0.1042733, 0.0354833, 0.093644, 0.0290792) : True
// (Unknown City, 0.014505, -0.1042733, 0.0354833, 0.093644, 0.029079) : True
// (San Francisco, -0.0332858, -0.0512803, 0.0662544, 0.0728964, 0.0491912) : False
// (New York, -0.013934, 0.014505, -0.1042733, 0.0354833, 0.093644, 0.0290792) =
// (Unknown City, -0.013934, 0.014505, -0.1042733, 0.0354833, 0.093644, 0.0290792) : True
// (Unknown City, -0.013934, 0.014505, -0.1042733, 0.0354833, 0.093644, 0.029079) : True
// (San Francisco, -0.0451934, -0.0332858, -0.0512803, 0.0662544, 0.0728964, 0.0491912) : False
// </Snippet2>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'<snippet1>
' This example demonstrates the RegionInfo.EnglishName, NativeName,
' This example demonstrates the RegionInfo.EnglishName, NativeName,
' CurrencyEnglishName, CurrencyNativeName, and GeoId properties.
Imports System.Globalization

Class Sample
Public Shared Sub Main()
Dim ri As New RegionInfo("SE") ' Sweden
Console.Clear()
Console.WriteLine("Region English Name: . . . {0}", ri.EnglishName)
Console.WriteLine("Native Name: . . . . . . . {0}", ri.NativeName)
Console.WriteLine("Currency English Name: . . {0}", ri.CurrencyEnglishName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,128 +3,128 @@
' Define a custom parameter attribute that takes a single message argument.
<AttributeUsage(AttributeTargets.Parameter)> _
Public Class ArgumentUsageAttribute : Inherits Attribute

' This is the attribute constructor.
Public Sub New(UsageMsg As String)
Me.usageMsg = UsageMsg
End Sub
End Sub

' usageMsg is storage for the attribute message.
Protected usageMsg As String

' Append the message to what the base generates.
Public Overrides Function ToString() As String
Return $"{MyBase.ToString()}: {usageMsg}"
End Function
End Class
End Function
End Class

' Define a custom parameter attribute that generates a GUID for each instance.
<AttributeUsage(AttributeTargets.Parameter)> _
Public Class ArgumentIDAttribute : Inherits Attribute

' This is the attribute constructor, which generates the GUID.
Public Sub New()
Me.GUIDinstance = Guid.NewGuid()
End Sub

' instanceGUID is storage for the generated GUID.
Protected GUIDinstance As Guid

' Append the GUID to what the base generates.
Public Overrides Function ToString() As String
Return $"{MyBase.ToString()}.{ GUIDinstance}"
End Function
End Function
End Class

Public Class TestClass
' Assign an ArgumentID and an ArgumentUsage attribute to each parameter.
Public Sub TestMethod(
<ArgumentID, ArgumentUsage("Must pass an array here.")>
strArray() As String,
<ArgumentID, ArgumentUsage("Can pass param list or array here.")>
Public Sub TestMethod(
<ArgumentID, ArgumentUsage("Must pass an array here.")>
strArray() As String,
<ArgumentID, ArgumentUsage("Can pass param list or array here.")>
ParamArray strList() As String)
End Sub
End Class
End Class

Module AttributeEqualsDemo
Sub Main()
' Get the class type.
' Get the class type.
Dim clsType As Type = GetType(TestClass)
' Get the MethodInfo object for TestMethod to access its metadata.
' Get the MethodInfo object for TestMethod to access its metadata.
Dim mInfo As MethodInfo = clsType.GetMethod("TestMethod")

' There will be two elements in pInfoArray, one for each parameter.
Dim pInfoArray As ParameterInfo() = mInfo.GetParameters()
If pInfoArray IsNot Nothing Then
' Create an instance of the argument usage attribute on strArray.
Dim arrayUsageAttr1 As ArgumentUsageAttribute =
Attribute.GetCustomAttribute(pInfoArray(0),
Dim arrayUsageAttr1 As ArgumentUsageAttribute =
Attribute.GetCustomAttribute(pInfoArray(0),
GetType(ArgumentUsageAttribute))

' Create another instance of the argument usage attribute on strArray.
Dim arrayUsageAttr2 As ArgumentUsageAttribute = _
Attribute.GetCustomAttribute(pInfoArray(0), _
GetType(ArgumentUsageAttribute))

' Create an instance of the argument usage attribute on strList.
Dim listUsageAttr As ArgumentUsageAttribute = _
Attribute.GetCustomAttribute(pInfoArray(1), _
GetType(ArgumentUsageAttribute))

' Create an instance of the argument ID attribute on strArray.
Dim arrayIDAttr1 As ArgumentIDAttribute = _
Attribute.GetCustomAttribute(pInfoArray(0), _
GetType(ArgumentIDAttribute))

' Create another instance of the argument ID attribute on strArray.
Dim arrayIDAttr2 As ArgumentIDAttribute = _
Attribute.GetCustomAttribute(pInfoArray(0), _
GetType(ArgumentIDAttribute))

' Create an instance of the argument ID attribute on strList.
Dim listIDAttr As ArgumentIDAttribute = _
Attribute.GetCustomAttribute(pInfoArray(1), _
GetType(ArgumentIDAttribute))

' Compare various pairs of attributes for equality.
Console.WriteLine(vbCrLf & "Compare a usage attribute instance " & _
"to another instance of the same attribute:")
Console.WriteLine($" ""{arrayUsageAttr1}"" = {vbCrLf}" +
$" ""{arrayUsageAttr2}""? {arrayUsageAttr1.Equals(arrayUsageAttr2)}")
Console.WriteLine($" ""{arrayUsageAttr1}"" = {vbCrLf}" +
$" ""{arrayUsageAttr2}""? {arrayUsageAttr1.Equals(arrayUsageAttr2)}")

Console.WriteLine(vbCrLf & _
"Compare a usage attribute to another usage attribute:")
Console.WriteLine($" ""{arrayUsageAttr1}"" = {vbCrLf}" +
$" ""{listUsageAttr}""? {arrayUsageAttr1.Equals(listUsageAttr)}")
Console.WriteLine($" ""{arrayUsageAttr1}"" = {vbCrLf}" +
$" ""{listUsageAttr}""? {arrayUsageAttr1.Equals(listUsageAttr)}")

Console.WriteLine(vbCrLf & "Compare an ID attribute instance " & _
"to another instance of the same attribute:")
Console.WriteLine($" ""{arrayIDAttr1}"" = {vbCrLf}" +
$" ""{arrayIDAttr2}""? {arrayIDAttr1.Equals(arrayIDAttr2)}")

Console.WriteLine(vbCrLf & _
"Compare an ID attribute to another ID attribute:")
Console.WriteLine($" ""{arrayIDAttr1}"" ={vbCrLf}" +
Console.WriteLine($" ""{arrayIDAttr1}"" ={vbCrLf}" +
$" ""{listIDAttr}"" ? {arrayIDAttr1.Equals(listIDAttr)}")
Else
Console.WriteLine("The parameters information could " & _
"not be retrieved for method {0}.", mInfo.Name)
End If
End Sub
End Module
' The example displays the following output.
End Sub
End Module
' The example displays an output similar to the following:
' Compare a usage attribute instance to another instance of the same attribute:
' "ArgumentUsageAttribute: Must pass an array here." =
' "ArgumentUsageAttribute: Must pass an array here."? True
'
'
' Compare a usage attribute to another usage attribute:
' "ArgumentUsageAttribute: Must pass an array here." =
' "ArgumentUsageAttribute: Can pass param list or array here."? False
'
'
' Compare an ID attribute instance to another instance of the same attribute:
' "ArgumentIDAttribute.d4f78468-f1d0-4a08-b6da-58cad249f8ea" =
' "ArgumentIDAttribute.9b1151bd-9c87-4e9f-beb0-92375f8c24f7"? False
'
'
' Compare an ID attribute to another ID attribute:
' "ArgumentIDAttribute.d4f78468-f1d0-4a08-b6da-58cad249f8ea" =
' "ArgumentIDAttribute.7eba47d0-ff29-4e46-9740-e0ba05b39947"? False
Expand Down
Loading

0 comments on commit 54e27a3

Please sign in to comment.