Skip to content

Commit af73a25

Browse files
authored
Merge pull request #4148 from dotnet/publish-18187
Merge master into live
2 parents db45e83 + efcc087 commit af73a25

File tree

278 files changed

+4540
-4262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+4540
-4262
lines changed

samples/snippets/cpp/VS_Snippets_CLR/DataBinding/CPP/webcustomcontrol1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
// System.Web.UI.DataBindingHandlerAttribute
2222
// System.Web.UI.DataBindingHandlerAttribute.IsDefaultAttribute().
2323
/*The following example demonstrates the members of 'DataBinding' and
24-
' 'DataBindingCollection'.A new control 'SimpleWebControl' is created
24+
' 'DataBindingCollection'. A new control 'SimpleWebControl' is created
2525
and a 'Designer' attribute is attached to it which actually refers to the
26-
DesignTimeClass.The 'OnBindingsCollectionChanged(string)' method is overridden
26+
DesignTimeClass. The 'OnBindingsCollectionChanged(string)' method is overridden
2727
to actually capture the DataBindingCollection instance and add the
2828
DataBinding Expression to the property in the ASPX file. When 'Text' property of the
2929
SimpleWebControl is bound to the 'Text' property of 'Button1' at the DesignTime
3030
using the IDE, the 'OnBindingCollectionChanged' method is called and
3131
the 'Text' property of the 'SimpleWebControl' is updated in .aspx file.
32-
The actual DataBinding is done at the runtime.The properties of the 'DataBinding'
32+
The actual DataBinding is done at the runtime. The properties of the 'DataBinding'
3333
and 'DataBindingCollection' are written into a text file (DataBindingOutput.txt)
34-
in drive C.The Output is written at the design time itself.
34+
in drive C. The Output is written at the design time itself.
3535
3636
Note:This program has to be tested at "DesignTime".
3737
These are the instructions to be followed to successfully test the functionality of the program.

samples/snippets/cpp/VS_Snippets_CLR/EventLogEntry_CopyTo/CPP/eventlogentry_copyto.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
/*
55
The following example demonstrates the EventLogEntryCollection class and the
6-
CopyTo method of EventLogEntryCollection class.A new Source for eventlog 'MyNewLog'
7-
is created.A new entry is created for 'MyNewLog'.The entries of EventLog are copied
6+
CopyTo method of EventLogEntryCollection class. A new Source for eventlog 'MyNewLog'
7+
is created. A new entry is created for 'MyNewLog'. The entries of EventLog are copied
88
to an Array.
99
*/
1010

samples/snippets/cpp/VS_Snippets_CLR/EventLogEntry_Item/CPP/eventlogentry_item.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
/*
55
The following example demonstrates 'Item','Count' properties of
6-
EventLogEntryCollection class.A new Source for eventlog 'MyNewLog' is created.
7-
The program checks if a Event source exists.If the source already exists, it gets
6+
EventLogEntryCollection class. A new Source for eventlog 'MyNewLog' is created.
7+
The program checks if a Event source exists. If the source already exists, it gets
88
the Log name associated with it otherwise, creates a new event source.
9-
A new entry is created for 'MyNewLog'.Entries of 'MyNewLog' are obtained and
9+
A new entry is created for 'MyNewLog'.Entries of 'MyNewLog' are obtained and
1010
the count and the messages are displayed.
1111
1212
*/

samples/snippets/cpp/VS_Snippets_CLR/EventLog_WriteEntry_1_3/CPP/eventlog_writeentry_1_3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'WriteEntry(String, String, EventLogEntryType, Int32, Int16)',
77
'WriteEntry(String, String, EventLogEntryType, Int32, Int16, Byte->Item[]) '
88
and 'WriteEntry(String, EventLogEntryType, Int32, Int16)' of class
9-
'EventLog'.The following example writes the information to an event log.
9+
'EventLog'. The following example writes the information to an event log.
1010
*/
1111

1212
#using <System.dll>
Lines changed: 132 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,132 @@
1-
2-
// System::Reflection::Emit::FieldBuilder.SetCustomAttribute(ConstructorInfo, Byte->Item[])
3-
// System::Reflection::Emit::FieldBuilder.SetCustomAttribute(CustomAttributeBuilder)
4-
/*
5-
The following program demonstrates 'SetCustomAttribute(ConstructorInfo, Byte[])'
6-
and 'SetCustomAttribute(CustomAttributeBuilder)' methods of 'FieldBuilder' class.
7-
A dynamic assembly is created. A new class of type 'MyClass' is created.
8-
A 'Method' and a 'Field are defined in the class.Two 'CustomAttributes' are
9-
set to the field.The method initializes a value to 'Field'.Value of the field
10-
is displayed to console.Values of Attributes applied to field are retrieved and
11-
displayed to console.
12-
*/
13-
// <Snippet1>
14-
using namespace System;
15-
using namespace System::Threading;
16-
using namespace System::Reflection;
17-
using namespace System::Reflection::Emit;
18-
19-
[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
20-
public ref class MyAttribute1: public Attribute
21-
{
22-
public:
23-
String^ myCustomAttributeValue;
24-
MyAttribute1( String^ myString )
25-
{
26-
myCustomAttributeValue = myString;
27-
}
28-
};
29-
30-
31-
[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
32-
public ref class MyAttribute2: public Attribute
33-
{
34-
public:
35-
bool myCustomAttributeValue;
36-
MyAttribute2( bool myBool )
37-
{
38-
myCustomAttributeValue = myBool;
39-
}
40-
};
41-
42-
Type^ CreateCallee( AppDomain^ currentDomain )
43-
{
44-
// Create a simple name for the assembly.
45-
AssemblyName^ myAssemblyName = gcnew AssemblyName;
46-
myAssemblyName->Name = "EmittedAssembly";
47-
48-
// Create the called dynamic assembly.
49-
AssemblyBuilder^ myAssemblyBuilder = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
50-
ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
51-
52-
// Define a public class named 'CustomClass' in the assembly.
53-
TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "CustomClass", TypeAttributes::Public );
54-
55-
// Define a private String field named 'MyField' in the type.
56-
FieldBuilder^ myFieldBuilder = myTypeBuilder->DefineField( "MyField", String::typeid, FieldAttributes::Public );
57-
Type^ myAttributeType1 = MyAttribute1::typeid;
58-
59-
// Create a Constructorinfo Object* for attribute 'MyAttribute1'.
60-
array<Type^>^type1 = {String::typeid};
61-
ConstructorInfo^ myConstructorInfo = myAttributeType1->GetConstructor( type1 );
62-
63-
// Create the CustomAttribute instance of attribute of type 'MyAttribute1'.
64-
array<Object^>^obj1 = {"Test"};
65-
CustomAttributeBuilder^ attributeBuilder = gcnew CustomAttributeBuilder( myConstructorInfo,obj1 );
66-
67-
// Set the CustomAttribute 'MyAttribute1' to the Field.
68-
myFieldBuilder->SetCustomAttribute( attributeBuilder );
69-
Type^ myAttributeType2 = MyAttribute2::typeid;
70-
71-
// Create a Constructorinfo Object* for attribute 'MyAttribute2'.
72-
array<Type^>^type2 = {bool::typeid};
73-
ConstructorInfo^ myConstructorInfo2 = myAttributeType2->GetConstructor( type2 );
74-
75-
// Set the CustomAttribute 'MyAttribute2' to the Field.
76-
array<Byte>^bytes = {01,00,01,00,00};
77-
myFieldBuilder->SetCustomAttribute( myConstructorInfo2, bytes );
78-
79-
// Create a method.
80-
array<Type^>^type3 = {String::typeid,int::typeid};
81-
MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyMethod", MethodAttributes::Public, nullptr, type3 );
82-
ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
83-
myILGenerator->Emit( OpCodes::Ldarg_0 );
84-
myILGenerator->Emit( OpCodes::Ldarg_1 );
85-
myILGenerator->Emit( OpCodes::Stfld, myFieldBuilder );
86-
myILGenerator->EmitWriteLine( "Value of the Field is :" );
87-
myILGenerator->EmitWriteLine( myFieldBuilder );
88-
myILGenerator->Emit( OpCodes::Ret );
89-
return myTypeBuilder->CreateType();
90-
}
91-
92-
int main()
93-
{
94-
try
95-
{
96-
Type^ myCustomClass = CreateCallee( Thread::GetDomain() );
97-
98-
// Construct an instance of a type.
99-
Object^ myObject = Activator::CreateInstance( myCustomClass );
100-
Console::WriteLine( "FieldBuilder Sample" );
101-
102-
// Find a method in this type and call it on this Object*.
103-
MethodInfo^ myMethodInfo = myCustomClass->GetMethod( "MyMethod" );
104-
array<Object^>^obj1 = {"Sample string",3};
105-
myMethodInfo->Invoke( myObject, obj1 );
106-
107-
// Retrieve the values of Attributes applied to field and display to console.
108-
array<FieldInfo^>^myFieldInfo = myCustomClass->GetFields();
109-
for ( int i = 0; i < myFieldInfo->Length; i++ )
110-
{
111-
array<Object^>^attributes = myFieldInfo[ i ]->GetCustomAttributes( true );
112-
for ( int index = 0; index < attributes->Length; index++ )
113-
{
114-
if ( dynamic_cast<MyAttribute1^>(attributes[ index ]) )
115-
{
116-
MyAttribute1^ myCustomAttribute = safe_cast<MyAttribute1^>(attributes[ index ]);
117-
Console::WriteLine( "Attribute Value of (MyAttribute1): {0}", myCustomAttribute->myCustomAttributeValue );
118-
}
119-
if ( dynamic_cast<MyAttribute2^>(attributes[ index ]) )
120-
{
121-
MyAttribute2^ myCustomAttribute = safe_cast<MyAttribute2^>(attributes[ index ]);
122-
Console::WriteLine( "Attribute Value of (MyAttribute2): {0}", myCustomAttribute->myCustomAttributeValue );
123-
}
124-
}
125-
}
126-
}
127-
catch ( Exception^ e )
128-
{
129-
Console::WriteLine( "Exception Caught {0}", e->Message );
130-
}
131-
}
132-
// </Snippet1>
1+
2+
// System::Reflection::Emit::FieldBuilder.SetCustomAttribute(ConstructorInfo, Byte->Item[])
3+
// System::Reflection::Emit::FieldBuilder.SetCustomAttribute(CustomAttributeBuilder)
4+
/*
5+
The following program demonstrates 'SetCustomAttribute(ConstructorInfo, Byte[])'
6+
and 'SetCustomAttribute(CustomAttributeBuilder)' methods of 'FieldBuilder' class.
7+
A dynamic assembly is created. A new class of type 'MyClass' is created.
8+
A 'Method' and a 'Field are defined in the class.Two 'CustomAttributes' are
9+
set to the field. The method initializes a value to 'Field'.Value of the field
10+
is displayed to console.Values of Attributes applied to field are retrieved and
11+
displayed to console.
12+
*/
13+
// <Snippet1>
14+
using namespace System;
15+
using namespace System::Threading;
16+
using namespace System::Reflection;
17+
using namespace System::Reflection::Emit;
18+
19+
[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
20+
public ref class MyAttribute1: public Attribute
21+
{
22+
public:
23+
String^ myCustomAttributeValue;
24+
MyAttribute1( String^ myString )
25+
{
26+
myCustomAttributeValue = myString;
27+
}
28+
};
29+
30+
31+
[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
32+
public ref class MyAttribute2: public Attribute
33+
{
34+
public:
35+
bool myCustomAttributeValue;
36+
MyAttribute2( bool myBool )
37+
{
38+
myCustomAttributeValue = myBool;
39+
}
40+
};
41+
42+
Type^ CreateCallee( AppDomain^ currentDomain )
43+
{
44+
// Create a simple name for the assembly.
45+
AssemblyName^ myAssemblyName = gcnew AssemblyName;
46+
myAssemblyName->Name = "EmittedAssembly";
47+
48+
// Create the called dynamic assembly.
49+
AssemblyBuilder^ myAssemblyBuilder = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
50+
ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
51+
52+
// Define a public class named 'CustomClass' in the assembly.
53+
TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "CustomClass", TypeAttributes::Public );
54+
55+
// Define a private String field named 'MyField' in the type.
56+
FieldBuilder^ myFieldBuilder = myTypeBuilder->DefineField( "MyField", String::typeid, FieldAttributes::Public );
57+
Type^ myAttributeType1 = MyAttribute1::typeid;
58+
59+
// Create a Constructorinfo Object* for attribute 'MyAttribute1'.
60+
array<Type^>^type1 = {String::typeid};
61+
ConstructorInfo^ myConstructorInfo = myAttributeType1->GetConstructor( type1 );
62+
63+
// Create the CustomAttribute instance of attribute of type 'MyAttribute1'.
64+
array<Object^>^obj1 = {"Test"};
65+
CustomAttributeBuilder^ attributeBuilder = gcnew CustomAttributeBuilder( myConstructorInfo,obj1 );
66+
67+
// Set the CustomAttribute 'MyAttribute1' to the Field.
68+
myFieldBuilder->SetCustomAttribute( attributeBuilder );
69+
Type^ myAttributeType2 = MyAttribute2::typeid;
70+
71+
// Create a Constructorinfo Object* for attribute 'MyAttribute2'.
72+
array<Type^>^type2 = {bool::typeid};
73+
ConstructorInfo^ myConstructorInfo2 = myAttributeType2->GetConstructor( type2 );
74+
75+
// Set the CustomAttribute 'MyAttribute2' to the Field.
76+
array<Byte>^bytes = {01,00,01,00,00};
77+
myFieldBuilder->SetCustomAttribute( myConstructorInfo2, bytes );
78+
79+
// Create a method.
80+
array<Type^>^type3 = {String::typeid,int::typeid};
81+
MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyMethod", MethodAttributes::Public, nullptr, type3 );
82+
ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
83+
myILGenerator->Emit( OpCodes::Ldarg_0 );
84+
myILGenerator->Emit( OpCodes::Ldarg_1 );
85+
myILGenerator->Emit( OpCodes::Stfld, myFieldBuilder );
86+
myILGenerator->EmitWriteLine( "Value of the Field is :" );
87+
myILGenerator->EmitWriteLine( myFieldBuilder );
88+
myILGenerator->Emit( OpCodes::Ret );
89+
return myTypeBuilder->CreateType();
90+
}
91+
92+
int main()
93+
{
94+
try
95+
{
96+
Type^ myCustomClass = CreateCallee( Thread::GetDomain() );
97+
98+
// Construct an instance of a type.
99+
Object^ myObject = Activator::CreateInstance( myCustomClass );
100+
Console::WriteLine( "FieldBuilder Sample" );
101+
102+
// Find a method in this type and call it on this Object*.
103+
MethodInfo^ myMethodInfo = myCustomClass->GetMethod( "MyMethod" );
104+
array<Object^>^obj1 = {"Sample string",3};
105+
myMethodInfo->Invoke( myObject, obj1 );
106+
107+
// Retrieve the values of Attributes applied to field and display to console.
108+
array<FieldInfo^>^myFieldInfo = myCustomClass->GetFields();
109+
for ( int i = 0; i < myFieldInfo->Length; i++ )
110+
{
111+
array<Object^>^attributes = myFieldInfo[ i ]->GetCustomAttributes( true );
112+
for ( int index = 0; index < attributes->Length; index++ )
113+
{
114+
if ( dynamic_cast<MyAttribute1^>(attributes[ index ]) )
115+
{
116+
MyAttribute1^ myCustomAttribute = safe_cast<MyAttribute1^>(attributes[ index ]);
117+
Console::WriteLine( "Attribute Value of (MyAttribute1): {0}", myCustomAttribute->myCustomAttributeValue );
118+
}
119+
if ( dynamic_cast<MyAttribute2^>(attributes[ index ]) )
120+
{
121+
MyAttribute2^ myCustomAttribute = safe_cast<MyAttribute2^>(attributes[ index ]);
122+
Console::WriteLine( "Attribute Value of (MyAttribute2): {0}", myCustomAttribute->myCustomAttributeValue );
123+
}
124+
}
125+
}
126+
}
127+
catch ( Exception^ e )
128+
{
129+
Console::WriteLine( "Exception Caught {0}", e->Message );
130+
}
131+
}
132+
// </Snippet1>

samples/snippets/cpp/VS_Snippets_CLR/InstallerCollection_Item/CPP/installercollection_item.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The following example demonstrates the 'Item(Int32)' method of the
55
'InstallerCollection' class. It creates 'AssemblyInstaller' instances
66
for 'MyAssembly1.exe' and 'MyAssembly2.exe'. These instances are added
77
to an instance of 'TransactedInstaller'. The names of all the assemblies
8-
that are to be installed are displayed to the console.The installation
8+
that are to be installed are displayed to the console. The installation
99
process installs both 'MyAssembly1.exe' and 'MyAssembly2.exe'.
1010
*/
1111

samples/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_GetArrayMethod/CPP/modulebuilder_getarraymethod.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ The following example demonstrates 'GetArrayMethod' and 'GetArrayMethodToken'
66
methods of 'ModuleBuilder' class.
77
A dynamic assembly with a module having a runtime class, 'TempClass' is created.
88
This class defines a method, 'SortArray', which sorts the elements of the array
9-
passed to it.The 'GetArrayMethod' method is used to obtain the 'MethodInfo' object
10-
corresponding to the 'Sort' method of the 'Array' .The token used to identify the 'Sort'
9+
passed to it. The 'GetArrayMethod' method is used to obtain the 'MethodInfo' object
10+
corresponding to the 'Sort' method of the 'Array'. The token used to identify the 'Sort'
1111
method in dynamic module is displayed using 'GetArrayMethodToken' method.
1212
*/
1313

samples/snippets/cpp/VS_Snippets_CLR/PropertyBuilder_SetGetMethod_4/CPP/propertybuilder_setgetmethod_4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Type^ CreateCallee( AppDomain^ myAppDomain, AssemblyBuilderAccess access )
4848
array<Type^>^constructorArgs = {String::typeid};
4949
ConstructorBuilder^ constructor = helloWorldTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, constructorArgs );
5050

51-
// Generate IL code for the method.The constructor stores its argument in the private field.
51+
// Generate IL code for the method. The constructor stores its argument in the private field.
5252
ILGenerator^ constructorIL = constructor->GetILGenerator();
5353
constructorIL->Emit( OpCodes::Ldarg_0 );
5454
constructorIL->Emit( OpCodes::Ldarg_1 );

samples/snippets/cpp/VS_Snippets_CLR/TypeBuilder_Sample_4/CPP/typebuilder_sample_4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Type^ CreateDynamicAssembly( AppDomain^ myAppDomain, AssemblyBuilderAccess myAcc
5555
ConstructorBuilder^ myConstructorBuilder =
5656
helloWorldTypeBuilder->DefineConstructor( MethodAttributes::Public,
5757
CallingConventions::Standard, constructorArgs );
58-
// Generate IL for the method.The constructor stores its argument in the private field.
58+
// Generate IL for the method. The constructor stores its argument in the private field.
5959
ILGenerator^ myConstructorIL = myConstructorBuilder->GetILGenerator();
6060
myConstructorIL->Emit( OpCodes::Ldarg_0 );
6161
myConstructorIL->Emit( OpCodes::Ldarg_1 );

samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.XML.SignedXml.ComputeSig-Check-KeyedHash-Detached/CPP/xmldsigdetachedkeyedhashalg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int main()
8888

8989
// Sign the detached resourceand save the signature in an XML file.
9090
SignDetachedResource( resourceToSign, XmlFileName, Key );
91-
Console::WriteLine( "XML signature was succesfully computed and saved to {0}.", XmlFileName );
91+
Console::WriteLine( "XML signature was successfully computed and saved to {0}.", XmlFileName );
9292

9393
// Verify the signature of the signed XML.
9494
Console::WriteLine( "Verifying signature..." );

0 commit comments

Comments
 (0)