diff --git a/snippets/cpp/VS_Snippets_CLR/Assembly.FullName/CPP/Example.cpp b/snippets/cpp/VS_Snippets_CLR/Assembly.FullName/CPP/Example.cpp
deleted file mode 100644
index 54654202f49..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Assembly.FullName/CPP/Example.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-void main()
-{
- Console::WriteLine("The FullName property (also called the display name) of...");
- Console::WriteLine("...the currently executing assembly:");
- Console::WriteLine(Assembly::GetExecutingAssembly()->FullName);
-
- Console::WriteLine("...the assembly that contains the Int32 type:");
- Console::WriteLine(int::typeid->Assembly->FullName);
-}
-
-/* This example produces output similar to the following:
-
-The FullName property (also called the display name) of...
-...the currently executing assembly:
-ExampleAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
-...the assembly that contains the Int32 type:
-mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- */
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR/Assembly.GetExportedTypes/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR/Assembly.GetExportedTypes/CPP/source.cpp
deleted file mode 100644
index 85c7081e152..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Assembly.GetExportedTypes/CPP/source.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-namespace ExportedClassExample
-{
- public ref class Example sealed
- {
- private:
- Example()
- {
- }
-
- public:
- void static EnumerateExportedTypes()
- {
- for each (Type^ exportedType in
- Example::typeid->Assembly->GetExportedTypes())
- {
- Console::WriteLine(exportedType);
- }
- }
- };
-
- public ref class PublicClass
- {
- public:
- ref class PublicNestedClass
- {
- };
-
- protected:
- ref class ProtectedNestedClass
- {
- };
-
- internal:
- ref class FriendNestedClass
- {
- };
-
- private:
- ref class PrivateNestedClass
- {
- };
- };
-
- ref class FriendClass
- {
- public:
- ref class PublicNestedClass
- {
- };
-
- protected:
- ref class ProtectedNestedClass
- {
- };
-
- internal:
- ref class FriendNestedClass
- {
- };
-
- private:
- ref class PrivateNestedClass
- {
- };
- };
-}
-
-int main()
-{
- ExportedClassExample::Example::EnumerateExportedTypes();
-
- return 0;
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/Assembly.Load1/CPP/load1.cpp b/snippets/cpp/VS_Snippets_CLR/Assembly.Load1/CPP/load1.cpp
deleted file mode 100644
index 8735dfb6dac..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Assembly.Load1/CPP/load1.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Collections;
-using namespace System::Reflection;
-int main()
-{
- // You must supply a valid fully qualified assembly name.
- Assembly^ SampleAssembly = Assembly::Load
- ( "SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3" );
- array^ Types = SampleAssembly->GetTypes();
-
- // Display all the types contained in the specified assembly.
- IEnumerator^ myEnum = Types->GetEnumerator();
- Type^ oType;
- while ( myEnum->MoveNext() )
- {
- oType = safe_cast(myEnum->Current);
- Console::WriteLine( oType->Name );
- }
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder.DefineResource Example 2/CPP/assemblybuilder_defineresource.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder.DefineResource Example 2/CPP/assemblybuilder_defineresource.cpp
deleted file mode 100644
index d5ff911a579..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder.DefineResource Example 2/CPP/assemblybuilder_defineresource.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-
-//
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Resources;
-
-/*
- The following program demonstrates the 'DefineResource' and 'DefineVersionInfoResource'
- methods of 'AssemblyBuilder' class. It builds an assembly and a resource file at runtime.
- The unmanaged version information like product, product version, Company, Copyright,
- trademark are defined with 'DefineVersionInfoResource' method.
-*/
-static Type^ CreateAssembly( AppDomain^ appDomain );
-
-int main()
-{
- AssemblyBuilder^ myAssembly;
- IResourceWriter^ myResourceWriter;
- myAssembly = safe_cast(CreateAssembly( Thread::GetDomain() )->Assembly);
- myResourceWriter = myAssembly->DefineResource( "myResourceFile", "A sample Resource File", "MyEmitAssembly.MyResource.resources" );
- myResourceWriter->AddResource( "AddResource 1", "First added resource" );
- myResourceWriter->AddResource( "AddResource 2", "Second added resource" );
- myResourceWriter->AddResource( "AddResource 3", "Third added resource" );
- myAssembly->DefineVersionInfoResource( "AssemblySample", "2:0:0:1", "Microsoft Corporation", "@Copyright Microsoft Corp. 1990-2001", ".NET is a trademark of Microsoft Corporation" );
- myAssembly->Save( "MyEmitAssembly.dll" );
-}
-
-// Create the callee transient dynamic assembly.
-static Type^ CreateAssembly( AppDomain^ appDomain )
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "MyEmitAssembly";
- AssemblyBuilder^ myAssembly = appDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Save );
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
-
- // Define a public class named "HelloWorld" in the assembly.
- TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
-
- // Define the Display method.
- MethodBuilder^ myMethod = helloWorldClass->DefineMethod( "Display", MethodAttributes::Public, String::typeid, nullptr );
-
- // Generate IL for GetGreeting.
- ILGenerator^ methodIL = myMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldstr, "Display method get called." );
- methodIL->Emit( OpCodes::Ret );
-
- // Returns the type HelloWorld.
- return (helloWorldClass->CreateType());
-}
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/24895.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/24895.cpp
deleted file mode 100644
index 28daac1e840..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/24895.cpp
+++ /dev/null
@@ -1,222 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-void main()
-{
- // This code creates an assembly that contains one type,
- // named "MyDynamicType", that has a private field, a property
- // that gets and sets the private field, constructors that
- // initialize the private field, and a method that multiplies
- // a user-supplied number by the private field value and returns
- // the result. In Visual C++ the type might look like this:
- /*
- public ref class MyDynamicType
- {
- private:
- int m_number;
-
- public:
- MyDynamicType() : m_number(42) {};
- MyDynamicType(int initNumber) : m_number(initNumber) {};
-
- property int Number
- {
- int get() { return m_number; }
- void set(int value) { m_number = value; }
- }
-
- int MyMethod(int multiplier)
- {
- return m_number * multiplier;
- }
- };
- */
-
- AssemblyName^ aName = gcnew AssemblyName("DynamicAssemblyExample");
- AssemblyBuilder^ ab =
- AssemblyBuilder::DefineDynamicAssembly(
- aName,
- AssemblyBuilderAccess::Run);
-
- // The module name is usually the same as the assembly name
- ModuleBuilder^ mb =
- ab->DefineDynamicModule(aName->Name);
-
- TypeBuilder^ tb = mb->DefineType(
- "MyDynamicType",
- TypeAttributes::Public);
-
- // Add a private field of type int (Int32).
- FieldBuilder^ fbNumber = tb->DefineField(
- "m_number",
- int::typeid,
- FieldAttributes::Private);
-
- // Define a constructor that takes an integer argument and
- // stores it in the private field.
- array^ parameterTypes = { int::typeid };
- ConstructorBuilder^ ctor1 = tb->DefineConstructor(
- MethodAttributes::Public,
- CallingConventions::Standard,
- parameterTypes);
-
- ILGenerator^ ctor1IL = ctor1->GetILGenerator();
- // For a constructor, argument zero is a reference to the new
- // instance. Push it on the stack before calling the base
- // class constructor. Specify the default constructor of the
- // base class (System::Object) by passing an empty array of
- // types (Type::EmptyTypes) to GetConstructor.
- ctor1IL->Emit(OpCodes::Ldarg_0);
- ctor1IL->Emit(OpCodes::Call,
- Object::typeid->GetConstructor(Type::EmptyTypes));
- // Push the instance on the stack before pushing the argument
- // that is to be assigned to the private field m_number.
- ctor1IL->Emit(OpCodes::Ldarg_0);
- ctor1IL->Emit(OpCodes::Ldarg_1);
- ctor1IL->Emit(OpCodes::Stfld, fbNumber);
- ctor1IL->Emit(OpCodes::Ret);
-
- // Define a default constructor that supplies a default value
- // for the private field. For parameter types, pass the empty
- // array of types or pass nullptr.
- ConstructorBuilder^ ctor0 = tb->DefineConstructor(
- MethodAttributes::Public,
- CallingConventions::Standard,
- Type::EmptyTypes);
-
- ILGenerator^ ctor0IL = ctor0->GetILGenerator();
- ctor0IL->Emit(OpCodes::Ldarg_0);
- ctor0IL->Emit(OpCodes::Call,
- Object::typeid->GetConstructor(Type::EmptyTypes));
- // For a constructor, argument zero is a reference to the new
- // instance. Push it on the stack before pushing the default
- // value on the stack.
- ctor0IL->Emit(OpCodes::Ldarg_0);
- ctor0IL->Emit(OpCodes::Ldc_I4_S, 42);
- ctor0IL->Emit(OpCodes::Stfld, fbNumber);
- ctor0IL->Emit(OpCodes::Ret);
-
- // Define a property named Number that gets and sets the private
- // field.
- //
- // The last argument of DefineProperty is nullptr, because the
- // property has no parameters. (If you don't specify nullptr, you must
- // specify an array of Type objects. For a parameterless property,
- // use the built-in array with no elements: Type::EmptyTypes)
- PropertyBuilder^ pbNumber = tb->DefineProperty(
- "Number",
- PropertyAttributes::HasDefault,
- int::typeid,
- nullptr);
-
- // The property "set" and property "get" methods require a special
- // set of attributes.
- MethodAttributes getSetAttr = MethodAttributes::Public |
- MethodAttributes::SpecialName | MethodAttributes::HideBySig;
-
- // Define the "get" accessor method for Number. The method returns
- // an integer and has no arguments. (Note that nullptr could be
- // used instead of Types::EmptyTypes)
- MethodBuilder^ mbNumberGetAccessor = tb->DefineMethod(
- "get_Number",
- getSetAttr,
- int::typeid,
- Type::EmptyTypes);
-
- ILGenerator^ numberGetIL = mbNumberGetAccessor->GetILGenerator();
- // For an instance property, argument zero is the instance. Load the
- // instance, then load the private field and return, leaving the
- // field value on the stack.
- numberGetIL->Emit(OpCodes::Ldarg_0);
- numberGetIL->Emit(OpCodes::Ldfld, fbNumber);
- numberGetIL->Emit(OpCodes::Ret);
-
- // Define the "set" accessor method for Number, which has no return
- // type and takes one argument of type int (Int32).
- MethodBuilder^ mbNumberSetAccessor = tb->DefineMethod(
- "set_Number",
- getSetAttr,
- nullptr,
- gcnew array { int::typeid });
-
- ILGenerator^ numberSetIL = mbNumberSetAccessor->GetILGenerator();
- // Load the instance and then the numeric argument, then store the
- // argument in the field.
- numberSetIL->Emit(OpCodes::Ldarg_0);
- numberSetIL->Emit(OpCodes::Ldarg_1);
- numberSetIL->Emit(OpCodes::Stfld, fbNumber);
- numberSetIL->Emit(OpCodes::Ret);
-
- // Last, map the "get" and "set" accessor methods to the
- // PropertyBuilder. The property is now complete.
- pbNumber->SetGetMethod(mbNumberGetAccessor);
- pbNumber->SetSetMethod(mbNumberSetAccessor);
-
- // Define a method that accepts an integer argument and returns
- // the product of that integer and the private field m_number. This
- // time, the array of parameter types is created on the fly.
- MethodBuilder^ meth = tb->DefineMethod(
- "MyMethod",
- MethodAttributes::Public,
- int::typeid,
- gcnew array { int::typeid });
-
- ILGenerator^ methIL = meth->GetILGenerator();
- // To retrieve the private instance field, load the instance it
- // belongs to (argument zero). After loading the field, load the
- // argument one and then multiply. Return from the method with
- // the return value (the product of the two numbers) on the
- // execution stack.
- methIL->Emit(OpCodes::Ldarg_0);
- methIL->Emit(OpCodes::Ldfld, fbNumber);
- methIL->Emit(OpCodes::Ldarg_1);
- methIL->Emit(OpCodes::Mul);
- methIL->Emit(OpCodes::Ret);
-
- // Finish the type->
- Type^ t = tb->CreateType();
-
- // Because AssemblyBuilderAccess includes Run, the code can be
- // executed immediately. Start by getting reflection objects for
- // the method and the property.
- MethodInfo^ mi = t->GetMethod("MyMethod");
- PropertyInfo^ pi = t->GetProperty("Number");
-
- // Create an instance of MyDynamicType using the default
- // constructor.
- Object^ o1 = Activator::CreateInstance(t);
-
- // Display the value of the property, then change it to 127 and
- // display it again. Use nullptr to indicate that the property
- // has no index.
- Console::WriteLine("o1->Number: {0}", pi->GetValue(o1, nullptr));
- pi->SetValue(o1, 127, nullptr);
- Console::WriteLine("o1->Number: {0}", pi->GetValue(o1, nullptr));
-
- // Call MyMethod, passing 22, and display the return value, 22
- // times 127. Arguments must be passed as an array, even when
- // there is only one.
- array
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/AssemblyBuilderClass.vcxproj b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/AssemblyBuilderClass.vcxproj
deleted file mode 100644
index f0b6e04f882..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/AssemblyBuilderClass.vcxproj
+++ /dev/null
@@ -1,147 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 15.0
- {2C2BE6AE-166F-4B41-8A58-5A6088ED4869}
- v4.7.2
- ManagedCProj
- AssemblyBuilderClass
- 10.0.17134.0
-
-
-
- Application
- true
- v141
- true
- Unicode
-
-
- Application
- false
- v141
- true
- Unicode
-
-
- Application
- true
- v141
- true
- Unicode
-
-
- Application
- false
- v141
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
- true
-
-
- false
-
-
- false
-
-
-
- NotUsing
- Level3
- Disabled
- WIN32;_DEBUG;%(PreprocessorDefinitions)
-
-
-
- Console
-
-
-
-
- NotUsing
- Level3
- Disabled
- _DEBUG;%(PreprocessorDefinitions)
-
-
-
- Console
-
-
-
-
- NotUsing
- Level3
- WIN32;NDEBUG;%(PreprocessorDefinitions)
-
-
-
- Console
-
-
-
-
- NotUsing
- Level3
- NDEBUG;%(PreprocessorDefinitions)
-
-
-
- Console
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/snippets.5000.json b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/snippets.5000.json
deleted file mode 100644
index da9ebf8da2f..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilderClass/cpp/snippets.5000.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "host": "visualstudio"
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineUnmanagedResource/CPP/assemblybuilder_defineunmanagedresource.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineUnmanagedResource/CPP/assemblybuilder_defineunmanagedresource.cpp
deleted file mode 100644
index be95d74e2dc..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineUnmanagedResource/CPP/assemblybuilder_defineunmanagedresource.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-
-//
-/*
- The following program demonstrates the 'DefineResource' and 'DefineUnmanagedResource'
- methods of 'AssemblyBuilder' class. It builds an assembly and a resource file at runtime.
- An unmanaged resource file is also defined for the same resource file. The EmittedTest2.cpp file
- calls the methods of "MyEmitAssembly.dll" assembly and the message is displayed to console.
-*/
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Resources;
-
- static AssemblyBuilder^ CreateAssembly( String^ name )
- {
- AssemblyName^ aName = gcnew AssemblyName(name);
- AssemblyBuilder^ myAssembly =
- AppDomain::CurrentDomain->DefineDynamicAssembly( aName,
- AssemblyBuilderAccess::Save );
-
- // Define a dynamic module.
- ModuleBuilder^ myModule =
- myAssembly->DefineDynamicModule( aName->Name, aName->Name + ".dll" );
-
- // Define a public class named "EmitClass" in the assembly.
- TypeBuilder^ myEmitClass =
- myModule->DefineType( "EmitClass", TypeAttributes::Public );
-
- // Define the Display method.
- MethodBuilder^ myMethod =
- myEmitClass->DefineMethod( "Display", MethodAttributes::Public,
- String::typeid, nullptr );
-
- // Generate IL for Display method.
- ILGenerator^ methodIL = myMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldstr, "Display method gets called." );
- methodIL->Emit( OpCodes::Ret );
-
- myEmitClass->CreateType();
-
- return (myAssembly);
- };
-
- //
- //
- void main()
- {
- AssemblyBuilder^ myAssembly = CreateAssembly("MyEmitTestAssembly");
-
- // Defines a standalone managed resource for this assembly.
- IResourceWriter^ myResourceWriter =
- myAssembly->DefineResource( "myResourceFile", "A sample Resource File",
- "MyAssemblyResource.resources", ResourceAttributes::Private );
-
- myResourceWriter->AddResource( "AddResource Test", "Testing for the added resource" );
-
- myAssembly->Save(myAssembly->GetName()->Name + ".dll" );
-
- // Defines an unmanaged resource file for this assembly.
- myAssembly->DefineUnmanagedResource( "MyAssemblyResource.resources" );
- };
-
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineUnmanagedResource2/CPP/assemblybuilder_defineunmanagedresource2.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineUnmanagedResource2/CPP/assemblybuilder_defineunmanagedresource2.cpp
deleted file mode 100644
index 6f099f1d8c4..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineUnmanagedResource2/CPP/assemblybuilder_defineunmanagedresource2.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-
-//
-/*
- The following program demonstrates the 'DefineResource' and 'DefineUnmanagedResource'
- methods of 'AssemblyBuilder' class. It builds an assembly and a resource file at runtime.
- An unmanaged resource file is also defined for the same resource file. The EmittedTest2.cpp file
- calls the methods of "MyEmitAssembly.dll" assembly and the message is displayed to console.
-*/
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Resources;
-
- static AssemblyBuilder^ CreateAssembly( String^ name )
- {
- AssemblyName^ aName = gcnew AssemblyName(name);
- AssemblyBuilder^ myAssembly =
- AppDomain::CurrentDomain->DefineDynamicAssembly( aName,
- AssemblyBuilderAccess::Save );
-
- // Define a dynamic module.
- ModuleBuilder^ myModule =
- myAssembly->DefineDynamicModule( aName->Name, aName->Name + ".dll" );
-
- // Define a public class named "EmitClass" in the assembly.
- TypeBuilder^ myEmitClass =
- myModule->DefineType( "EmitClass", TypeAttributes::Public );
-
- // Define the Display method.
- MethodBuilder^ myMethod =
- myEmitClass->DefineMethod( "Display", MethodAttributes::Public,
- String::typeid, nullptr );
-
- // Generate IL for Display method.
- ILGenerator^ methodIL = myMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldstr, "Display method gets called." );
- methodIL->Emit( OpCodes::Ret );
-
- myEmitClass->CreateType();
-
- return (myAssembly);
- };
-
- //
- //
- void main()
- {
- AssemblyBuilder^ myAssembly = CreateAssembly("MyEmitTestAssembly");
-
- // Defines a standalone managed resource for this assembly.
- IResourceWriter^ myResourceWriter =
- myAssembly->DefineResource( "myResourceFile", "A sample Resource File",
- "MyAssemblyResource.resources", ResourceAttributes::Private );
-
- myResourceWriter->AddResource( "AddResource Test", "Testing for the added resource" );
-
- myAssembly->Save(myAssembly->GetName()->Name + ".dll" );
-
- // Defines an unmanaged resource file for this assembly.
- myAssembly->DefineUnmanagedResource( gcnew array{01, 00, 01} );
- };
-
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineVersionInfoResource/CPP/assemblybuilder_defineversioninforesource.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineVersionInfoResource/CPP/assemblybuilder_defineversioninforesource.cpp
deleted file mode 100644
index 8b17c3f5d4f..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_DefineVersionInfoResource/CPP/assemblybuilder_defineversioninforesource.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-// System::Reflection::Emit::AssemblyBuilder.DefineVersionInfoResource()
-
-// This code example shows how to use the AssemblyBuilder::DefineVersionInfoResource method
-// to add Windows version information to a dynamic assembly. The code example builds an
-// assembly with one module and no types. Several attributes are applied to the assembly,
-// DefineVersionInfoResource is used to create the Windows version information resource,
-// and then the assembly is saved as EmittedAssembly.exe. The Windows Explorer can be used
-// to examine the version information for the assembly.
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-
-/*
-// Create the callee transient dynamic assembly.
-static Type^ CreateAssembly( AppDomain^ myDomain )
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "MyEmittedAssembly";
- AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Save );
-
- // Set Company Attribute to the assembly.
- Type^ companyAttribute = AssemblyCompanyAttribute::typeid;
- array^types1 = {String::typeid};
- ConstructorInfo^ myConstructorInfo1 = companyAttribute->GetConstructor( types1 );
- array^obj1 = {"Microsoft Corporation"};
- CustomAttributeBuilder^ attributeBuilder1 = gcnew CustomAttributeBuilder( myConstructorInfo1,obj1 );
- myAssembly->SetCustomAttribute( attributeBuilder1 );
-
- // Set Copyright Attribute to the assembly.
- Type^ copyrightAttribute = AssemblyCopyrightAttribute::typeid;
- array^types2 = {String::typeid};
- ConstructorInfo^ myConstructorInfo2 = copyrightAttribute->GetConstructor( types2 );
- array^obj2 = {"@Copyright Microsoft Corp. 1990-2001"};
- CustomAttributeBuilder^ attributeBuilder2 = gcnew CustomAttributeBuilder( myConstructorInfo2,obj2 );
- myAssembly->SetCustomAttribute( attributeBuilder2 );
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
-
- // Define a public class named S"HelloWorld" in the assembly.
- TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
-
- // Define the Display method.
- MethodBuilder^ myMethod = helloWorldClass->DefineMethod( "Display", MethodAttributes::Public, String::typeid, nullptr );
-
- // Generate IL for GetGreeting.
- ILGenerator^ methodIL = myMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldstr, "Display method get called." );
- methodIL->Emit( OpCodes::Ret );
-
- // Returns the type HelloWorld.
- return (helloWorldClass->CreateType());
-}
-*/
-
-int main()
-{
- AssemblyName^ assemName = gcnew AssemblyName();
- assemName->Name = "EmittedAssembly";
-
- // Create a dynamic assembly in the current application domain,
- // specifying that the assembly is to be saved.
- //
- AssemblyBuilder^ myAssembly =
- AppDomain::CurrentDomain->DefineDynamicAssembly(assemName,
- AssemblyBuilderAccess::Save);
-
-
- // To apply an attribute to a dynamic assembly, first get the
- // attribute type. The AssemblyFileVersionAttribute sets the
- // File Version field on the Version tab of the Windows file
- // properties dialog.
- //
- Type^ attributeType = AssemblyFileVersionAttribute::typeid;
-
- // To identify the constructor, use an array of types representing
- // the constructor's parameter types. This ctor takes a string.
- //
- array^ ctorParameters = { String::typeid };
-
- // Get the constructor for the attribute.
- //
- ConstructorInfo^ ctor = attributeType->GetConstructor(ctorParameters);
-
- // Pass the constructor and an array of arguments (in this case,
- // an array containing a single string) to the
- // CustomAttributeBuilder constructor.
- //
- array^ ctorArgs = { "2.0.3033.0" };
- CustomAttributeBuilder^ attribute =
- gcnew CustomAttributeBuilder(ctor, ctorArgs);
-
- // Finally, apply the attribute to the assembly.
- //
- myAssembly->SetCustomAttribute(attribute);
-
-
- // The pattern described above is used to create and apply
- // several more attributes. As it happens, all these attributes
- // have a constructor that takes a string, so the same ctorArgs
- // variable works for all of them.
-
-
- // The AssemblyTitleAttribute sets the Description field on
- // the General tab and the Version tab of the Windows file
- // properties dialog.
- //
- attributeType = AssemblyTitleAttribute::typeid;
- ctor = attributeType->GetConstructor(ctorParameters);
- ctorArgs = gcnew array { "The Application Title" };
- attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
- myAssembly->SetCustomAttribute(attribute);
-
- // The AssemblyCopyrightAttribute sets the Copyright field on
- // the Version tab.
- //
- attributeType = AssemblyCopyrightAttribute::typeid;
- ctor = attributeType->GetConstructor(ctorParameters);
- ctorArgs = gcnew array { "� My Example Company 1991-2005" };
- attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
- myAssembly->SetCustomAttribute(attribute);
-
- // The AssemblyDescriptionAttribute sets the Comment item.
- //
- attributeType = AssemblyDescriptionAttribute::typeid;
- ctor = attributeType->GetConstructor(ctorParameters);
- attribute = gcnew CustomAttributeBuilder(ctor,
- gcnew array { "This is a comment." });
- myAssembly->SetCustomAttribute(attribute);
-
- // The AssemblyCompanyAttribute sets the Company item.
- //
- attributeType = AssemblyCompanyAttribute::typeid;
- ctor = attributeType->GetConstructor(ctorParameters);
- attribute = gcnew CustomAttributeBuilder(ctor,
- gcnew array { "My Example Company" });
- myAssembly->SetCustomAttribute(attribute);
-
- // The AssemblyProductAttribute sets the Product Name item.
- //
- attributeType = AssemblyProductAttribute::typeid;
- ctor = attributeType->GetConstructor(ctorParameters);
- attribute = gcnew CustomAttributeBuilder(ctor,
- gcnew array { "My Product Name" });
- myAssembly->SetCustomAttribute(attribute);
-
-
- // Define the assembly's only module. For a single-file assembly,
- // the module name is the assembly name.
- //
- ModuleBuilder^ myModule =
- myAssembly->DefineDynamicModule(assemName->Name,
- assemName->Name + ".exe");
-
- // No types or methods are created for this example.
-
-
- // Define the unmanaged version information resource, which
- // contains the attribute informaion applied earlier, and save
- // the assembly. Use the Windows Explorer to examine the properties
- // of the .exe file.
- //
- myAssembly->DefineVersionInfoResource();
- myAssembly->Save(assemName->Name + ".exe");
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_SetCustomAttribute1/CPP/assemblybuilder_setcustomattribute1.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_SetCustomAttribute1/CPP/assemblybuilder_setcustomattribute1.cpp
deleted file mode 100644
index 668ee141f99..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_SetCustomAttribute1/CPP/assemblybuilder_setcustomattribute1.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-
-// System.Reflection.Emit.SetCustomAttribute(CustomAttributeBuilder)
-/*
-The following program demonstrates the 'SetCustomAttribute(CustomAttributeBuilder)'
-method of 'AssemblyBuilder' class. It defines a 'MyAttribute' class which is derived
-from 'Attribute' class. It builds an assembly by setting 'MyAttribute' custom attribute
-and defines 'HelloWorld' type. Then it gets the custom attributes of 'HelloWorld' type
-and displays its contents to the console.
-*/
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-//
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute: public Attribute
-{
-public:
- String^ s;
- int x;
- MyAttribute( String^ s, int x )
- {
- this->s = s;
- this->x = x;
- }
-};
-
-Type^ CreateCallee( AppDomain^ domain )
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
- AssemblyBuilder^ myAssembly = domain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
- Type^ myType = MyAttribute::typeid;
- array^temp0 = {String::typeid,int::typeid};
- ConstructorInfo^ infoConstructor = myType->GetConstructor( temp0 );
- array^temp1 = {"Hello",2};
- CustomAttributeBuilder^ attributeBuilder = gcnew CustomAttributeBuilder( infoConstructor,temp1 );
- myAssembly->SetCustomAttribute( attributeBuilder );
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Define a public class named "HelloWorld" in the assembly.
- TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
- return (helloWorldClass->CreateType());
-}
-
-int main()
-{
- Type^ customAttribute = CreateCallee( Thread::GetDomain() );
- array^attributes = customAttribute->Assembly->GetCustomAttributes( true );
- Console::WriteLine( "MyAttribute custom attribute contains : " );
- for ( int index = 0; index < attributes->Length; index++ )
- {
- if ( dynamic_cast(attributes[ index ]) )
- {
- Console::WriteLine( "s : {0}", (dynamic_cast(attributes[ index ]))->s );
- Console::WriteLine( "x : {0}", (dynamic_cast(attributes[ index ]))->x );
- break;
- }
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_SetCustomAttribute2/CPP/assemblybuilder_setcustomattribute2.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_SetCustomAttribute2/CPP/assemblybuilder_setcustomattribute2.cpp
deleted file mode 100644
index 008090d756e..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyBuilder_SetCustomAttribute2/CPP/assemblybuilder_setcustomattribute2.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-
-// System.Reflection.Emit.SetCustomAttribute(ConstructorInfo, byte[])
-/*
-The following program demonstrates the 'SetCustomAttribute(ConstructorInfo, byte[])'
-method of 'AssemblyBuilder' class. It defines a 'MyAttribute' class which is derived
-from 'Attribute' class. It builds an assembly by setting 'MyAttribute' custom attribute
-and defines 'HelloWorld' type. Then it gets the custom attributes of 'HelloWorld' type
-and displays its contents to the console.
-*/
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute: public Attribute
-{
-public:
- bool s;
- MyAttribute( bool s )
- {
- this->s = s;
- }
-};
-
-Type^ CreateCallee( AppDomain^ domain )
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
- AssemblyBuilder^ myAssembly = domain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
- Type^ myType = MyAttribute::typeid;
- array^temp0 = {bool::typeid};
- ConstructorInfo^ infoConstructor = myType->GetConstructor( temp0 );
- array^temp1 = {01,00,01};
- myAssembly->SetCustomAttribute( infoConstructor, temp1 );
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Define a public class named "HelloWorld" in the assembly.
- TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
- return (helloWorldClass->CreateType());
-}
-
-int main()
-{
- Type^ customAttribute = CreateCallee( Thread::GetDomain() );
- array^attributes = customAttribute->Assembly->GetCustomAttributes( true );
- Console::WriteLine( "MyAttribute custom attribute contains : " );
- for ( int index = 0; index < attributes->Length; index++ )
- {
- if ( dynamic_cast(attributes[ index ]) )
- {
- Console::WriteLine( "s : {0}", (dynamic_cast(attributes[ index ]))->s );
- break;
- }
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyClass/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyClass/cpp/source.cpp
deleted file mode 100644
index 2384a6c6a11..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyClass/cpp/source.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Security::Permissions;
-
-[assembly:AssemblyVersionAttribute("1.0.2000.0")];
-
-public ref class Example
-{
-private:
- int factor;
-
-public:
- Example(int f)
- {
- factor = f;
- }
-
- int SampleMethod(int x)
- {
- Console::WriteLine("\nExample->SampleMethod({0}) executes.", x);
- return x * factor;
- }
-};
-
-void main()
-{
- Assembly^ assem = Example::typeid->Assembly;
-
- Console::WriteLine("Assembly Full Name:");
- Console::WriteLine(assem->FullName);
-
- // The AssemblyName type can be used to parse the full name.
- AssemblyName^ assemName = assem->GetName();
- Console::WriteLine("\nName: {0}", assemName->Name);
- Console::WriteLine("Version: {0}.{1}",
- assemName->Version->Major, assemName->Version->Minor);
-
- Console::WriteLine("\nAssembly CodeBase:");
- Console::WriteLine(assem->CodeBase);
-
- // Create an object from the assembly, passing in the correct number and
- // type of arguments for the constructor.
- Object^ o = assem->CreateInstance("Example", false,
- BindingFlags::ExactBinding,
- nullptr, gcnew array { 2 }, nullptr, nullptr);
-
- // Make a late-bound call to an instance method of the object.
- MethodInfo^ m = assem->GetType("Example")->GetMethod("SampleMethod");
- Object^ ret = m->Invoke(o, gcnew array { 42 });
- Console::WriteLine("SampleMethod returned {0}.", ret);
-
- Console::WriteLine("\nAssembly entry point:");
- Console::WriteLine(assem->EntryPoint);
-}
-
-/* This code example produces output similar to the following:
-
-Assembly Full Name:
-source, Version=1.0.2000.0, Culture=neutral, PublicKeyToken=null
-
-Name: source
-Version: 1.0
-
-Assembly CodeBase:
-file:///C:/sdtree/AssemblyClass/cpp/source.exe
-
-Example->SampleMethod(42) executes.
-SampleMethod returned 84.
-
-Assembly entry point:
-UInt32 _mainCRTStartup()
- */
-//
-
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyDelaySignAttribute/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyDelaySignAttribute/cpp/source.cpp
deleted file mode 100644
index 9ec81948d79..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyDelaySignAttribute/cpp/source.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// Per Kitg, from cut QuickStart (vswhidbey 160832)
-//
-using namespace System;
-using namespace System::Reflection;
-
-[assembly:AssemblyKeyFileAttribute("TestPublicKey.snk")];
-[assembly:AssemblyDelaySignAttribute(true)];
-
-namespace DelaySign
-{
- public ref class Test { };
-}
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyFlagsAttribute/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyFlagsAttribute/CPP/source.cpp
deleted file mode 100644
index 28ca23085e4..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyFlagsAttribute/CPP/source.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Specify a combination of AssemblyNameFlags for this
-// assembly.
-[assembly:AssemblyFlagsAttribute(
- AssemblyNameFlags::EnableJITcompileOptimizer
- | AssemblyNameFlags::Retargetable)];
-
-public ref class Example
-{
-public:
- static void Main()
- {
- // Get this assembly.
- Assembly^ thisAsm = Example::typeid->Assembly;
-
- // Get the AssemblyName for this assembly.
- AssemblyName^ thisAsmName = thisAsm->GetName( false );
-
- // Display the flags that were set for this assembly.
- ListFlags( thisAsmName->Flags );
-
- // Create an instance of AssemblyFlagsAttribute with the
- // same combination of flags that was specified for this
- // assembly. Note that PublicKey is included automatically
- // for the assembly, but not for this instance of
- // AssemblyFlagsAttribute.
- AssemblyFlagsAttribute^ afa = gcnew AssemblyFlagsAttribute(
- static_cast (AssemblyNameFlags::EnableJITcompileOptimizer
- | AssemblyNameFlags::Retargetable) );
-
- // Get the flags. The property returns an integer, so
- // the return value must be cast to AssemblyNameFlags.
- AssemblyNameFlags anf = static_cast(afa->AssemblyFlags);
-
- // Display the flags.
- Console::WriteLine();
- ListFlags( anf );
- }
-
-private:
- static void ListFlags( AssemblyNameFlags anf )
- {
- if ( anf == AssemblyNameFlags::None )
- {
- Console::WriteLine( L"AssemblyNameFlags.None" );
- }
- else
- {
- if ( 0 != static_cast(anf & AssemblyNameFlags::Retargetable) )
- Console::WriteLine( L"AssemblyNameFlags.Retargetable" );
- if ( 0 != static_cast(anf & AssemblyNameFlags::PublicKey) )
- Console::WriteLine( L"AssemblyNameFlags.PublicKey" );
- if ( 0 != static_cast(anf & AssemblyNameFlags::EnableJITcompileOptimizer) )
- Console::WriteLine( L"AssemblyNameFlags.EnableJITcompileOptimizer" );
- if ( 0 != static_cast(anf & AssemblyNameFlags::EnableJITcompileTracking) )
- Console::WriteLine( L"AssemblyNameFlags.EnableJITcompileTracking" );
- }
- }
-
-};
-
-int main()
-{
- Example::Main();
-}
-
-/* This code example produces the following output:
-
-AssemblyNameFlags.Retargetable
-AssemblyNameFlags.PublicKey
-AssemblyNameFlags.EnableJITcompileOptimizer
-
-AssemblyNameFlags.Retargetable
-AssemblyNameFlags.EnableJITcompileOptimizer
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyName.Version/cpp/Example.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyName.Version/cpp/Example.cpp
deleted file mode 100644
index 7a72383a28c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyName.Version/cpp/Example.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-[assembly:AssemblyVersion("1.1.0.0")];
-
-void main()
-{
- Console::WriteLine("The version of the currently executing assembly is: {0}",
- Assembly::GetExecutingAssembly()->GetName()->Version);
-
- Console::WriteLine("The version of mscorlib.dll is: {0}",
- String::typeid->Assembly->GetName()->Version);
-}
-
-/* This example produces output similar to the following:
-
-The version of the currently executing assembly is: 1.1.0.0
-The version of mscorlib.dll is: 2.0.0.0
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyName_CodeBase/CPP/assemblyname_codebase.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyName_CodeBase/CPP/assemblyname_codebase.cpp
deleted file mode 100644
index 1879b4dc9fd..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyName_CodeBase/CPP/assemblyname_codebase.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-
-// System::Reflection::AssemblyName::CodeBase
-// System::Reflection::AssemblyName::CultureInfo
-// System::Reflection::AssemblyName::HashAlgorithm
-// System::Reflection::AssemblyName::FullName
-/*
- The following example demonstrates the 'CodeBase', 'CultureInfo'
- 'HashAlgorithm' and 'FullName' properties of the 'AssemblyName' class. Creates
- a dynamic assembly named 'MyAssembly' with a module named 'MyModule' and
- a type within the module named 'MyType'. The type 'MyType' has a single
- method called 'Main' which is also the entry point to the assembly. The
- creation of the dynamic assembly is carried out by the method called
- 'MakeAssembly'. After the assembly is created with the help of 'MakeAssembly'
- the assemblies currently loaded are found and the dynamic assembly that we
- have created is searched for, which is displayed to the console. The dynamic
- assembly is also saved to a file named 'MyAssembly.exe'.
-
- Note : Run 'MyAssembly.exe' which this example has created for a simple
- 'Hello World!' display.
-*/
-//
-//
-//
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Threading;
-using namespace System::IO;
-using namespace System::Globalization;
-using namespace System::Reflection::Emit;
-using namespace System::Configuration::Assemblies;
-static void MakeAssembly( AssemblyName^ myAssemblyName, String^ fileName )
-{
- // Get the assembly builder from the application domain associated with the current thread.
- AssemblyBuilder^ myAssemblyBuilder = Thread::GetDomain()->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Create a dynamic module in the assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "MyModule", fileName );
-
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyType" );
-
- // Create a method called 'Main'.
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "Main", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::Static), void::typeid, nullptr );
-
- // Get the Intermediate Language generator for the method.
- ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
-
- // Use the utility method to generate the IL instructions that print a String* to the console.
- myILGenerator->EmitWriteLine( "Hello World!" );
-
- // Generate the 'ret' IL instruction.
- myILGenerator->Emit( OpCodes::Ret );
-
- // End the creation of the type.
- myTypeBuilder->CreateType();
-
- // Set the method with name 'Main' as the entry point in the assembly.
- myAssemblyBuilder->SetEntryPoint( myMethodBuilder );
- myAssemblyBuilder->Save( fileName );
-}
-
-int main()
-{
- // Create a dynamic assembly with name 'MyAssembly' and build version '1.0.0.2001'.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
-
- // Set the codebase to the physical directory were the assembly resides.
- myAssemblyName->CodeBase = Directory::GetCurrentDirectory();
-
- // Set the culture information of the assembly to 'English-American'.
- myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );
-
- // Set the hash algorithm to 'SHA256'.
- myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA256;
- myAssemblyName->Name = "MyAssembly";
- myAssemblyName->Version = gcnew Version( "1.0.0.2001" );
- MakeAssembly( myAssemblyName, "MyAssembly.exe" );
-
- // Get all the assemblies currently loaded in the application domain.
- array^myAssemblies = Thread::GetDomain()->GetAssemblies();
-
- // Get the dynamic assembly named 'MyAssembly'.
- Assembly^ myAssembly = nullptr;
- for ( int i = 0; i < myAssemblies->Length; i++ )
- {
- if ( String::Compare( myAssemblies[ i ]->GetName()->Name, "MyAssembly" ) == 0 )
- myAssembly = myAssemblies[ i ];
- }
- if ( myAssembly != nullptr )
- {
- Console::WriteLine( "\nDisplaying the full assembly name\n" );
- Console::WriteLine( myAssembly->GetName()->FullName );
- }
-}
-//
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyName_Constructor/CPP/assemblyname_constructor.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyName_Constructor/CPP/assemblyname_constructor.cpp
deleted file mode 100644
index 21eae3f4c19..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyName_Constructor/CPP/assemblyname_constructor.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-
-// System::Reflection::AssemblyName::AssemblyName()
-// System::Reflection::AssemblyName::Name
-// System::Reflection::AssemblyName::Version
-/*
- The following example demonstrates the constructor 'AssemblyName()' and
- the 'Name' and 'Version' properties of the 'AssemblyName' class. Creates
- a dynamic assembly named 'MyAssembly' with a module named 'MyModule' and
- a type within the module named 'MyType'. The type 'MyType' has a single
- method called 'Main' which is also the entry point to the assembly. The
- creation of the dynamic assembly is carried out by the method called
- 'MakeAssembly'. After the assembly is created with the help of 'MakeAssembly'
- the assemblies currently loaded are found and the dynamic assembly that we
- have created is searched for, which is displayed to the console. The dynamic
- assembly is also saved to a file named 'MyAssembly.exe'.
-
- Note : Run 'MyAssembly.exe' which this example has created for a simple
- 'Hello World!' display.
-*/
-//
-//
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Threading;
-using namespace System::Reflection::Emit;
-static void MakeAssembly( AssemblyName^ myAssemblyName, String^ fileName )
-{
- // Get the assembly builder from the application domain associated with the current thread.
- AssemblyBuilder^ myAssemblyBuilder = Thread::GetDomain()->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Create a dynamic module in the assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "MyModule", fileName );
-
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyType" );
-
- // Create a method called 'Main'.
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "Main", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::Static), void::typeid, nullptr );
-
- // Get the Intermediate Language generator for the method.
- ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
-
- // Use the utility method to generate the IL instructions that print a String* to the console.
- myILGenerator->EmitWriteLine( "Hello World!" );
-
- // Generate the 'ret' IL instruction.
- myILGenerator->Emit( OpCodes::Ret );
-
- // End the creation of the type.
- myTypeBuilder->CreateType();
-
- // Set the method with name 'Main' as the entry point in the assembly.
- myAssemblyBuilder->SetEntryPoint( myMethodBuilder );
- myAssemblyBuilder->Save( fileName );
-}
-
-int main()
-{
- // Create a dynamic assembly with name 'MyAssembly' and build version '1.0.0.2001'.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "MyAssembly";
- myAssemblyName->Version = gcnew Version( "1.0.0.2001" );
- MakeAssembly( myAssemblyName, "MyAssembly.exe" );
-
- // Get all the assemblies currently loaded in the application domain.
- array^myAssemblies = Thread::GetDomain()->GetAssemblies();
-
- // Get the dynamic assembly named 'MyAssembly'.
- Assembly^ myAssembly = nullptr;
- for ( int i = 0; i < myAssemblies->Length; i++ )
- {
- if ( String::Compare( myAssemblies[ i ]->GetName()->Name, "MyAssembly" ) == 0 )
- myAssembly = myAssemblies[ i ];
- }
- if ( myAssembly != nullptr )
- {
- Console::WriteLine( "\nDisplaying the assembly name\n" );
- Console::WriteLine( myAssembly );
- }
-}
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyName_Constructor_2/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyName_Constructor_2/CPP/source.cpp
deleted file mode 100644
index 7bd4f7d79f0..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyName_Constructor_2/CPP/source.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Simplified snippet per SuzCook tech review.
-//
-using namespace System;
-using namespace System::Reflection;
-
-int main()
-{
- // Create an AssemblyName, specifying the display name, and then
- // print the properties.
- AssemblyName^ myAssemblyName =
- gcnew AssemblyName("Example, Version=1.0.0.2001, Culture=en-US, PublicKeyToken=null");
- Console::WriteLine("Name: {0}", myAssemblyName->Name);
- Console::WriteLine("Version: {0}", myAssemblyName->Version);
- Console::WriteLine("CultureInfo: {0}", myAssemblyName->CultureInfo);
- Console::WriteLine("FullName: {0}", myAssemblyName->FullName);
-}
-/* This code example produces output similar to the following:
-
-Name: Example
-Version: 1.0.0.2001
-CultureInfo: en-US
-FullName: Example, Version=1.0.0.2001, Culture=en-US, PublicKeyToken=null
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyName_GetAssemblyName/CPP/assemblyname_getassemblyname.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyName_GetAssemblyName/CPP/assemblyname_getassemblyname.cpp
deleted file mode 100644
index 2f372084604..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyName_GetAssemblyName/CPP/assemblyname_getassemblyname.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-// System::Reflection::AssemblyName::GetAssemblyName(String*)
-// System::Reflection::AssemblyName
-/*
- This example demonstrates the 'GetAssemblyName(String*)' and 'ToString()'
- methods of the 'AssemblyName' class. Get the path of 'System.dll' from
- the path of 'mscorlib.dll'. Get the assembly information from 'System.dll'
- and display the information to the console.
- */
-//
-//
-#using
-
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
-
- // Replace the string "MyAssembly.exe" with the name of an assembly,
- // including a path if necessary. If you do not have another assembly
- // to use, you can use whatever name you give to this assembly.
- //
- AssemblyName^ myAssemblyName = AssemblyName::GetAssemblyName( "MyAssembly.exe" );
- Console::WriteLine( "\nDisplaying assembly information:\n" );
- Console::WriteLine( myAssemblyName );
-}
-
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyName_KeyPair/CPP/assemblyname_keypair.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyName_KeyPair/CPP/assemblyname_keypair.cpp
deleted file mode 100644
index ce82c90bc54..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyName_KeyPair/CPP/assemblyname_keypair.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-
-// System::Reflection::AssemblyName::KeyPair
-// System::Reflection::AssemblyName::GetPublicKey()
-// System::Reflection::AssemblyName::GetPublicKeyToken()
-// System::Reflection::AssemblyName::Flags
-// System::Reflection::AssemblyName::VersionCompatibility
-/*
- The following example demonstrates the 'GetPublicKey()' and
- 'GetPublicKeyToken()' methods and the 'KeyPair', 'Flags' and 'VersionCompatibility'
- properties of the 'AssemblyName' class. Creates a dynamic assembly named 'MyAssembly'
- with a module named 'MyModule' and a type within the module named 'MyType'.
- The type 'MyType' has a single method called 'Main' which is also the entry
- point to the assembly. The creation of the dynamic assembly is carried out
- by the method called 'MakeAssembly'. After the assembly is created with the
- help of 'MakeAssembly' the assemblies currently loaded are found and the
- dynamic assembly that we have created is searched for, which is displayed
- to the console. Moreover the public key and the public key token are displayed
- The dynamic assembly is also saved to a file named 'MyAssembly.exe'. The
- dynamic assembly that has been created has a strong name containing a private
- and a public key which is generated by a tool named 'Sn.exe'. The key pair
- is stored in a file named 'KeyPair.snk'.
-
- Note : Run 'MyAssembly.exe' which this example has created for a simple
- 'Hello World!' display.
-*/
-//
-//
-//
-//
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Threading;
-using namespace System::IO;
-using namespace System::Globalization;
-using namespace System::Reflection::Emit;
-using namespace System::Configuration::Assemblies;
-using namespace System::Text;
-static void MakeAssembly( AssemblyName^ myAssemblyName, String^ fileName )
-{
- // Get the assembly builder from the application domain associated with the current thread.
- AssemblyBuilder^ myAssemblyBuilder = Thread::GetDomain()->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Create a dynamic module in the assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "MyModule", fileName );
-
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyType" );
-
- // Create a method called 'Main'.
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "Main", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::Static), void::typeid, nullptr );
-
- // Get the Intermediate Language generator for the method.
- ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
-
- // Use the utility method to generate the IL instructions that print a String* to the console.
- myILGenerator->EmitWriteLine( "Hello World!" );
-
- // Generate the 'ret' IL instruction.
- myILGenerator->Emit( OpCodes::Ret );
-
- // End the creation of the type.
- myTypeBuilder->CreateType();
-
- // Set the method with name 'Main' as the entry point in the assembly.
- myAssemblyBuilder->SetEntryPoint( myMethodBuilder );
- myAssemblyBuilder->Save( fileName );
-}
-
-int main()
-{
- // Create a dynamic assembly with name 'MyAssembly' and build version '1.0.0.2001'.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
-
- // Set the codebase to the physical directory were the assembly resides.
- myAssemblyName->CodeBase = Directory::GetCurrentDirectory();
-
- // Set the culture information of the assembly to 'English-American'.
- myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );
-
- // Set the hash algorithm to 'SHA256'.
- myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA256;
- myAssemblyName->VersionCompatibility = AssemblyVersionCompatibility::SameProcess;
- myAssemblyName->Flags = AssemblyNameFlags::PublicKey;
-
- // Provide this assembly with a strong name.
- myAssemblyName->KeyPair = gcnew StrongNameKeyPair( File::Open( "KeyPair.snk", FileMode::Open, FileAccess::Read ) );
- myAssemblyName->Name = "MyAssembly";
- myAssemblyName->Version = gcnew Version( "1.0.0.2001" );
- MakeAssembly( myAssemblyName, "MyAssembly.exe" );
-
- // Get the assemblies loaded in the current application domain.
- array^myAssemblies = Thread::GetDomain()->GetAssemblies();
-
- // Get the dynamic assembly named 'MyAssembly'.
- Assembly^ myAssembly = nullptr;
- for ( int i = 0; i < myAssemblies->Length; i++ )
- if ( String::Compare( myAssemblies[ i ]->GetName()->Name, "MyAssembly" ) == 0 )
- myAssembly = myAssemblies[ i ];
-
- // Display the full assembly information to the console.
- if ( myAssembly != nullptr )
- {
- Console::WriteLine( "\nDisplaying the full assembly name.\n" );
- Console::WriteLine( myAssembly->GetName()->FullName );
- Console::WriteLine( "\nDisplaying the public key.\n" );
- array^pk;
- pk = myAssembly->GetName()->GetPublicKey();
- for ( int i = 0; i < pk->GetLength( 0 ); i++ )
- Console::Write( " {0:x2}", pk[ i ] );
- Console::WriteLine();
- Console::WriteLine( "\nDisplaying the public key token.\n" );
- array^pt;
- pt = myAssembly->GetName()->GetPublicKeyToken();
- for ( int i = 0; i < pt->GetLength( 0 ); i++ )
- Console::Write( " {0:x2}", pt[ i ] );
- }
-}
-//
-//
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/AssemblyName_SetPublicKey/CPP/assemblyname_setpublickey.cpp b/snippets/cpp/VS_Snippets_CLR/AssemblyName_SetPublicKey/CPP/assemblyname_setpublickey.cpp
deleted file mode 100644
index 105e762cd75..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/AssemblyName_SetPublicKey/CPP/assemblyname_setpublickey.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-
-// System::Reflection::AssemblyName::SetPublicKey(Byte->Item[])
-// System::Reflection::AssemblyName::SetPublicKeyToken(Byte->Item[])
-/*
- The following example demonstrates the 'SetPublicKey(Byte->Item[])' and the
- 'SetPublicKeyToken(Byte->Item[])' methods of the 'AssemblyName' class. Creates
- a dynamic assembly named 'MyAssembly' with a module named 'MyModule' and
- a type within the module named 'MyType'. The type 'MyType' has a single
- method called 'Main' which is also the entry point to the assembly. The
- creation of the dynamic assembly is carried out by the method called
- 'MakeAssembly'. After the assembly is created with the help of 'MakeAssembly'
- the assemblies currently loaded are found and the dynamic assembly that we
- have created is searched for, which is displayed to the console. The dynamic
- assembly is also saved to a file named 'MyAssembly.exe'. The assembly is
- provided with a strong name. This is done by getting the public key and
- the public key token from the 'KeyPair.snk' (private and public key file).
- The public key is stored in 'PublicKey.snk' and the public key token is
- stored in 'PublicKeyToken.snk' with the help of the tool named 'sn.exe'.
-
- Note : Running 'MyAssembly.exe' with this example does not display 'Hello World!'
- since this assembly has been stongly signed.
-*/
-
-//
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Threading;
-using namespace System::IO;
-using namespace System::Globalization;
-using namespace System::Reflection::Emit;
-using namespace System::Configuration::Assemblies;
-using namespace System::Text;
-
-static void MakeAssembly( AssemblyName^ myAssemblyName, String^ fileName )
-{
- // Get the assembly builder from the application domain associated with the current thread.
- AssemblyBuilder^ myAssemblyBuilder = Thread::GetDomain()->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Create a dynamic module in the assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "MyModule", fileName );
-
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyType" );
-
- // Create a method called 'Main'.
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "Main", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::Static), void::typeid, nullptr );
-
- // Get the Intermediate Language generator for the method.
- ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
-
- // Use the utility method to generate the IL instructions that print a String* to the console.
- myILGenerator->EmitWriteLine( "Hello World!" );
-
- // Generate the 'ret' IL instruction.
- myILGenerator->Emit( OpCodes::Ret );
-
- // End the creation of the type.
- myTypeBuilder->CreateType();
-
- // Set the method with name 'Main' as the entry point in the assembly.
- myAssemblyBuilder->SetEntryPoint( myMethodBuilder );
- myAssemblyBuilder->Save( fileName );
-}
-
-int main()
-{
- // Create a dynamic assembly with name 'MyAssembly' and build version '1.0.0.2001'.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
-
- // Set the codebase to the physical directory were the assembly resides.
- myAssemblyName->CodeBase = Directory::GetCurrentDirectory();
-
- // Set the culture information of the assembly to 'English-American'.
- myAssemblyName->CultureInfo = gcnew CultureInfo( "en-US" );
-
- // Set the hash algorithm to 'SHA256'.
- myAssemblyName->HashAlgorithm = AssemblyHashAlgorithm::SHA256;
- myAssemblyName->VersionCompatibility = AssemblyVersionCompatibility::SameProcess;
- myAssemblyName->Flags = AssemblyNameFlags::PublicKey;
-
- // Get the whole contents of the 'PublicKey.snk' into a Byte array.
- FileStream^ publicKeyStream = File::Open( "PublicKey.snk", FileMode::Open );
- array^publicKey = gcnew array(publicKeyStream->Length);
- publicKeyStream->Read( publicKey, 0, (int)publicKeyStream->Length );
-
- // Provide the assembly with a public key.
- myAssemblyName->SetPublicKey( publicKey );
-
- // Get the whole contents of the 'PublicKeyToken.snk' into a Byte array.
- FileStream^ publicKeyTokenStream = File::Open( "PublicKeyToken.snk", FileMode::Open );
- array^publicKeyToken = gcnew array(publicKeyTokenStream->Length);
- publicKeyTokenStream->Read( publicKeyToken, 0, (int)publicKeyToken->Length );
-
- // Provide the assembly with a public key token.
- myAssemblyName->SetPublicKeyToken( publicKeyToken );
- myAssemblyName->Name = "MyAssembly";
- myAssemblyName->Version = gcnew Version( "1.0.0.2001" );
- MakeAssembly( myAssemblyName, "MyAssembly.exe" );
-
- // Get the assemblies loaded in the current application domain.
- array^myAssemblies = Thread::GetDomain()->GetAssemblies();
-
- // Get the dynamic assembly named 'MyAssembly'.
- Assembly^ myAssembly = nullptr;
- for ( int i = 0; i < myAssemblies->Length; i++ )
- if ( String::Compare( myAssemblies[ i ]->GetName()->Name, "MyAssembly" ) == 0 )
- myAssembly = myAssemblies[ i ];
-
- // Display the full assembly information to the console.
- if ( myAssembly != nullptr )
- {
- Console::WriteLine( "\nDisplaying the full assembly name\n" );
- String^ assemblyName = myAssembly->GetName()->FullName;
- Console::WriteLine( assemblyName );
- Console::WriteLine( "\nDisplaying the public key for the assembly\n" );
- array^publicKeyBytes = myAssembly->GetName()->GetPublicKey();
- Console::WriteLine( Encoding::ASCII->GetString( publicKeyBytes ) );
- Console::WriteLine( "\nDisplaying the public key token for the assembly\n" );
- array^publicKeyTokenBytes = myAssembly->GetName()->GetPublicKeyToken();
- Console::WriteLine( Encoding::ASCII->GetString( publicKeyTokenBytes ) );
- }
-}
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/Binder_1/CPP/binder.cpp b/snippets/cpp/VS_Snippets_CLR/Binder_1/CPP/binder.cpp
deleted file mode 100644
index 382e0b264dd..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Binder_1/CPP/binder.cpp
+++ /dev/null
@@ -1,449 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Globalization;
-using namespace System::Runtime::InteropServices;
-public ref class MyBinder: public Binder
-{
-public:
- MyBinder()
- : Binder()
- {}
-
-private:
- ref class BinderState
- {
- public:
- array^args;
- };
-
-public:
- virtual FieldInfo^ BindToField( BindingFlags bindingAttr, array^match, Object^ value, CultureInfo^ culture ) override
- {
- if ( match == nullptr )
- throw gcnew ArgumentNullException( "match" );
-
- // Get a field for which the value parameter can be converted to the specified field type.
- for ( int i = 0; i < match->Length; i++ )
- if ( ChangeType( value, match[ i ]->FieldType, culture ) != nullptr )
- return match[ i ];
-
- return nullptr;
- }
-
- virtual MethodBase^ BindToMethod( BindingFlags bindingAttr, array^match, array^%args, array^ modifiers, CultureInfo^ culture, array^names, [Out]Object^% state ) override
- {
- // Store the arguments to the method in a state Object*.
- BinderState^ myBinderState = gcnew BinderState;
- array^arguments = gcnew array(args->Length);
- args->CopyTo( arguments, 0 );
- myBinderState->args = arguments;
- state = myBinderState;
- if ( match == nullptr )
- throw gcnew ArgumentNullException;
-
- // Find a method that has the same parameters as those of the args parameter.
- for ( int i = 0; i < match->Length; i++ )
- {
- // Count the number of parameters that match.
- int count = 0;
- array^parameters = match[ i ]->GetParameters();
-
- // Go on to the next method if the number of parameters do not match.
- if ( args->Length != parameters->Length )
- continue;
-
- // Match each of the parameters that the user expects the method to have.
- for ( int j = 0; j < args->Length; j++ )
- {
- // If the names parameter is not 0, then reorder args.
- if ( names != nullptr )
- {
- if ( names->Length != args->Length )
- throw gcnew ArgumentException( "names and args must have the same number of elements." );
-
- for ( int k = 0; k < names->Length; k++ )
- if ( String::Compare( parameters[ j ]->Name, names[ k ] ) == 0 )
- args[ j ] = myBinderState->args[ k ];
- }
-
- // Determine whether the types specified by the user can be converted to the parameter type.
- if ( ChangeType( args[ j ], parameters[ j ]->ParameterType, culture ) != nullptr )
- count += 1;
- else
- break;
- }
- if ( count == args->Length )
- return match[ i ];
- }
- return nullptr;
- }
-
- virtual Object^ ChangeType( Object^ value, Type^ myChangeType, CultureInfo^ culture ) override
- {
- // Determine whether the value parameter can be converted to a value of type myType.
- if ( CanConvertFrom( value->GetType(), myChangeType ) )
- // Return the converted Object*.
- return Convert::ChangeType( value, myChangeType );
- else
- return nullptr;
- }
-
- virtual void ReorderArgumentArray( array^%args, Object^ state ) override
- {
- // Return the args that had been reordered by BindToMethod.
- (safe_cast(state))->args->CopyTo( args, 0 );
- }
-
- virtual MethodBase^ SelectMethod( BindingFlags bindingAttr, array^match, array^types, array^ modifiers ) override
- {
- if ( match == nullptr )
- throw gcnew ArgumentNullException( "match" );
-
- for ( int i = 0; i < match->Length; i++ )
- {
- // Count the number of parameters that match.
- int count = 0;
- array^parameters = match[ i ]->GetParameters();
-
- // Go on to the next method if the number of parameters do not match.
- if ( types->Length != parameters->Length )
- continue;
-
- // Match each of the parameters that the user expects the method to have.
- for ( int j = 0; j < types->Length; j++ )
- {
- // Determine whether the types specified by the user can be converted to parameter type.
- if ( CanConvertFrom( types[ j ], parameters[ j ]->ParameterType ) )
- count += 1;
- else
- break;
- }
- // Determine whether the method has been found.
- if ( count == types->Length )
- return match[ i ];
- }
- return nullptr;
- }
-
- virtual PropertyInfo^ SelectProperty( BindingFlags bindingAttr, array^match, Type^ returnType, array^indexes, array^ modifiers ) override
- {
- if ( match == nullptr )
- throw gcnew ArgumentNullException( "match" );
-
- for ( int i = 0; i < match->Length; i++ )
- {
- // Count the number of indexes that match.
- int count = 0;
- array^parameters = match[ i ]->GetIndexParameters();
-
- // Go on to the next property if the number of indexes do not match.
- if ( indexes->Length != parameters->Length )
- continue;
-
- // Match each of the indexes that the user expects the property to have.
- for ( int j = 0; j < indexes->Length; j++ )
- // Determine whether the types specified by the user can be converted to index type.
- if ( CanConvertFrom( indexes[ j ], parameters[ j ]->ParameterType ) )
- count += 1;
- else
- break;
-
- // Determine whether the property has been found.
- if ( count == indexes->Length )
- {
- // Determine whether the return type can be converted to the properties type.
- if ( CanConvertFrom( returnType, match[ i ]->PropertyType ) )
- return match[ i ];
- else
- continue;
- }
- }
- return nullptr;
- }
-
-private:
-
- // Determines whether type1 can be converted to type2. Check only for primitive types.
- bool CanConvertFrom( Type^ type1, Type^ type2 )
- {
- if ( type1->IsPrimitive && type2->IsPrimitive )
- {
- TypeCode typeCode1 = Type::GetTypeCode( type1 );
- TypeCode typeCode2 = Type::GetTypeCode( type2 );
-
- // If both type1 and type2 have the same type, return true.
- if ( typeCode1 == typeCode2 )
- return true;
-
- // Possible conversions from Char follow.
- if ( typeCode1 == TypeCode::Char )
- {
- switch ( typeCode2 )
- {
- case TypeCode::UInt16:
- return true;
-
- case TypeCode::UInt32:
- return true;
-
- case TypeCode::Int32:
- return true;
-
- case TypeCode::UInt64:
- return true;
-
- case TypeCode::Int64:
- return true;
-
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from Byte follow.
- if ( typeCode1 == TypeCode::Byte )
- {
- switch ( typeCode2 )
- {
- case TypeCode::Char:
- return true;
-
- case TypeCode::UInt16:
- return true;
-
- case TypeCode::Int16:
- return true;
-
- case TypeCode::UInt32:
- return true;
-
- case TypeCode::Int32:
- return true;
-
- case TypeCode::UInt64:
- return true;
-
- case TypeCode::Int64:
- return true;
-
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from SByte follow.
- if ( typeCode1 == TypeCode::SByte )
- {
- switch ( typeCode2 )
- {
- case TypeCode::Int16:
- return true;
-
- case TypeCode::Int32:
- return true;
-
- case TypeCode::Int64:
- return true;
-
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from UInt16 follow.
- if ( typeCode1 == TypeCode::UInt16 )
- {
- switch ( typeCode2 )
- {
- case TypeCode::UInt32:
- return true;
-
- case TypeCode::Int32:
- return true;
-
- case TypeCode::UInt64:
- return true;
-
- case TypeCode::Int64:
- return true;
-
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from Int16 follow.
- if ( typeCode1 == TypeCode::Int16 )
- {
- switch ( typeCode2 )
- {
- case TypeCode::Int32:
- return true;
-
- case TypeCode::Int64:
- return true;
-
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from UInt32 follow.
- if ( typeCode1 == TypeCode::UInt32 )
- {
- switch ( typeCode2 )
- {
- case TypeCode::UInt64:
- return true;
-
- case TypeCode::Int64:
- return true;
-
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from Int32 follow.
- if ( typeCode1 == TypeCode::Int32 )
- {
- switch ( typeCode2 )
- {
- case TypeCode::Int64:
- return true;
-
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from UInt64 follow.
- if ( typeCode1 == TypeCode::UInt64 )
- {
- switch ( typeCode2 )
- {
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from Int64 follow.
- if ( typeCode1 == TypeCode::Int64 )
- {
- switch ( typeCode2 )
- {
- case TypeCode::Single:
- return true;
-
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
-
- // Possible conversions from Single follow.
- if ( typeCode1 == TypeCode::Single )
- {
- switch ( typeCode2 )
- {
- case TypeCode::Double:
- return true;
-
- default:
- return false;
- }
- }
- }
-
- return false;
- }
-
-};
-
-public ref class MyClass1
-{
-public:
- short myFieldB;
- int myFieldA;
- void MyMethod( long i, char k )
- {
- Console::WriteLine( "\nThis is MyMethod(long i, char k)" );
- }
-
- void MyMethod( long i, long j )
- {
- Console::WriteLine( "\nThis is MyMethod(long i, long j)" );
- }
-};
-
-int main()
-{
- // Get the type of MyClass1.
- Type^ myType = MyClass1::typeid;
-
- // Get the instance of MyClass1.
- MyClass1^ myInstance = gcnew MyClass1;
- Console::WriteLine( "\nDisplaying the results of using the MyBinder binder.\n" );
-
- // Get the method information for MyMethod.
- array^types = {short::typeid,short::typeid};
- MethodInfo^ myMethod = myType->GetMethod( "MyMethod", static_cast(BindingFlags::Public | BindingFlags::Instance), gcnew MyBinder, types, nullptr );
- Console::WriteLine( myMethod );
-
- // Invoke MyMethod.
- array^obj = {32,32};
- myMethod->Invoke( myInstance, BindingFlags::InvokeMethod, gcnew MyBinder, obj, CultureInfo::CurrentCulture );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/BindingFlags/CPP/bindingflagssample.cpp b/snippets/cpp/VS_Snippets_CLR/BindingFlags/CPP/bindingflagssample.cpp
deleted file mode 100644
index 9657b10660c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/BindingFlags/CPP/bindingflagssample.cpp
+++ /dev/null
@@ -1,365 +0,0 @@
-//
-using namespace System;
-using namespace System::Collections;
-using namespace System::Reflection;
-using namespace System::IO;
-
-//namespace BindingFlagsSnippet {
-public ref class TestClass
-{
-public:
- String^ Name;
-
-private:
- array^ values;
- int methodCalled;
-
-public:
-
- property Object^ Item [int]
- {
- Object^ get( int index )
- {
- return values[ index ];
- }
-
- void set( int index, Object^ value )
- {
- values[ index ] = value;
- }
- }
-
- property Object^ Value
- {
- Object^ get()
- {
- return "the value";
- }
- }
-
- TestClass()
- {
- Name = "initialName";
- values = gcnew array {(int^)0,1,2,3,4,5,6,7,8,9};
- methodCalled = 0;
- }
-
- TestClass(String^ initName)
- {
- Name = initName;
- values = gcnew array {(int^)0,1,2,3,4,5,6,7,8,9};
- methodCalled = 0;
- }
-
- static void SayHello()
- {
- Console::WriteLine( "Hello" );
- }
-
- void AddUp()
- {
- methodCalled++;
- Console::WriteLine( "AddUp Called {0} times", methodCalled );
- }
-
- static double ComputeSum( double d1, double d2 )
- {
- return d1 + d2;
- }
-
- static void PrintName( String^ firstName, String^ lastName )
- {
- Console::WriteLine( "{0},{1}", lastName, firstName );
- }
-
- void PrintTime()
- {
- Console::WriteLine( DateTime::Now );
- }
-
- void Swap( interior_ptr a, interior_ptr b )
- {
- int x = *a;
- *a = *b;
- *b = x;
- }
-};
-
-
-[DefaultMemberAttribute("PrintTime")]
-public ref class TestClass2
-{
-public:
- void PrintTime()
- {
- Console::WriteLine( DateTime::Now );
- }
-
-};
-
-public ref class Base
-{
-private:
- static int BaseOnlyPrivate = 0;
-protected:
- static int BaseOnly = 0;
-};
-
-public ref class Derived : Base
-{
-public:
- static int DerivedOnly = 0;
-};
-
-public ref class MostDerived : Derived {};
-
-void main()
-{
- array^ noArguments;
-
- // BindingFlags::InvokeMethod
- // Call a static method.
- Type^ t = TestClass::typeid;
- Console::WriteLine();
- Console::WriteLine( "Invoking a static method." );
- Console::WriteLine( "-------------------------" );
- t->InvokeMember( "SayHello", BindingFlags::InvokeMethod | BindingFlags::Public | BindingFlags::Static,
- nullptr, nullptr, noArguments );
-
- // BindingFlags::InvokeMethod
- // Call an instance method.
- TestClass^ c = gcnew TestClass;
- Console::WriteLine();
- Console::WriteLine( "Invoking an instance method." );
- Console::WriteLine( "----------------------------" );
- c->GetType()->InvokeMember( "AddUp", BindingFlags::InvokeMethod, nullptr, c, noArguments );
- c->GetType()->InvokeMember( "AddUp", BindingFlags::InvokeMethod, nullptr, c, noArguments );
-
- // BindingFlags::InvokeMethod
- // Call a method with parameters.
- array^args = {100.09,184.45};
- Object^ result;
- Console::WriteLine();
- Console::WriteLine( "Invoking a method with parameters." );
- Console::WriteLine( "---------------------------------" );
- result = t->InvokeMember( "ComputeSum", BindingFlags::InvokeMethod, nullptr, nullptr, args );
- Console::WriteLine( " {0} + {1} = {2}", args[ 0 ], args[ 1 ], result );
-
- // BindingFlags::GetField, SetField
- Console::WriteLine();
- Console::WriteLine( "Invoking a field (getting and setting.)" );
- Console::WriteLine( "--------------------------------------" );
-
- // Get a field value.
- result = t->InvokeMember( "Name", BindingFlags::GetField, nullptr, c, noArguments );
- Console::WriteLine( "Name == {0}", result );
-
- // Set a field.
- array^obj2 = {"NewName"};
- t->InvokeMember( "Name", BindingFlags::SetField, nullptr, c, obj2 );
- result = t->InvokeMember( "Name", BindingFlags::GetField, nullptr, c, noArguments );
- Console::WriteLine( "Name == {0}", result );
- Console::WriteLine();
- Console::WriteLine( "Invoking an indexed property (getting and setting.)" );
- Console::WriteLine( "--------------------------------------------------" );
-
- // BindingFlags::GetProperty
- // Get an indexed property value.
- int index = 3;
- array^obj3 = {index};
- result = t->InvokeMember( "Item", BindingFlags::GetProperty, nullptr, c, obj3 );
- Console::WriteLine( "Item->Item[ {0}] == {1}", index, result );
-
- // BindingFlags::SetProperty
- // Set an indexed property value.
- index = 3;
- array^obj4 = {index,"NewValue"};
- t->InvokeMember( "Item", BindingFlags::SetProperty, nullptr, c, obj4 );
- result = t->InvokeMember( "Item", BindingFlags::GetProperty, nullptr, c, obj3 );
- Console::WriteLine( "Item->Item[ {0}] == {1}", index, result );
- Console::WriteLine();
- Console::WriteLine( "Getting a field or property." );
- Console::WriteLine( "----------------------------" );
-
- // BindingFlags::GetField
- // Get a field or property.
- result = t->InvokeMember( "Name", static_cast(BindingFlags::GetField |
- BindingFlags::GetProperty), nullptr, c, noArguments );
- Console::WriteLine( "Name == {0}", result );
-
- // BindingFlags::GetProperty
- result = t->InvokeMember( "Value", static_cast(BindingFlags::GetField |
- BindingFlags::GetProperty), nullptr, c, noArguments );
- Console::WriteLine( "Value == {0}", result );
- Console::WriteLine();
- Console::WriteLine( "Invoking a method with named parameters." );
- Console::WriteLine( "---------------------------------------" );
-
- // BindingFlags::InvokeMethod
- // Call a method using named parameters.
- array^argValues = {"Mouse","Micky"};
- array^argNames = {"lastName","firstName"};
- t->InvokeMember( "PrintName", BindingFlags::InvokeMethod, nullptr, nullptr, argValues, nullptr,
- nullptr, argNames );
- Console::WriteLine();
- Console::WriteLine( "Invoking a default member of a type." );
- Console::WriteLine( "------------------------------------" );
-
- // BindingFlags::Default
- // Call the default member of a type.
- Type^ t3 = TestClass2::typeid;
- t3->InvokeMember( "", static_cast(BindingFlags::InvokeMethod | BindingFlags::Default),
- nullptr, gcnew TestClass2, noArguments );
-
- // BindingFlags::Static, NonPublic, and Public
- // Invoking a member with ref parameters.
- Console::WriteLine();
- Console::WriteLine( "Invoking a method with ref parameters." );
- Console::WriteLine( "--------------------------------------" );
- MethodInfo^ m = t->GetMethod( "Swap" );
- args = gcnew array(2);
- args[ 0 ] = 1;
- args[ 1 ] = 2;
- m->Invoke( gcnew TestClass, args );
- Console::WriteLine( "{0}, {1}", args[ 0 ], args[ 1 ] );
-
- // BindingFlags::CreateInstance
- // Creating an instance with a parameterless constructor.
- Console::WriteLine();
- Console::WriteLine( "Creating an instance with a parameterless constructor." );
- Console::WriteLine( "------------------------------------------------------" );
- Object^ obj = t->InvokeMember( "TestClass", static_cast(BindingFlags::Public |
- BindingFlags::Instance | BindingFlags::CreateInstance), nullptr, nullptr, noArguments );
- Console::WriteLine("Instance of {0} created.", obj->GetType()->Name);
-
- // Creating an instance with a constructor that has parameters.
- Console::WriteLine();
- Console::WriteLine( "Creating an instance with a constructor that has parameters." );
- Console::WriteLine( "------------------------------------------------------------" );
- obj = t->InvokeMember( "TestClass", static_cast(BindingFlags::Public |
- BindingFlags::Instance | BindingFlags::CreateInstance), nullptr, nullptr,
- gcnew array { "Hello, World!" } );
- Console::WriteLine("Instance of {0} created with initial value '{1}'.", obj->GetType()->Name,
- obj->GetType()->InvokeMember("Name", BindingFlags::GetField, nullptr, obj, noArguments));
-
- // BindingFlags::DeclaredOnly
- Console::WriteLine();
- Console::WriteLine( "DeclaredOnly instance members." );
- Console::WriteLine( "------------------------------" );
- array^memInfo = t->GetMembers( BindingFlags::DeclaredOnly |
- BindingFlags::Instance | BindingFlags::Public);
- for ( int i = 0; i < memInfo->Length; i++ )
- {
- Console::WriteLine( memInfo[ i ]->Name );
-
- }
-
- // BindingFlags::IgnoreCase
- Console::WriteLine();
- Console::WriteLine( "Using IgnoreCase and invoking the PrintName method." );
- Console::WriteLine( "---------------------------------------------------" );
- t->InvokeMember( "printname", static_cast(BindingFlags::IgnoreCase |
- BindingFlags::Static | BindingFlags::Public | BindingFlags::InvokeMethod),
- nullptr, nullptr, gcnew array {"Brad","Smith"});
-
- // BindingFlags::FlattenHierarchy
- Console::WriteLine();
- Console::WriteLine( "Using FlattenHierarchy to get inherited static protected and public members." );
- Console::WriteLine( "----------------------------------------------------------------------------" );
- array^ finfos = MostDerived::typeid->GetFields(BindingFlags::NonPublic |
- BindingFlags::Public | BindingFlags::Static | BindingFlags::FlattenHierarchy);
- for each (FieldInfo^ finfo in finfos)
- {
- Console::WriteLine("{0} defined in {1}.", finfo->Name, finfo->DeclaringType->Name);
- }
-
- Console::WriteLine();
- Console::WriteLine("Without FlattenHierarchy." );
- Console::WriteLine("-------------------------");
- finfos = MostDerived::typeid->GetFields(BindingFlags::NonPublic | BindingFlags::Public |
- BindingFlags::Static);
- for each (FieldInfo^ finfo in finfos)
- {
- Console::WriteLine("{0} defined in {1}.", finfo->Name, finfo->DeclaringType->Name);
- }
-};
-
-/* This example produces output similar to the following:
-
-Invoking a static method.
--------------------------
-Hello
-
-Invoking an instance method.
-----------------------------
-AddUp Called 1 times
-AddUp Called 2 times
-
-Invoking a method with parameters.
----------------------------------
- 100.09 + 184.45 = 284.54
-
-Invoking a field (getting and setting.)
---------------------------------------
-Name == initialName
-Name == NewName
-
-Invoking an indexed property (getting and setting.)
---------------------------------------------------
-Item->Item[ 3] == 3
-Item->Item[ 3] == NewValue
-
-Getting a field or property.
-----------------------------
-Name == NewName
-Value == the value
-
-Invoking a method with named parameters.
----------------------------------------
-Mouse,Micky
-
-Invoking a default member of a type.
-------------------------------------
-12/23/2009 4:19:06 PM
-
-Invoking a method with ref parameters.
---------------------------------------
-2, 1
-
-Creating an instance with a parameterless constructor.
-------------------------------------------------------
-Instance of TestClass created.
-
-Creating an instance with a constructor that has parameters.
-------------------------------------------------------------
-Instance of TestClass created with initial value 'Hello, World!'.
-
-DeclaredOnly instance members.
-------------------------------
-get_Item
-set_Item
-get_Value
-AddUp
-PrintTime
-Swap
-.ctor
-.ctor
-Value
-Item
-Name
-methodCalled
-
-Using IgnoreCase and invoking the PrintName method.
----------------------------------------------------
-Smith,Brad
-
-Using FlattenHierarchy to get inherited static protected and public members.
-----------------------------------------------------------------------------
-DerivedOnly defined in Derived.
-BaseOnly defined in Base.
-
-Without FlattenHierarchy.
--------------------------
-
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_Attributes_4/CPP/constructorbuilder_attributes_4.cpp b/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_Attributes_4/CPP/constructorbuilder_attributes_4.cpp
deleted file mode 100644
index da26b213429..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_Attributes_4/CPP/constructorbuilder_attributes_4.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-// System.Reflection.Emit.ConstructorBuilder.AddDeclarativeSecurity()
-// System.Reflection.Emit.ConstructorBuilder.Attributes
-// System.Reflection.Emit.ConstructorBuilder.DeclaringType
-// System.Reflection.Emit.ConstructorBuilder.DefineParameter()
-
-/* The following program demonstrates the 'AddDeclarativeSecurity',
-'DefineParameter' methods, and 'Attributes', 'DeclaringType' properties
-of the ConstructorBuilder class. Create the assembly in the current domain
-with dynamic module in the assembly. Constructor builder is used in
-conjunction with the 'TypeBuilder' class to create constructor at run time.
-Add declarative security to the constructor. Display the 'Attributes',
-'DeclaringType' and 'DefineParameter'.
-*/
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Security::Permissions;
-using namespace System::Security;
-
-public ref class MyConstructorBuilder
-{
-private:
- Type^ myType1;
- ModuleBuilder^ myModuleBuilder;
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- MyConstructorBuilder()
- {
- myModuleBuilder = nullptr;
- myAssemblyBuilder = nullptr;
-
-//
-//
-//
- MethodBuilder^ myMethodBuilder = nullptr;
-
- AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
- // Create assembly in current CurrentDomain
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
- // Create a dynamic assembly
- myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly(
- myAssemblyName, AssemblyBuilderAccess::RunAndSave );
- // Create a dynamic module in the assembly.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
- FieldInfo^ myFieldInfo =
- myModuleBuilder->DefineUninitializedData( "myField", 2, FieldAttributes::Public );
- // Create a type in the module
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
- FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting",
- String::typeid, FieldAttributes::Public );
- array^myConstructorArgs = {String::typeid};
- // Define a constructor of the dynamic class.
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor(
- MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
- PermissionSet^ myPset = gcnew PermissionSet( PermissionState::Unrestricted );
- // Add declarative security to the constructor.
- Console::WriteLine( "Adding declarative security to the constructor....." );
- Console::WriteLine( "The Security action to be taken is \"DENY\" and" +
- " Permission set is \"UNRESTRICTED\"." );
- myConstructor->AddDeclarativeSecurity( SecurityAction::Deny, myPset );
-//
- MethodAttributes myMethodAttributes = myConstructor->Attributes;
- Type^ myAttributeType = MethodAttributes::typeid;
- int myAttribValue = (int)myMethodAttributes;
- if ( !myAttributeType->IsEnum )
- {
- Console::WriteLine( "This is not an Enum" );
- }
- array^myFieldInfo1 = myAttributeType->GetFields( static_cast(BindingFlags::Public | BindingFlags::Static) );
- Console::WriteLine( "The Field info names of the Attributes for the constructor are:" );
- for ( int i = 0; i < myFieldInfo1->Length; i++ )
- {
- int myFieldValue = *dynamic_cast(myFieldInfo1[ i ]->GetValue( nullptr ));
- if ( (myFieldValue & myAttribValue) == myFieldValue )
- {
- Console::WriteLine( " {0}", myFieldInfo1[ i ]->Name );
- }
- }
-
- Type^ myType2 = myConstructor->DeclaringType;
- Console::WriteLine( "The declaring type is : {0}", myType2 );
-//
- ParameterBuilder^ myParameterBuilder1 =
- myConstructor->DefineParameter( 1, ParameterAttributes::Out, "My Parameter Name1" );
- Console::WriteLine( "The name of the parameter is : {0}",
- myParameterBuilder1->Name );
- if ( myParameterBuilder1->IsIn )
- Console::WriteLine( "{0} is Input parameter.", myParameterBuilder1->Name );
- else
- Console::WriteLine( "{0} is not Input Parameter.", myParameterBuilder1->Name );
- ParameterBuilder^ myParameterBuilder2 =
- myConstructor->DefineParameter( 1, ParameterAttributes::In, "My Parameter Name2" );
- Console::WriteLine( "The Parameter name is : {0}",
- myParameterBuilder2->Name );
- if ( myParameterBuilder2->IsIn )
- Console::WriteLine( "{0} is Input parameter.", myParameterBuilder2->Name );
- else
- Console::WriteLine( "{0} is not Input Parameter.", myParameterBuilder2->Name );
-//
- // Generate MSIL for the method, call its base class constructor and store the arguments
- // in the private field.
- ILGenerator^ myILGenerator3 = myConstructor->GetILGenerator();
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- ConstructorInfo^ myConstructorInfo = Object::typeid->GetConstructor( gcnew array(0) );
- myILGenerator3->Emit( OpCodes::Call, myConstructorInfo );
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- myILGenerator3->Emit( OpCodes::Ldarg_1 );
- myILGenerator3->Emit( OpCodes::Stfld, myGreetingField );
- myILGenerator3->Emit( OpCodes::Ret );
- // Add a method to the type.
- myMethodBuilder = myTypeBuilder->DefineMethod(
- "HelloWorld", MethodAttributes::Public, nullptr, nullptr );
- // Generate MSIL for the method.
- ILGenerator^ myILGenerator2 = myMethodBuilder->GetILGenerator();
- myILGenerator2->EmitWriteLine( "Hello World from global" );
- myILGenerator2->Emit( OpCodes::Ret );
- myModuleBuilder->CreateGlobalFunctions();
- myType1 = myTypeBuilder->CreateType();
- }
- property Type^ MyTypeProperty
- {
- Type^ get()
- {
- return this->myType1;
- }
- }
-};
-int main()
-{
- MyConstructorBuilder^ myConstructorBuilder = gcnew MyConstructorBuilder;
- Type^ myType1 = myConstructorBuilder->MyTypeProperty;
- if ( nullptr != myType1 )
- {
- Console::WriteLine( "Instantiating the new type..." );
- array^myObject = {"hello"};
- Object^ myObject1 = Activator::CreateInstance( myType1, myObject, nullptr );
- MethodInfo^ myMethodInfo = myType1->GetMethod( "HelloWorld" );
- if ( nullptr != myMethodInfo )
- {
- Console::WriteLine( "Invoking dynamically created HelloWorld method..." );
- myMethodInfo->Invoke( myObject1, nullptr );
- }
- else
- {
- Console::WriteLine( "Could not locate HelloWorld method" );
- }
- }
- else
- {
- Console::WriteLine( "Could not access Type." );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_GetModule_4/CPP/constructorbuilder_getmodule_4.cpp b/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_GetModule_4/CPP/constructorbuilder_getmodule_4.cpp
deleted file mode 100644
index 6bc0d5da26e..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_GetModule_4/CPP/constructorbuilder_getmodule_4.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-// System.Reflection.Emit.ConstructorBuilder.GetModule()
-// System.Reflection.Emit.ConstructorBuilder.GetToken()
-// System.Reflection.Emit.ConstructorBuilder.GetMethodImplementationFlags()
-// System.Reflection.Emit.ConstructorBuilder.GetParameters()
-
-/* The following program demonstrates the 'GetModule','GetToken',
-'GetMethodImplementationFlags' and 'GetParameters'
-methods of 'ConstructorBuilder' class. Create the assembly
-in the current domain with dynamic module in the assembly. Constructor
-builder is used in conjunction with the 'TypeBuilder' class to create
-constructor at run time. Set a custom attribute using a custom attribute
-builder and displays module name, Token id and parameter info of this class.
-*/
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-
-public ref class MyConstructorBuilder
-{
-private:
- Type^ myType1;
- ModuleBuilder^ myModuleBuilder;
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- MyConstructorBuilder()
- {
- myModuleBuilder = nullptr;
- myAssemblyBuilder = nullptr;
-//
-//
-
- MethodBuilder^ myMethodBuilder = nullptr;
- AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
- // Create assembly in current CurrentDomain.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
- // Create a dynamic assembly.
- myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
- // Create a dynamic module in the assembly.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
- FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting",
- String::typeid, FieldAttributes::Public );
- array^myConstructorArgs = {String::typeid};
-//
-//
- // Define a constructor of the dynamic class.
- ConstructorBuilder^ myConstructorBuilder = myTypeBuilder->DefineConstructor(
- MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
- // Get a reference to the module that contains this constructor.
- Module^ myModule = myConstructorBuilder->GetModule();
- Console::WriteLine( "Module Name : {0}", myModule->Name );
- // Get the 'MethodToken' that represents the token for this constructor.
- MethodToken myMethodToken = myConstructorBuilder->GetToken();
- Console::WriteLine( "Constructor Token is : {0}", myMethodToken.Token );
- // Get the method implementation flags for this constructor.
- MethodImplAttributes myMethodImplAttributes = myConstructorBuilder->GetMethodImplementationFlags();
- Console::WriteLine( "MethodImplAttributes : {0}", myMethodImplAttributes );
-//
-//
-//
- // Generate IL for the method, call its base class constructor and store the arguments
- // in the private field.
- ILGenerator^ myILGenerator3 = myConstructorBuilder->GetILGenerator();
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- ConstructorInfo^ myConstructorInfo = Object::typeid->GetConstructor( gcnew array(0) );
- myILGenerator3->Emit( OpCodes::Call, myConstructorInfo );
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- myILGenerator3->Emit( OpCodes::Ldarg_1 );
- myILGenerator3->Emit( OpCodes::Stfld, myGreetingField );
- myILGenerator3->Emit( OpCodes::Ret );
- // Add a method to the type.
- myMethodBuilder = myTypeBuilder->DefineMethod(
- "HelloWorld", MethodAttributes::Public, nullptr, nullptr );
- // Generate IL for the method.
- ILGenerator^ myILGenerator2 = myMethodBuilder->GetILGenerator();
- myILGenerator2->EmitWriteLine( "Hello World from global" );
- myILGenerator2->Emit( OpCodes::Ret );
- myModuleBuilder->CreateGlobalFunctions();
- myType1 = myTypeBuilder->CreateType();
-
- // Get the parameters of this constructor.
- array^myParameterInfo = myConstructorBuilder->GetParameters();
- for ( int i = 0; i < myParameterInfo->Length; i++ )
- {
- Console::WriteLine( "Declaration type : {0}", myParameterInfo[ i ]->Member->DeclaringType );
- }
-//
- }
- property Type^ MyTypeProperty
- {
- Type^ get()
- {
- return this->myType1;
- }
- }
-};
-
-int main()
-{
- MyConstructorBuilder^ myConstructorBuilder1 = gcnew MyConstructorBuilder;
- Type^ myTypeProperty = myConstructorBuilder1->MyTypeProperty;
- if ( nullptr != myTypeProperty )
- {
- array^myObject = {"Hello"};
- Object^ myObject1 = Activator::CreateInstance( myTypeProperty, myObject, (Object^) 0 );
- MethodInfo^ myMethodInfo = myTypeProperty->GetMethod( "HelloWorld" );
-
- if ( nullptr != myMethodInfo )
- {
- myMethodInfo->Invoke( myObject1, nullptr );
- }
- else
- {
- Console::WriteLine( "Could not locate HelloWorld method" );
- }
- }
- else
- {
- Console::WriteLine( "Could not access Type." );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_Name_5/CPP/constructorbuilder_name_5.cpp b/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_Name_5/CPP/constructorbuilder_name_5.cpp
deleted file mode 100644
index 90448fc379b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_Name_5/CPP/constructorbuilder_name_5.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-
-// System.Reflection.Emit.ConstructorBuilder
-// System.Reflection.Emit.ConstructorBuilder.Name
-// System.Reflection.Emit.ConstructorBuilder.ReflectedType
-// System.Reflection.Emit.ConstructorBuilder.Signature
-// System.Reflection.Emit.ConstructorBuilder.ToString()
-/* The following program demonstrates the 'ConstructorBuilder' class,
-its 'Name', 'ReflectedType', 'Signature' properties and 'ToString'
-method. Create the assembly in the current domain with dynamic module
-in the assembly. ConstructorBuilder is used in conjunction with the
-'TypeBuilder' class to create constructor at run time. Display the
-'Name', 'Signature' and 'ReflectedType' to the console.
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-public ref class MyConstructorBuilder
-{
-private:
- Type^ myType1;
- ModuleBuilder^ myModuleBuilder;
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- MyConstructorBuilder()
- {
- myModuleBuilder = nullptr;
- myAssemblyBuilder = nullptr;
-
- //
- MethodBuilder^ myMethodBuilder = nullptr;
- AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
-
- // Create assembly in current CurrentDomain.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Create a dynamic assembly.
- myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module in the assembly.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
- FieldInfo^ myFieldInfo = myModuleBuilder->DefineUninitializedData( "myField", 2, FieldAttributes::Public );
-
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
- FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting", String::typeid, FieldAttributes::Public );
- array^myConstructorArgs = {String::typeid};
-
- // Define a constructor of the dynamic class.
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
-
- // Display the name of the constructor.
- Console::WriteLine( "The constructor name is : {0}", myConstructor->Name );
-
- // Display the 'Type' object from which this object was obtained.
- Console::WriteLine( "The reflected type is : {0}", myConstructor->ReflectedType );
-
- // Display the signature of the field.
- Console::WriteLine( myConstructor->Signature );
-
- // Display the constructor builder instance as a string.
- Console::WriteLine( myConstructor );
- //
-
- // Generate IL for the method, call its superclass constructor and store the arguments
- // in the private field.
- ILGenerator^ myILGenerator3 = myConstructor->GetILGenerator();
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- ConstructorInfo^ myConstructorInfo = Object::typeid->GetConstructor( gcnew array(0) );
- myILGenerator3->Emit( OpCodes::Call, myConstructorInfo );
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- myILGenerator3->Emit( OpCodes::Ldarg_1 );
- myILGenerator3->Emit( OpCodes::Stfld, myGreetingField );
- myILGenerator3->Emit( OpCodes::Ret );
-
- // Add a method to the type.
- myMethodBuilder = myTypeBuilder->DefineMethod( "HelloWorld", MethodAttributes::Public, nullptr, nullptr );
-
- // Generate IL for the method.
- ILGenerator^ myILGenerator2 = myMethodBuilder->GetILGenerator();
- myILGenerator2->EmitWriteLine( "Hello World from global" );
- myILGenerator2->Emit( OpCodes::Ret );
- myModuleBuilder->CreateGlobalFunctions();
- myType1 = myTypeBuilder->CreateType();
- }
-
- property Type^ MyTypeProperty
- {
- Type^ get()
- {
- return this->myType1;
- }
- }
-};
-
-int main()
-{
- MyConstructorBuilder^ myConstructorBuilder = gcnew MyConstructorBuilder;
- Type^ myType1 = myConstructorBuilder->MyTypeProperty;
- if ( nullptr != myType1 )
- {
- Console::WriteLine( "Instantiating the new type..." );
- array^myObject = {"hello"};
- Object^ myObject1 = Activator::CreateInstance( myType1, myObject, nullptr );
- MethodInfo^ myMethodInfo = myType1->GetMethod( "HelloWorld" );
- if ( nullptr != myMethodInfo )
- {
- Console::WriteLine( "Invoking dynamically created HelloWorld method..." );
- myMethodInfo->Invoke( myObject1, nullptr );
- }
- else
- {
- Console::WriteLine( "Could not locate HelloWorld method" );
- }
- }
- else
- {
- Console::WriteLine( "Could not access Type." );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetCustomAttribute1/CPP/constructorbuilder_setcustomattribute1.cpp b/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetCustomAttribute1/CPP/constructorbuilder_setcustomattribute1.cpp
deleted file mode 100644
index df97697cd2e..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetCustomAttribute1/CPP/constructorbuilder_setcustomattribute1.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-
-// System::Reflection::Emit::ConstructorBuilder.SetCustomAttribute(CustomAttributeBuilder)
-/*
- The following program demonstrates the 'SetCustomAttribute(CustomAttributeBuilder)'
- method of 'ConstructorBuilder' class. It defines a 'MyAttribute' class which is derived
- from 'Attribute' class. It builds a constructor by setting 'MyAttribute' custom attribute
- and defines 'Helloworld' type. Then it gets the custom attributes of 'HelloWorld' type
- and displays its contents to the console.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute: public Attribute
-{
-public:
- String^ myString;
- int myInteger;
- MyAttribute( String^ myString, int myInteger )
- {
- this->myString = myString;
- this->myInteger = myInteger;
- }
-
-};
-
-static Type^ MyCreateCallee( AppDomain^ domain )
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Define a dynamic assembly in the current application domain->
- AssemblyBuilder^ myAssembly = domain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Define a dynamic module in this assembly->
- ModuleBuilder^ myModuleBuilder = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Construct a 'TypeBuilder' given the name and attributes.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "HelloWorld", TypeAttributes::Public );
-
- // Define a constructor of the dynamic class.
- array^type1 = {String::typeid};
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, type1 );
- ILGenerator^ myILGenerator = myConstructor->GetILGenerator();
- myILGenerator->Emit( OpCodes::Ldstr, "Constructor is invoked" );
- myILGenerator->Emit( OpCodes::Ldarg_1 );
- array^type2 = {String::typeid};
- MethodInfo^ myMethodInfo = Console::typeid->GetMethod( "WriteLine", type2 );
- myILGenerator->Emit( OpCodes::Call, myMethodInfo );
- myILGenerator->Emit( OpCodes::Ret );
- Type^ myType = MyAttribute::typeid;
- array^type3 = {String::typeid,int::typeid};
- ConstructorInfo^ myConstructorInfo = myType->GetConstructor( type3 );
- array^obj1 = {"Hello",2};
- CustomAttributeBuilder^ attributeBuilder = gcnew CustomAttributeBuilder( myConstructorInfo,obj1 );
- try
- {
- myConstructor->SetCustomAttribute( attributeBuilder );
- }
- catch ( ArgumentNullException^ ex )
- {
- Console::WriteLine( "The following exception has occurred : {0}", ex->Message );
- }
- catch ( Exception^ ex )
- {
- Console::WriteLine( "The following exception has occurred : {0}", ex->Message );
- }
-
- return myTypeBuilder->CreateType();
-}
-
-int main()
-{
- Type^ myHelloworld = MyCreateCallee( Thread::GetDomain() );
- array^type1 = {String::typeid};
- ConstructorInfo^ myConstructor = myHelloworld->GetConstructor( type1 );
- array^myAttributes1 = myConstructor->GetCustomAttributes( true );
- Console::WriteLine( "MyAttribute custom attribute contains " );
- for ( int index = 0; index < myAttributes1->Length; index++ )
- {
- if ( dynamic_cast(myAttributes1[ index ]) )
- {
- Console::WriteLine( "The value of myString is : {0}", (safe_cast(myAttributes1[ index ]))->myString );
- Console::WriteLine( "The value of myInteger is : {0}", (safe_cast(myAttributes1[ index ]))->myInteger );
- }
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetCustomAttribute2/CPP/constructorbuilder_setcustomattribute2.cpp b/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetCustomAttribute2/CPP/constructorbuilder_setcustomattribute2.cpp
deleted file mode 100644
index 7c6ae9bf4cb..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetCustomAttribute2/CPP/constructorbuilder_setcustomattribute2.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-
-// System::Reflection::Emit::ConstructorBuilder.SetCustomAttribute(ConstructorInfo, Byte->Item[])
-/*
- The following program demonstrates the 'SetCustomAttribute(ConstructorInfo, Byte[])'
- method of 'ConstructorBuilder' class. It defines a 'MyAttribute' class which is derived
- from 'Attribute' class. It builds a constructor by setting 'MyAttribute' custom attribute
- and defines 'Helloworld' type. Then it gets the custom attributes of 'HelloWorld' type
- and displays its contents to the console.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute: public Attribute
-{
-public:
- bool myBoolean;
- MyAttribute( bool myBoolean )
- {
- this->myBoolean = myBoolean;
- }
-};
-
-static Type^ MyCreateCallee( AppDomain^ domain )
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Define a dynamic assembly in the current application domain.
- AssemblyBuilder^ myAssembly = domain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Define a dynamic module in this assembly.
- ModuleBuilder^ myModuleBuilder = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Construct a 'TypeBuilder' given the name and attributes.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "HelloWorld", TypeAttributes::Public );
-
- // Define a constructor of the dynamic class.
- array^type1 = {String::typeid};
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, type1 );
- ILGenerator^ myILGenerator = myConstructor->GetILGenerator();
- myILGenerator->Emit( OpCodes::Ldstr, "Constructor is invoked" );
- myILGenerator->Emit( OpCodes::Ldarg_1 );
- array^type2 = {String::typeid};
- MethodInfo^ myMethodInfo = Console::typeid->GetMethod( "WriteLine", type2 );
- myILGenerator->Emit( OpCodes::Call, myMethodInfo );
- myILGenerator->Emit( OpCodes::Ret );
- Type^ myType = MyAttribute::typeid;
- array^type3 = {bool::typeid};
- ConstructorInfo^ myConstructorInfo = myType->GetConstructor( type3 );
- try
- {
- array^bytes = {01,00,01};
- myConstructor->SetCustomAttribute( myConstructorInfo, bytes );
- }
- catch ( ArgumentNullException^ ex )
- {
- Console::WriteLine( "The following exception has occurred : {0}", ex->Message );
- }
- catch ( Exception^ ex )
- {
- Console::WriteLine( "The following exception has occurred : {0}", ex->Message );
- }
-
- return myTypeBuilder->CreateType();
-}
-
-int main()
-{
- Type^ myHelloworld = MyCreateCallee( Thread::GetDomain() );
- array^type1 = {String::typeid};
- ConstructorInfo^ myConstructor = myHelloworld->GetConstructor( type1 );
- array^myAttributes1 = myConstructor->GetCustomAttributes( true );
- Console::WriteLine( "MyAttribute custom attribute contains " );
- for ( int index = 0; index < myAttributes1->Length; index++ )
- {
- if ( dynamic_cast(myAttributes1[ index ]) )
- {
- Console::WriteLine( "myBoolean : {0}", safe_cast(myAttributes1[ index ])->myBoolean );
- }
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetImplementationFlags/CPP/constructorbuilder_setimplementationflags.cpp b/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetImplementationFlags/CPP/constructorbuilder_setimplementationflags.cpp
deleted file mode 100644
index 9ff254e4a6c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetImplementationFlags/CPP/constructorbuilder_setimplementationflags.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-
-// System::Reflection::Emit::ConstructorBuilder.SetImplementationFlags()
-/* The following program demonstrates the 'SetImplementationFlags'
- method of ConstructorBuilder class. It creates an assembly in the
- current domain with a dynamic module in the assembly. Constructor
- builder is used in conjunction with the 'TypeBuilder' class to create
- constructor at run time. It then sets the method implementation flags
- for the constructor and displays the same.
-*/
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-public ref class MyConstructorBuilder
-{
-private:
- Type^ myType1;
- ModuleBuilder^ myModuleBuilder;
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- MyConstructorBuilder()
- {
- myModuleBuilder = nullptr;
- myAssemblyBuilder = nullptr;
- try
- {
- //
- MethodBuilder^ myMethodBuilder = nullptr;
- AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
-
- // Create assembly in current CurrentDomain.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Create a dynamic assembly.
- myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module in the assembly.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule", true );
- FieldInfo^ myFieldInfo2 = myModuleBuilder->DefineUninitializedData( "myField", 2, FieldAttributes::Public );
-
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
- FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting", String::typeid, FieldAttributes::Public );
- array^myConstructorArgs = {String::typeid};
-
- // Define a constructor of the dynamic class.
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
-
- // Set the method implementation flags for the constructor.
- myConstructor->SetImplementationFlags( static_cast(MethodImplAttributes::PreserveSig | MethodImplAttributes::Runtime) );
-
- // Get the method implementation flags for the constructor.
- MethodImplAttributes myMethodAttributes = myConstructor->GetMethodImplementationFlags();
- Type^ myAttributeType = MethodImplAttributes::typeid;
- int myAttribValue = (int)myMethodAttributes;
- if ( !myAttributeType->IsEnum )
- {
- Console::WriteLine( "This is not an Enum" );
- }
-
- // Display the field info names of the retrieved method implementation flags.
- array^myFieldInfo = myAttributeType->GetFields( static_cast(BindingFlags::Public | BindingFlags::Static) );
- Console::WriteLine( "The Field info names of the MethodImplAttributes for the constructor are:" );
- for ( int i = 0; i < myFieldInfo->Length; i++ )
- {
- int myFieldValue = *safe_cast(myFieldInfo[ i ]->GetValue( nullptr ));
- if ( (myFieldValue & myAttribValue) == myFieldValue )
- {
- Console::WriteLine( " {0}", myFieldInfo[ i ]->Name );
- }
- }
- //
-
- // Add a method to the type.
- myMethodBuilder = myTypeBuilder->DefineMethod( "HelloWorld", MethodAttributes::Public, nullptr, nullptr );
-
- // Generate IL for the method.
- ILGenerator^ myILGenerator2 = myMethodBuilder->GetILGenerator();
- myILGenerator2->EmitWriteLine( "Hello World from global" );
- myILGenerator2->Emit( OpCodes::Ret );
- myModuleBuilder->CreateGlobalFunctions();
- myType1 = myTypeBuilder->CreateType();
- }
- catch ( InvalidOperationException^ ex )
- {
- Console::WriteLine( "The following exception has occurred : {0}", ex->Message );
- }
- catch ( Exception^ ex )
- {
- Console::WriteLine( "The following exception has occurred : {0}", ex->Message );
- }
- }
-
- property Type^ MyTypeProperty
- {
- Type^ get()
- {
- return this->myType1;
- }
- }
-};
-
-void main()
-{
- MyConstructorBuilder^ myConstructorBuilder = gcnew MyConstructorBuilder;
- Type^ myType1 = myConstructorBuilder->MyTypeProperty;
- if ( nullptr != myType1 )
- {
- Console::WriteLine( "Instantiating the new type..." );
- array^myObject = {"hello"};
- Object^ myObject1 = Activator::CreateInstance( myType1, myObject, nullptr );
- MethodInfo^ myMethodInfo = myType1->GetMethod( "HelloWorld" );
- if ( nullptr != myMethodInfo )
- {
- Console::WriteLine( "Invoking dynamically created HelloWorld method..." );
- myMethodInfo->Invoke( myObject1, nullptr );
- }
- else
- {
- Console::WriteLine( "Could not locate HelloWorld method" );
- }
- }
- else
- {
- Console::WriteLine( "Could not access Type." );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetSymCustomAttribute/CPP/constructorbuilder_setsymcustomattribute.cpp b/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetSymCustomAttribute/CPP/constructorbuilder_setsymcustomattribute.cpp
deleted file mode 100644
index 16aca594b6f..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ConstructorBuilder_SetSymCustomAttribute/CPP/constructorbuilder_setsymcustomattribute.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-// System.Reflection.Emit.ConstructorBuilder.SetSymCustomAttribute()
-
-/* The following program demonstrates the 'SetSymCustomAttribute' method
-of ConstructorBuilder class. It creates an assembly in the current
-domain with dynamic module in the assembly. Constructor builder is
-used in conjunction with the 'TypeBuilder' class to create constructor
-at run time. It then sets this constructor's custom attribute associated
-with symbolic information.
-*/
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class MyConstructorBuilder
-{
-private:
- Type^ myType1;
- ModuleBuilder^ myModuleBuilder;
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- MyConstructorBuilder()
- {
- myModuleBuilder = nullptr;
- myAssemblyBuilder = nullptr;
-
-//
- MethodBuilder^ myMethodBuilder = nullptr;
- AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
- // Create assembly in current CurrentDomain.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
- // Create a dynamic assembly.
- myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly(
- myAssemblyName, AssemblyBuilderAccess::Run );
- // Create a dynamic module in the assembly.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule", true );
- FieldInfo^ myFieldInfo =
- myModuleBuilder->DefineUninitializedData( "myField", 2, FieldAttributes::Public );
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
- FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting",
- String::typeid, FieldAttributes::Public );
- array^ myConstructorArgs = {String::typeid};
- // Define a constructor of the dynamic class.
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
- // Display the name of the constructor.
- Console::WriteLine( "The constructor name is : {0}", myConstructor->Name );
- array^ temp0 = {01,00,00};
- myConstructor->SetSymCustomAttribute( "MySimAttribute", temp0 );
-//
- // Generate the IL for the method and call its superclass constructor.
- ILGenerator^ myILGenerator3 = myConstructor->GetILGenerator();
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- ConstructorInfo^ myConstructorInfo = Object::typeid->GetConstructor( gcnew array(0) );
- myILGenerator3->Emit( OpCodes::Call, myConstructorInfo );
- myILGenerator3->Emit( OpCodes::Ldarg_0 );
- myILGenerator3->Emit( OpCodes::Ldarg_1 );
- myILGenerator3->Emit( OpCodes::Stfld, myGreetingField );
- myILGenerator3->Emit( OpCodes::Ret );
- // Add a method to the type.
- myMethodBuilder = myTypeBuilder->DefineMethod(
- "HelloWorld", MethodAttributes::Public, nullptr, nullptr );
- // Generate IL for the method.
- ILGenerator^ myILGenerator2 = myMethodBuilder->GetILGenerator();
- myILGenerator2->EmitWriteLine( "Hello World from global" );
- myILGenerator2->Emit( OpCodes::Ret );
- myModuleBuilder->CreateGlobalFunctions();
- myType1 = myTypeBuilder->CreateType();
- }
-
- property Type^ MyTypeProperty
- {
- Type^ get()
- {
- return this->myType1;
- }
- }
-};
-
-int main()
-{
- MyConstructorBuilder^ myConstructorBuilder = gcnew MyConstructorBuilder;
- Type^ myType1 = myConstructorBuilder->MyTypeProperty;
- if ( nullptr != myType1 )
- {
- Console::WriteLine( "Instantiating the new type..." );
- array^ myObject = {"hello"};
- Object^ myObject1 = Activator::CreateInstance( myType1, myObject, nullptr );
- MethodInfo^ myMethodInfo = myType1->GetMethod( "HelloWorld" );
- if ( nullptr != myMethodInfo )
- {
- Console::WriteLine( "Invoking dynamically created HelloWorld method..." );
- myMethodInfo->Invoke( myObject1, nullptr );
- }
- else
- {
- Console::WriteLine( "Could not locate HelloWorld method" );
- }
- }
- else
- {
- Console::WriteLine( "Could not access Type." );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/CustomAttributeData/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR/CustomAttributeData/CPP/source.cpp
deleted file mode 100644
index 95a1012b1d2..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/CustomAttributeData/CPP/source.cpp
+++ /dev/null
@@ -1,234 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Collections::Generic;
-using namespace System::Collections::ObjectModel;
-
-// An enumeration used by the ExampleAttribute class.
-public enum class ExampleKind
-{
- FirstKind, SecondKind, ThirdKind, FourthKind
-};
-
-// An example attribute. The attribute can be applied to all
-// targets, from assemblies to parameters.
-//
-[AttributeUsage(AttributeTargets::All)]
-public ref class ExampleAttribute: public Attribute
-{
-private:
- // Data for properties.
- ExampleKind kindValue;
- String^ noteValue;
- array^ arrayStrings;
- array^ arrayNumbers;
-
- // Constructors.
- void ExampleAttributeInitialize( ExampleKind initKind, array^ initStrings )
- {
- kindValue = initKind;
- arrayStrings = initStrings;
- }
-public:
- ExampleAttribute()
- {
- ExampleAttributeInitialize( ExampleKind::FirstKind, nullptr );
- }
- ExampleAttribute( ExampleKind initKind )
- {
- ExampleAttributeInitialize( initKind, nullptr );
- }
- ExampleAttribute( ExampleKind initKind, array^ initStrings )
- {
- ExampleAttributeInitialize( initKind, initStrings );
- }
-
- // Properties. The Note and Numbers properties must be read/write, so they
- // can be used as named parameters.
- //
- property ExampleKind Kind
- {
- ExampleKind get()
- {
- return kindValue;
- }
- }
- property array^ Strings
- {
- array^ get()
- {
- return arrayStrings;
- }
- }
- property String^ Note
- {
- String^ get()
- {
- return noteValue;
- }
-
- void set( String^ value )
- {
- noteValue = value;
- }
- }
- property array^ Numbers
- {
- array^ get()
- {
- return arrayNumbers;
- }
-
- void set( array^ value )
- {
- arrayNumbers = value;
- }
- }
-};
-
-// The example attribute is applied to the assembly.
-[assembly:Example(ExampleKind::ThirdKind,Note="This is a note on the assembly.")];
-
-// The example attribute is applied to the test class.
-//
-[Example(ExampleKind::SecondKind,
- gcnew array { "String array argument, line 1",
- "String array argument, line 2",
- "String array argument, line 3" },
- Note="This is a note on the class.",
- Numbers = gcnew array { 53, 57, 59 })]
-public ref class Test
-{
-public:
- // The example attribute is applied to a method, using the
- // parameterless constructor and supplying a named argument.
- // The attribute is also applied to the method parameter.
- //
- [Example(Note="This is a note on a method.")]
- void TestMethod( [Example] Object^ arg ){}
-
- // Main() gets objects representing the assembly, the test
- // type, the test method, and the method parameter. Custom
- // attribute data is displayed for each of these.
- //
- static void Main()
- {
- Assembly^ assembly = Assembly::ReflectionOnlyLoad( "Source" );
- Type^ t = assembly->GetType( "Test" );
- MethodInfo^ m = t->GetMethod( "TestMethod" );
- array^p = m->GetParameters();
-
- Console::WriteLine( "\r\nAttributes for assembly: '{0}'", assembly );
- ShowAttributeData( CustomAttributeData::GetCustomAttributes( assembly ) );
- Console::WriteLine( "\r\nAttributes for type: '{0}'", t );
- ShowAttributeData( CustomAttributeData::GetCustomAttributes( t ) );
- Console::WriteLine( "\r\nAttributes for member: '{0}'", m );
- ShowAttributeData( CustomAttributeData::GetCustomAttributes( m ) );
- Console::WriteLine( "\r\nAttributes for parameter: '{0}'", p );
- ShowAttributeData( CustomAttributeData::GetCustomAttributes( p[ 0 ] ) );
- }
-
-private:
- static void ShowValueOrArray(CustomAttributeTypedArgument^ cata)
- {
- if (cata->Value->GetType() == ReadOnlyCollection::typeid)
- {
- Console::WriteLine(" Array of '{0}':", cata->ArgumentType);
-
- for each (CustomAttributeTypedArgument^ cataElement in
- (ReadOnlyCollection^) cata->Value)
- {
- Console::WriteLine(" Type: '{0}' Value: '{1}'",
- cataElement->ArgumentType, cataElement->Value);
- }
- }
- else
- {
- Console::WriteLine( " Type: '{0}' Value: '{1}'",
- cata->ArgumentType, cata->Value );
- }
- }
-
- static void ShowAttributeData( IList< CustomAttributeData^ >^ attributes )
- {
- for each ( CustomAttributeData^ cad in attributes )
- {
- Console::WriteLine( " {0}", cad );
- Console::WriteLine( " Constructor: '{0}'", cad->Constructor );
-
- Console::WriteLine( " Constructor arguments:" );
- for each ( CustomAttributeTypedArgument^ cata in cad->ConstructorArguments )
- {
- ShowValueOrArray(cata);
- }
-
- Console::WriteLine( " Named arguments:" );
- for each ( CustomAttributeNamedArgument cana in cad->NamedArguments )
- {
- Console::WriteLine( " MemberInfo: '{0}'", cana.MemberInfo );
- ShowValueOrArray(cana.TypedValue);
- }
- }
- }
-};
-
-int main()
-{
- Test::Main();
-}
-
-/* This code example produces output similar to the following:
-
-Attributes for assembly: 'source, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
- [System.Runtime.CompilerServices.CompilationRelaxationsAttribute((Int32)8)]
- Constructor: 'Void .ctor(Int32)'
- Constructor arguments:
- Type: 'System.Int32' Value: '8'
- Named arguments:
- [System.Runtime.CompilerServices.RuntimeCompatibilityAttribute(WrapNonExceptionThrows = True)]
- Constructor: 'Void .ctor()'
- Constructor arguments:
- Named arguments:
- MemberInfo: 'Boolean WrapNonExceptionThrows'
- Type: 'System.Boolean' Value: 'True'
- [ExampleAttribute((ExampleKind)2, Note = "This is a note on the assembly.")]
- Constructor: 'Void .ctor(ExampleKind)'
- Constructor arguments:
- Type: 'ExampleKind' Value: '2'
- Named arguments:
- MemberInfo: 'System.String Note'
- Type: 'System.String' Value: 'This is a note on the assembly.'
-
-Attributes for type: 'Test'
- [ExampleAttribute((ExampleKind)1, new String[3] { "String array argument, line 1", "String array argument, line 2", "String array argument, line 3" }, Note = "This is a note on the class.", Numbers = new Int32[3] { 53, 57, 59 })]
- Constructor: 'Void .ctor(ExampleKind, System.String[])'
- Constructor arguments:
- Type: 'ExampleKind' Value: '1'
- Array of 'System.String[]':
- Type: 'System.String' Value: 'String array argument, line 1'
- Type: 'System.String' Value: 'String array argument, line 2'
- Type: 'System.String' Value: 'String array argument, line 3'
- Named arguments:
- MemberInfo: 'System.String Note'
- Type: 'System.String' Value: 'This is a note on the class.'
- MemberInfo: 'Int32[] Numbers'
- Array of 'System.Int32[]':
- Type: 'System.Int32' Value: '53'
- Type: 'System.Int32' Value: '57'
- Type: 'System.Int32' Value: '59'
-
-Attributes for member: 'Void TestMethod(System.Object)'
- [ExampleAttribute(Note = "This is a note on a method.")]
- Constructor: 'Void .ctor()'
- Constructor arguments:
- Named arguments:
- MemberInfo: 'System.String Note'
- Type: 'System.String' Value: 'This is a note on a method.'
-
-Attributes for parameter: 'System.Object arg'
- [ExampleAttribute()]
- Constructor: 'Void .ctor()'
- Constructor arguments:
- Named arguments:
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/Emit.ArgIterator/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/Emit.ArgIterator/cpp/source.cpp
deleted file mode 100644
index 0ee3bf8e579..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Emit.ArgIterator/cpp/source.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-void main()
-{
- String^ name = "InMemory";
-
- AssemblyBuilder^ asmBldr =
- AppDomain::CurrentDomain->DefineDynamicAssembly(gcnew AssemblyName(name),
- AssemblyBuilderAccess::Run);
- ModuleBuilder^ modBldr = asmBldr->DefineDynamicModule(name);
-
- TypeBuilder^ tb = modBldr->DefineType("DemoVararg");
-
- // Create a vararg method with no return value and one
- // string argument. (The string argument type is the only
- // element of an array of Type objects.)
- //
- MethodBuilder^ mb1 = tb->DefineMethod("VarargMethod",
- MethodAttributes::Public | MethodAttributes::Static,
- CallingConventions::VarArgs,
- nullptr,
- gcnew array { String::typeid });
-
- ILGenerator^ il1 = mb1->GetILGenerator();
-
- LocalBuilder^ locAi = il1->DeclareLocal(ArgIterator::typeid);
- LocalBuilder^ locNext = il1->DeclareLocal(bool::typeid);
-
- Label labelCheckCondition = il1->DefineLabel();
- Label labelNext = il1->DefineLabel();
-
- // Load the fixed argument and print it.
- il1->Emit(OpCodes::Ldarg_0);
- il1->Emit(OpCodes::Call, Console::typeid->GetMethod("Write",
- gcnew array { String::typeid }));
-
- // Load the address of the local variable represented by
- // locAi, which will hold the ArgIterator.
- il1->Emit(OpCodes::Ldloca_S, locAi);
-
- // Load the address of the argument list, and call the
- // ArgIterator constructor that takes an array of runtime
- // argument handles.
- il1->Emit(OpCodes::Arglist);
- il1->Emit(OpCodes::Call, ArgIterator::typeid->GetConstructor(
- gcnew array { RuntimeArgumentHandle::typeid }));
-
- // Enter the loop at the point where the remaining argument
- // count is tested.
- il1->Emit(OpCodes::Br_S, labelCheckCondition);
-
- // At the top of the loop, call GetNextArg to get the next
- // argument from the ArgIterator. Convert the typed reference
- // to an object reference and write the object to the console.
- il1->MarkLabel(labelNext);
- il1->Emit(OpCodes::Ldloca_S, locAi);
- il1->Emit(OpCodes::Call, ArgIterator::typeid->GetMethod("GetNextArg", Type::EmptyTypes));
- il1->Emit(OpCodes::Call, TypedReference::typeid->GetMethod("ToObject"));
- il1->Emit(OpCodes::Call, Console::typeid->GetMethod("Write",
- gcnew array { Object::typeid }));
-
- il1->MarkLabel(labelCheckCondition);
- il1->Emit(OpCodes::Ldloca_S, locAi);
- il1->Emit(OpCodes::Call, ArgIterator::typeid->GetMethod("GetRemainingCount"));
-
- // If the remaining count is greater than zero, go to
- // the top of the loop.
- il1->Emit(OpCodes::Ldc_I4_0);
- il1->Emit(OpCodes::Cgt);
- il1->Emit(OpCodes::Stloc_1);
- il1->Emit(OpCodes::Ldloc_1);
- il1->Emit(OpCodes::Brtrue_S, labelNext);
-
- il1->Emit(OpCodes::Ret);
-
- // Create a method that contains a call to the vararg
- // method.
- MethodBuilder^ mb2 = tb->DefineMethod("CallVarargMethod",
- MethodAttributes::Public | MethodAttributes::Static,
- CallingConventions::Standard,
- nullptr, Type::EmptyTypes);
-
- ILGenerator^ il2 = mb2->GetILGenerator();
-
- // Push arguments on the stack: one for the fixed string
- // parameter, and two for the list.
- il2->Emit(OpCodes::Ldstr, "Hello ");
- il2->Emit(OpCodes::Ldstr, "world ");
- il2->Emit(OpCodes::Ldc_I4, 2006);
-
- // Call the vararg method, specifying the types of the
- // arguments in the list.
- il2->EmitCall(OpCodes::Call, mb1,
- gcnew array { String::typeid, int::typeid });
-
- il2->Emit(OpCodes::Ret);
-
- Type^ type = tb->CreateType();
- type->GetMethod("CallVarargMethod")->Invoke(nullptr, nullptr);
-}
-
-/* This code example produces the following output:
-
-Hello world 2006
- */
-//
-
-
diff --git a/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp
deleted file mode 100644
index e0695468622..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Collections::Generic;
-
-// Dummy class to satisfy TFirst constraints.
-//
-public ref class Example {};
-
-// Define a trivial base class and two trivial interfaces
-// to use when demonstrating constraints.
-//
-public ref class ExampleBase {};
-public interface class IExampleA {};
-public interface class IExampleB {};
-
-// Define a trivial type that can substitute for type parameter
-// TSecond.
-//
-public ref class ExampleDerived : ExampleBase, IExampleA, IExampleB {};
-
-// List the constraint flags. The GenericParameterAttributes
-// enumeration contains two sets of attributes, variance and
-// constraints. For this example, only constraints are used.
-//
-static void ListConstraintAttributes( Type^ t )
-{
- // Mask off the constraint flags.
- GenericParameterAttributes constraints =
- t->GenericParameterAttributes &
- GenericParameterAttributes::SpecialConstraintMask;
-
- if ((constraints & GenericParameterAttributes::ReferenceTypeConstraint)
- != GenericParameterAttributes::None)
- Console::WriteLine( L" ReferenceTypeConstraint");
-
- if ((constraints & GenericParameterAttributes::NotNullableValueTypeConstraint)
- != GenericParameterAttributes::None)
- Console::WriteLine( L" NotNullableValueTypeConstraint");
-
- if ((constraints & GenericParameterAttributes::DefaultConstructorConstraint)
- != GenericParameterAttributes::None)
- Console::WriteLine( L" DefaultConstructorConstraint");
-}
-
-static void DisplayGenericParameters( Type^ t )
-{
- if (!t->IsGenericType)
- {
- Console::WriteLine( L"Type '{0}' is not generic." );
- return;
- }
- if (!t->IsGenericTypeDefinition)
- t = t->GetGenericTypeDefinition();
-
- array^ typeParameters = t->GetGenericArguments();
- Console::WriteLine( L"\r\nListing {0} type parameters for type '{1}'.",
- typeParameters->Length, t );
-
- for each ( Type^ tParam in typeParameters )
- {
- Console::WriteLine( L"\r\nType parameter {0}:",
- tParam->ToString() );
-
- for each (Type^ c in tParam->GetGenericParameterConstraints())
- {
- if (c->IsInterface)
- Console::WriteLine( L" Interface constraint: {0}", c);
- else
- Console::WriteLine( L" Base type constraint: {0}", c);
- }
- ListConstraintAttributes(tParam);
- }
-}
-
-void main()
-{
- // Define a dynamic assembly to contain the sample type. The
- // assembly will be run and also saved to disk, so
- // AssemblyBuilderAccess.RunAndSave is specified.
- //
- //
- AppDomain^ myDomain = AppDomain::CurrentDomain;
- AssemblyName^ myAsmName = gcnew AssemblyName( L"GenericEmitExample1" );
- AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly(
- myAsmName, AssemblyBuilderAccess::RunAndSave );
- //
-
- // An assembly is made up of executable modules. For a single-
- // module assembly, the module name and file name are the same
- // as the assembly name.
- //
- //
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule(
- myAsmName->Name, String::Concat( myAsmName->Name, L".dll" ) );
- //
-
- // Get type objects for the base class trivial interfaces to
- // be used as constraints.
- //
- Type^ baseType = ExampleBase::typeid;
- Type^ interfaceA = IExampleA::typeid;
- Type^ interfaceB = IExampleB::typeid;
-
- // Define the sample type.
- //
- //
- TypeBuilder^ myType = myModule->DefineType( L"Sample",
- TypeAttributes::Public );
- //
-
- Console::WriteLine( L"Type 'Sample' is generic: {0}",
- myType->IsGenericType );
-
- // Define type parameters for the type. Until you do this,
- // the type is not generic, as the preceding and following
- // WriteLine statements show. The type parameter names are
- // specified as an array of strings. To make the code
- // easier to read, each GenericTypeParameterBuilder is placed
- // in a variable with the same name as the type parameter.
- //
- //
- array^typeParamNames = {L"TFirst",L"TSecond"};
- array^typeParams =
- myType->DefineGenericParameters( typeParamNames );
-
- GenericTypeParameterBuilder^ TFirst = typeParams[0];
- GenericTypeParameterBuilder^ TSecond = typeParams[1];
- //
-
- Console::WriteLine( L"Type 'Sample' is generic: {0}",
- myType->IsGenericType );
-
- // Apply constraints to the type parameters.
- //
- // A type that is substituted for the first parameter, TFirst,
- // must be a reference type and must have a parameterless
- // constructor.
- //
- TFirst->SetGenericParameterAttributes(
- GenericParameterAttributes::DefaultConstructorConstraint |
- GenericParameterAttributes::ReferenceTypeConstraint
- );
- //
-
- // A type that is substituted for the second type
- // parameter must implement IExampleA and IExampleB, and
- // inherit from the trivial test class ExampleBase. The
- // interface constraints are specified as an array
- // containing the interface types.
- //
- array^interfaceTypes = { interfaceA, interfaceB };
- TSecond->SetInterfaceConstraints( interfaceTypes );
- TSecond->SetBaseTypeConstraint( baseType );
- //
-
- // The following code adds a private field named ExampleField,
- // of type TFirst.
- //
- FieldBuilder^ exField =
- myType->DefineField("ExampleField", TFirst,
- FieldAttributes::Private);
- //
-
- // Define a static method that takes an array of TFirst and
- // returns a List containing all the elements of
- // the array. To define this method it is necessary to create
- // the type List by calling MakeGenericType on the
- // generic type definition, generic List.
- // The parameter type is created by using the
- // MakeArrayType method.
- //
- //
- Type^ listOf = List::typeid;
- Type^ listOfTFirst = listOf->MakeGenericType(TFirst);
- array^ mParamTypes = { TFirst->MakeArrayType() };
-
- MethodBuilder^ exMethod =
- myType->DefineMethod("ExampleMethod",
- MethodAttributes::Public | MethodAttributes::Static,
- listOfTFirst,
- mParamTypes);
- //
-
- // Emit the method body.
- // The method body consists of just three opcodes, to load
- // the input array onto the execution stack, to call the
- // List constructor that takes IEnumerable,
- // which does all the work of putting the input elements into
- // the list, and to return, leaving the list on the stack. The
- // hard work is getting the constructor.
- //
- // The GetConstructor method is not supported on a
- // GenericTypeParameterBuilder, so it is not possible to get
- // the constructor of List directly. There are two
- // steps, first getting the constructor of generic List and then
- // calling a method that converts it to the corresponding
- // constructor of List.
- //
- // The constructor needed here is the one that takes an
- // IEnumerable. Note, however, that this is not the
- // generic type definition of generic IEnumerable; instead, the
- // T from generic List must be substituted for the T of
- // generic IEnumerable. (This seems confusing only because both
- // types have type parameters named T. That is why this example
- // uses the somewhat silly names TFirst and TSecond.) To get
- // the type of the constructor argument, take the generic
- // type definition generic IEnumerable and
- // call MakeGenericType with the first generic type parameter
- // of generic List. The constructor argument list must be passed
- // as an array, with just one argument in this case.
- //
- // Now it is possible to get the constructor of generic List,
- // using GetConstructor on the generic type definition. To get
- // the constructor of List, pass List and
- // the constructor from generic List to the static
- // TypeBuilder.GetConstructor method.
- //
- //
- ILGenerator^ ilgen = exMethod->GetILGenerator();
-
- Type^ ienumOf = IEnumerable::typeid;
- Type^ TfromListOf = listOf->GetGenericArguments()[0];
- Type^ ienumOfT = ienumOf->MakeGenericType(TfromListOf);
- array^ ctorArgs = {ienumOfT};
-
- ConstructorInfo^ ctorPrep = listOf->GetConstructor(ctorArgs);
- ConstructorInfo^ ctor =
- TypeBuilder::GetConstructor(listOfTFirst, ctorPrep);
-
- ilgen->Emit(OpCodes::Ldarg_0);
- ilgen->Emit(OpCodes::Newobj, ctor);
- ilgen->Emit(OpCodes::Ret);
- //
-
- // Create the type and save the assembly.
- //
- Type^ finished = myType->CreateType();
- myAssembly->Save( String::Concat( myAsmName->Name, L".dll" ) );
- //
-
- // Invoke the method.
- // ExampleMethod is not generic, but the type it belongs to is
- // generic, so in order to get a MethodInfo that can be invoked
- // it is necessary to create a constructed type. The Example
- // class satisfies the constraints on TFirst, because it is a
- // reference type and has a default constructor. In order to
- // have a class that satisfies the constraints on TSecond,
- // this code example defines the ExampleDerived type. These
- // two types are passed to MakeGenericMethod to create the
- // constructed type.
- //
- //
- array^ typeArgs =
- { Example::typeid, ExampleDerived::typeid };
- Type^ constructed = finished->MakeGenericType(typeArgs);
- MethodInfo^ mi = constructed->GetMethod("ExampleMethod");
- //
-
- // Create an array of Example objects, as input to the generic
- // method. This array must be passed as the only element of an
- // array of arguments. The first argument of Invoke is
- // null, because ExampleMethod is static. Display the count
- // on the resulting List.
- //
- //
- array^ input = { gcnew Example(), gcnew Example() };
- array^ arguments = { input };
-
- List^ listX =
- (List^) mi->Invoke(nullptr, arguments);
-
- Console::WriteLine(
- "\nThere are {0} elements in the List.",
- listX->Count);
- //
-
- DisplayGenericParameters(finished);
-}
-
-/* This code example produces the following output:
-
-Type 'Sample' is generic: False
-Type 'Sample' is generic: True
-
-There are 2 elements in the List.
-
-Listing 2 type parameters for type 'Sample[TFirst,TSecond]'.
-
-Type parameter TFirst:
- ReferenceTypeConstraint
- DefaultConstructorConstraint
-
-Type parameter TSecond:
- Interface constraint: IExampleA
- Interface constraint: IExampleB
- Base type constraint: ExampleBase
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_Properties_4.cs/CPP/enumbuilder_properties_4.cpp b/snippets/cpp/VS_Snippets_CLR/EnumBuilder_Properties_4.cs/CPP/enumbuilder_properties_4.cpp
deleted file mode 100644
index 47c3f438a04..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_Properties_4.cs/CPP/enumbuilder_properties_4.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-
-// System.Reflection.Emit.EnumBuilder.TypeToken
-// System.Reflection.Emit.EnumBuilder.UnderlyingField
-// System.Reflection.Emit.EnumBuilder.UnderlyingSystemType
-// System.Reflection.Emit.EnumBuilder.GUID
-/* The following program demonstrates 'TypeToken', 'UnderlyingField',
- 'UnderlyingSystemType' and ''GUID' properties of
- 'System.Reflection.Emit.EnumBuilder' class. This example defines
- a class 'MyEnumBuilderSample'. The main function calls the CreateCalle
- method in which the 'EnumBuilder' class and its fields are constructed.
- The output of the 'EnumBuilder' properties are displayed on the console
- in the main method. */
-//
-//
-//
-//
-using namespace System;
-using namespace System::Collections;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-public ref class MyEnumBuilderSample
-{
-private:
- static AssemblyBuilder^ myAssemblyBuilder;
- static ModuleBuilder^ myModuleBuilder;
- static EnumBuilder^ myEnumBuilder;
-
-public:
- static void Main()
- {
- try
- {
- CreateCallee( Thread::GetDomain(), AssemblyBuilderAccess::Save );
- array^myTypeArray = myModuleBuilder->GetTypes();
- IEnumerator^ myEnum = myTypeArray->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Type^ myType = safe_cast(myEnum->Current);
- Console::WriteLine( "Enum Builder defined in the module builder is: {0}", myType->Name );
- }
- Console::WriteLine( "Enum TypeToken is :{0}", myEnumBuilder->TypeToken );
- Console::WriteLine( "Enum UnderLyingField is :{0}", myEnumBuilder->UnderlyingField );
- Console::WriteLine( "Enum UnderLyingSystemType is :{0}", myEnumBuilder->UnderlyingSystemType );
- Console::WriteLine( "Enum GUID is :{0}", myEnumBuilder->GUID );
- myAssemblyBuilder->Save( "EmittedAssembly.dll" );
- }
- catch ( NotSupportedException^ ex )
- {
- Console::WriteLine( "The following is the exception is raised: {0}", ex->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "The following is the exception raised: {0}", e->Message );
- }
- }
-
-
-private:
- static void CreateCallee( AppDomain^ myAppDomain, AssemblyBuilderAccess /*access*/ )
- {
- // Create a name for the assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Create the dynamic assembly.
- myAssemblyBuilder = myAppDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Save );
-
- // Create a dynamic module.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
-
- // Create a dynamic Enum.
- myEnumBuilder = myModuleBuilder->DefineEnum( "MyNamespace.MyEnum", TypeAttributes::Public, Int32::typeid );
- FieldBuilder^ myFieldBuilder1 = myEnumBuilder->DefineLiteral( "FieldOne", 1 );
- FieldBuilder^ myFieldBuilder2 = myEnumBuilder->DefineLiteral( "FieldTwo", 2 );
- myEnumBuilder->CreateType();
- }
-};
-
-int main()
-{
- MyEnumBuilderSample::Main();
-}
-//
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_Properties_5/CPP/enumbuilder_properties_5.cpp b/snippets/cpp/VS_Snippets_CLR/EnumBuilder_Properties_5/CPP/enumbuilder_properties_5.cpp
deleted file mode 100644
index e210b66486f..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_Properties_5/CPP/enumbuilder_properties_5.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-
-// System.Reflection.Emit.EnumBuilder.Assembly
-// System.Reflection.Emit.EnumBuilder.AssemblyQualifiedName
-// System.Reflection.Emit.EnumBuilder.Module
-// System.Reflection.Emit.EnumBuilder.Name
-// System.Reflection.Emit.EnumBuilder.Namespace
-/* The following program demonstrates 'Assembly', 'AssemblyQualifiedName',
- 'Module', 'Name' and 'Namespace' properties of
- 'System.Reflection.Emit.EnumBuilder' class. This example defines a
- class 'MyEnumBuilderSample'. The main function calls the CreateCalle
- method in which the 'EnumBuilder' class and its fields are constructed.
- The output of the 'EnumBuilder' properties are displayed on the console
- in the main method. */
-//
-//
-//
-//
-//
-using namespace System;
-using namespace System::Collections;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class MyEnumBuilderSample
-{
-private:
- static AssemblyBuilder^ myAssemblyBuilder;
- static ModuleBuilder^ myModuleBuilder;
- static EnumBuilder^ myEnumBuilder;
-
-public:
- static void Main()
- {
- try
- {
- CreateCallee( Thread::GetDomain(), AssemblyBuilderAccess::Save );
- array^myTypeArray = myModuleBuilder->GetTypes();
- IEnumerator^ myEnum = myTypeArray->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Type^ myType = safe_cast(myEnum->Current);
- Console::WriteLine( "Enum Builder defined in the module builder is: {0}", myType->Name );
- }
- Console::WriteLine( "Properties of EnumBuilder : " );
- Console::WriteLine( "Enum Assembly is :{0}", myEnumBuilder->Assembly );
- Console::WriteLine( "Enum AssemblyQualifiedName is :{0}", myEnumBuilder->AssemblyQualifiedName );
- Console::WriteLine( "Enum Module is :{0}", myEnumBuilder->Module );
- Console::WriteLine( "Enum Name is :{0}", myEnumBuilder->Name );
- Console::WriteLine( "Enum NameSpace is :{0}", myEnumBuilder->Namespace );
- myAssemblyBuilder->Save( "EmittedAssembly.dll" );
- }
- catch ( NotSupportedException^ ex )
- {
- Console::WriteLine( "The following is the exception is raised: {0}", ex->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "The following is the exception raised: {0}", e->Message );
- }
- }
-
-private:
- static void CreateCallee( AppDomain^ myAppDomain, AssemblyBuilderAccess /*access*/ )
- {
- // Create a name for the assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Create the dynamic assembly.
- myAssemblyBuilder = myAppDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Save );
-
- // Create a dynamic module.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
-
- // Create a dynamic Enum.
- myEnumBuilder = myModuleBuilder->DefineEnum( "MyNamespace.MyEnum", TypeAttributes::Public, Int32::typeid );
- FieldBuilder^ myFieldBuilder1 = myEnumBuilder->DefineLiteral( "FieldOne", 1 );
- FieldBuilder^ myFieldBuilder2 = myEnumBuilder->DefineLiteral( "FieldTwo", 2 );
- myEnumBuilder->CreateType();
- }
-};
-
-int main()
-{
- MyEnumBuilderSample::Main();
-}
-//
-//
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_SetCustomAttribute1/CPP/enumbuilder_setcustomattribute1.cpp b/snippets/cpp/VS_Snippets_CLR/EnumBuilder_SetCustomAttribute1/CPP/enumbuilder_setcustomattribute1.cpp
deleted file mode 100644
index 6fa6db382ff..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_SetCustomAttribute1/CPP/enumbuilder_setcustomattribute1.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-
-// System.Reflection.Emit.EnumBuilder
-// System.Reflection.Emit.EnumBuilder.IsDefined()
-// System.Reflection.Emit.EnumBuilder.GetCustomAttributes(Type, bool)
-// System.Reflection.Emit.EnumBuilder.SetCustomAttribute(CustomAttributeBuilder)
-/*
- The following program demonstrates the EnumBuilder class and
- its methods 'IsDefined', 'GetCustomAttributes(Type, bool)' and
- 'SetCustomAttribute(CustomAttributeBuilder)'. It defines a 'MyAttribute'
- class which is derived from 'System.Attribute' class. It builds an Enum
- and sets 'MyAttribute' as custom attribute to the Enum. It gets the
- custom attributes of the Enum type and displays its contents on the console.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-//
-
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute: public Attribute
-{
-public:
- String^ myString;
- int myInteger;
- MyAttribute( String^ myString1, int myInteger1 )
- {
- this->myString = myString1;
- this->myInteger = myInteger1;
- }
-
-};
-
-ref class MyApplication
-{
-private:
- static AssemblyBuilder^ myAssemblyBuilder;
- static EnumBuilder^ myEnumBuilder;
-
-public:
- static void Main()
- {
- try
- {
- CreateCallee( Thread::GetDomain() );
- if ( myEnumBuilder->IsDefined( MyAttribute::typeid, false ) )
- {
- array^myAttributesArray = myEnumBuilder->GetCustomAttributes( MyAttribute::typeid, false );
- Console::WriteLine( "Custom attribute contains: " );
-
- // Read the attributes and display them on the console.
- for ( int index = 0; index < myAttributesArray->Length; index++ )
- {
- if ( dynamic_cast(myAttributesArray[ index ]) )
- {
- Console::WriteLine( "The value of myString is: {0}", (dynamic_cast(myAttributesArray[ index ]))->myString );
- Console::WriteLine( "The value of myInteger is: {0}", (dynamic_cast(myAttributesArray[ index ]))->myInteger );
- }
- }
- }
- else
- {
- Console::WriteLine( "Custom Attributes are not set for the EnumBuilder" );
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "The following exception is raised:{0}", e->Message );
- }
-
- }
-
-private:
- static void CreateCallee( AppDomain^ domain )
- {
- // Create a name for the assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Create the dynamic assembly.
- myAssemblyBuilder = domain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
- Type^ myType = MyAttribute::typeid;
- array^temp0 = {String::typeid,int::typeid};
- ConstructorInfo^ myInfo = myType->GetConstructor( temp0 );
- array^temp1 = {"Hello",2};
- CustomAttributeBuilder^ myCustomAttributeBuilder = gcnew CustomAttributeBuilder( myInfo,temp1 );
-
- // Create a dynamic module.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule" );
-
- // Create a dynamic Enum.
- myEnumBuilder = myModuleBuilder->DefineEnum( "MyNamespace.MyEnum", TypeAttributes::Public, Int32::typeid );
- FieldBuilder^ myFieldBuilder1 = myEnumBuilder->DefineLiteral( "FieldOne", 1 );
- FieldBuilder^ myFieldBuilder2 = myEnumBuilder->DefineLiteral( "FieldTwo", 2 );
- myEnumBuilder->CreateType();
- myEnumBuilder->SetCustomAttribute( myCustomAttributeBuilder );
- }
-};
-
-int main()
-{
- MyApplication::Main();
-}
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_SetCustomAttribute2/CPP/enumbuilder_setcustomattribute2.cpp b/snippets/cpp/VS_Snippets_CLR/EnumBuilder_SetCustomAttribute2/CPP/enumbuilder_setcustomattribute2.cpp
deleted file mode 100644
index 2e1b90bdfc9..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/EnumBuilder_SetCustomAttribute2/CPP/enumbuilder_setcustomattribute2.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-
-// System.Reflection.Emit.EnumBuilder.GetCustomAttributes(bool)
-// System.Reflection.Emit.EnumBuilder.SetCustomAttribute(ConstructorInfo, byte[])
-/*
- The following program demonstrates 'GetCustomAttributes(bool)'
- and 'SetCustomAttribute(ConstructorInfo, byte[])' methods of
- 'System.Reflection.Emit.EnumBuilder' class. It defines 'MyAttribute'
- class which is derived from 'System.Attribute' class. It builds an
- Enum and sets 'MyAttribute' as custom attribute to the Enum.
- It gets the custom attributes of the Enum type and displays its contents
- on the console.
-*/
-//
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute: public Attribute
-{
-public:
- bool myBoolValue;
- MyAttribute( bool myBool )
- {
- this->myBoolValue = myBool;
- }
-};
-
-ref class MyApplication
-{
-private:
- static EnumBuilder^ myEnumBuilder;
-
-public:
- static void Main()
- {
- try
- {
- CreateCallee( Thread::GetDomain() );
- array^myAttributesArray = myEnumBuilder->GetCustomAttributes( true );
-
- // Read the attributes and display them on the console.
- Console::WriteLine( "Custom attribute contains: " );
- for ( int index = 0; index < myAttributesArray->Length; index++ )
- {
- if ( dynamic_cast(myAttributesArray[ index ]) )
- {
- Console::WriteLine( "myBoolValue: {0}", (dynamic_cast(myAttributesArray[ index ]))->myBoolValue );
- }
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "The following exception is raised:{0}", e->Message );
- }
-
- }
-
-private:
- static void CreateCallee( AppDomain^ domain )
- {
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
-
- // Create a name for the assembly.
- myAssemblyName->Name = "EmittedAssembly";
-
- // Create the dynamic assembly.
- AssemblyBuilder^ myAssemblyBuilder = domain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
- Type^ myType = MyAttribute::typeid;
- array^temp0 = {bool::typeid};
- ConstructorInfo^ myInfo = myType->GetConstructor( temp0 );
-
- // Create a dynamic module.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule" );
-
- // Create a dynamic Enum.
- myEnumBuilder = myModuleBuilder->DefineEnum( "MyNamespace.MyEnum", TypeAttributes::Public, Int32::typeid );
- FieldBuilder^ myFieldBuilder1 = myEnumBuilder->DefineLiteral( "FieldOne", 1 );
- FieldBuilder^ myFieldBuilder2 = myEnumBuilder->DefineLiteral( "FieldTwo", 2 );
- myEnumBuilder->CreateType();
- array^temp1 = {01,00,01};
- myEnumBuilder->SetCustomAttribute( myInfo, temp1 );
- }
-};
-
-int main()
-{
- MyApplication::Main();
-}
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/EventArg/CPP/eventarg.cpp b/snippets/cpp/VS_Snippets_CLR/EventArg/CPP/eventarg.cpp
deleted file mode 100644
index 1b826c1f2bc..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/EventArg/CPP/eventarg.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-
-//
-// The following example uses instances of classes in
-// the System::Reflection namespace to discover an event argument type.
-using namespace System;
-using namespace System::Reflection;
-
-public delegate void MyDelegate( int i );
-public ref class MainClass
-{
-public:
- event MyDelegate^ ev;
-};
-
-int main()
-{
- Type^ delegateType = MainClass::typeid->GetEvent( "ev" )->EventHandlerType;
- MethodInfo^ invoke = delegateType->GetMethod( "Invoke" );
- array^pars = invoke->GetParameters();
- System::Collections::IEnumerator^ myEnum = pars->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- ParameterInfo^ p = safe_cast(myEnum->Current);
- Console::WriteLine( p->ParameterType );
- }
-}
-// The example displays the following output:
-// System.Int32
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldBuilder_ReflectedType/CPP/fieldbuilder_reflectedtype.cpp b/snippets/cpp/VS_Snippets_CLR/FieldBuilder_ReflectedType/CPP/fieldbuilder_reflectedtype.cpp
deleted file mode 100644
index 8b038438f4b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldBuilder_ReflectedType/CPP/fieldbuilder_reflectedtype.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-
-// System::Reflection::Emit::FieldBuilder.ReflectedType
-// System::Reflection::Emit::FieldBuilder.Attributes
-/*
- The following example demonstrates 'ReflectedType' and 'Attributes'
- properties of 'FieldBuilder' class.A new class 'MyClass' is created.
- A Field and a method are defined in the class.In the constructor of the class
- the field is initialized.Method of the class gets the value of the Field.
- An instance of the class is created and method is invoked.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ CreateType( AppDomain^ currentDomain )
-{
- // Create an assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "DynamicAssembly";
- AssemblyBuilder^ myAssembly = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module in Dynamic Assembly.
- ModuleBuilder^ myModuleBuilder = myAssembly->DefineDynamicModule( "MyModule" );
-
- // Define a public class named S"MyClass" in the assembly.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyClass", TypeAttributes::Public );
-
- // Define a private String field named S"MyField" in the type.
- FieldBuilder^ myFieldBuilder = myTypeBuilder->DefineField( "MyField", String::typeid, static_cast(FieldAttributes::Private | FieldAttributes::Static) );
-
- // Create the constructor.
- array^constructorArgs = {String::typeid};
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, constructorArgs );
- ILGenerator^ constructorIL = myConstructor->GetILGenerator();
- constructorIL->Emit( OpCodes::Ldarg_0 );
- ConstructorInfo^ superConstructor = Object::typeid->GetConstructor( gcnew array(0) );
- constructorIL->Emit( OpCodes::Call, superConstructor );
- constructorIL->Emit( OpCodes::Ldarg_0 );
- constructorIL->Emit( OpCodes::Ldarg_1 );
- constructorIL->Emit( OpCodes::Stfld, myFieldBuilder );
- constructorIL->Emit( OpCodes::Ret );
-
- // Create the MyMethod method.
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyMethod", MethodAttributes::Public, String::typeid, nullptr );
- ILGenerator^ methodIL = myMethodBuilder->GetILGenerator();
- methodIL->Emit( OpCodes::Ldarg_0 );
- methodIL->Emit( OpCodes::Ldfld, myFieldBuilder );
- methodIL->Emit( OpCodes::Ret );
- if ( myFieldBuilder->Attributes.Equals( FieldAttributes::Static ) )
- {
- Console::WriteLine( "Field attribute defined as Static" );
- }
- else
- if ( myFieldBuilder->Attributes.Equals( FieldAttributes::Static | FieldAttributes::Private ) )
- {
- Console::WriteLine( "Field attributes are Static and Private" );
- }
-
-
- Console::WriteLine( "ReflectedType of Field is : {0}", myFieldBuilder->ReflectedType );
- return myTypeBuilder->CreateType();
-}
-
-int main()
-{
- try
- {
- Type^ myType = CreateType( Thread::GetDomain() );
-
- // Create an instance of the S"HelloWorld" class.
- array^type = {"HelloWorld"};
- Object^ helloWorld = Activator::CreateInstance( myType, type );
-
- // Invoke the S"MyMethod" of the S"MyClass".
- Object^ myObject = myType->InvokeMember( "MyMethod", BindingFlags::InvokeMethod, nullptr, helloWorld, nullptr );
- Console::WriteLine( "MyClass::MyMethod returned: \"{0}\"", myObject );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception Caught {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldBuilder_SetCustomAttributes/CPP/fieldbuilder_setcustomattributes.cpp b/snippets/cpp/VS_Snippets_CLR/FieldBuilder_SetCustomAttributes/CPP/fieldbuilder_setcustomattributes.cpp
deleted file mode 100644
index fab865dd934..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldBuilder_SetCustomAttributes/CPP/fieldbuilder_setcustomattributes.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-
-// System::Reflection::Emit::FieldBuilder.SetCustomAttribute(ConstructorInfo, Byte->Item[])
-// System::Reflection::Emit::FieldBuilder.SetCustomAttribute(CustomAttributeBuilder)
-/*
- The following program demonstrates 'SetCustomAttribute(ConstructorInfo, Byte[])'
- and 'SetCustomAttribute(CustomAttributeBuilder)' methods of 'FieldBuilder' class.
- A dynamic assembly is created. A new class of type 'MyClass' is created.
- A 'Method' and a 'Field are defined in the class.Two 'CustomAttributes' are
- set to the field. The method initializes a value to 'Field'.Value of the field
- is displayed to console.Values of Attributes applied to field are retrieved and
- displayed to console.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute1: public Attribute
-{
-public:
- String^ myCustomAttributeValue;
- MyAttribute1( String^ myString )
- {
- myCustomAttributeValue = myString;
- }
-};
-
-
-[AttributeUsage(AttributeTargets::All,AllowMultiple=false)]
-public ref class MyAttribute2: public Attribute
-{
-public:
- bool myCustomAttributeValue;
- MyAttribute2( bool myBool )
- {
- myCustomAttributeValue = myBool;
- }
-};
-
-Type^ CreateCallee( AppDomain^ currentDomain )
-{
- // Create a simple name for the assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Create the called dynamic assembly.
- AssemblyBuilder^ myAssemblyBuilder = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
-
- // Define a public class named 'CustomClass' in the assembly.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "CustomClass", TypeAttributes::Public );
-
- // Define a private String field named 'MyField' in the type.
- FieldBuilder^ myFieldBuilder = myTypeBuilder->DefineField( "MyField", String::typeid, FieldAttributes::Public );
- Type^ myAttributeType1 = MyAttribute1::typeid;
-
- // Create a Constructorinfo Object* for attribute 'MyAttribute1'.
- array^type1 = {String::typeid};
- ConstructorInfo^ myConstructorInfo = myAttributeType1->GetConstructor( type1 );
-
- // Create the CustomAttribute instance of attribute of type 'MyAttribute1'.
- array^obj1 = {"Test"};
- CustomAttributeBuilder^ attributeBuilder = gcnew CustomAttributeBuilder( myConstructorInfo,obj1 );
-
- // Set the CustomAttribute 'MyAttribute1' to the Field.
- myFieldBuilder->SetCustomAttribute( attributeBuilder );
- Type^ myAttributeType2 = MyAttribute2::typeid;
-
- // Create a Constructorinfo Object* for attribute 'MyAttribute2'.
- array^type2 = {bool::typeid};
- ConstructorInfo^ myConstructorInfo2 = myAttributeType2->GetConstructor( type2 );
-
- // Set the CustomAttribute 'MyAttribute2' to the Field.
- array^bytes = {01,00,01,00,00};
- myFieldBuilder->SetCustomAttribute( myConstructorInfo2, bytes );
-
- // Create a method.
- array^type3 = {String::typeid,int::typeid};
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyMethod", MethodAttributes::Public, nullptr, type3 );
- ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
- myILGenerator->Emit( OpCodes::Ldarg_0 );
- myILGenerator->Emit( OpCodes::Ldarg_1 );
- myILGenerator->Emit( OpCodes::Stfld, myFieldBuilder );
- myILGenerator->EmitWriteLine( "Value of the Field is :" );
- myILGenerator->EmitWriteLine( myFieldBuilder );
- myILGenerator->Emit( OpCodes::Ret );
- return myTypeBuilder->CreateType();
-}
-
-int main()
-{
- try
- {
- Type^ myCustomClass = CreateCallee( Thread::GetDomain() );
-
- // Construct an instance of a type.
- Object^ myObject = Activator::CreateInstance( myCustomClass );
- Console::WriteLine( "FieldBuilder Sample" );
-
- // Find a method in this type and call it on this Object*.
- MethodInfo^ myMethodInfo = myCustomClass->GetMethod( "MyMethod" );
- array^obj1 = {"Sample string",3};
- myMethodInfo->Invoke( myObject, obj1 );
-
- // Retrieve the values of Attributes applied to field and display to console.
- array^myFieldInfo = myCustomClass->GetFields();
- for ( int i = 0; i < myFieldInfo->Length; i++ )
- {
- array^attributes = myFieldInfo[ i ]->GetCustomAttributes( true );
- for ( int index = 0; index < attributes->Length; index++ )
- {
- if ( dynamic_cast(attributes[ index ]) )
- {
- MyAttribute1^ myCustomAttribute = safe_cast(attributes[ index ]);
- Console::WriteLine( "Attribute Value of (MyAttribute1): {0}", myCustomAttribute->myCustomAttributeValue );
- }
- if ( dynamic_cast(attributes[ index ]) )
- {
- MyAttribute2^ myCustomAttribute = safe_cast(attributes[ index ]);
- Console::WriteLine( "Attribute Value of (MyAttribute2): {0}", myCustomAttribute->myCustomAttributeValue );
- }
- }
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception Caught {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldBuilder_SetOffset/CPP/fieldbuilder_setoffset.cpp b/snippets/cpp/VS_Snippets_CLR/FieldBuilder_SetOffset/CPP/fieldbuilder_setoffset.cpp
deleted file mode 100644
index 0fe41fc175c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldBuilder_SetOffset/CPP/fieldbuilder_setoffset.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-
-// System::Reflection::Emit::FieldBuilder.SetOffset
-// System::Reflection::Emit::FieldBuilder.SetMarshal
-/*
- The following program demonstrates 'SetOffset' and 'SetMarshal'
- methods of 'FieldBuilder' class.A new Class is defined and a
- 'PInvoke' method 'OpenFile' method of 'Kernel32.dll' is defined
- in the class.Instance of the class is created and the method is invoked.
- To execute this program, make sure a file named 'MyFile.txt' should be there
- in the current directory.
-*/
-//
-using namespace System;
-using namespace System::Runtime::InteropServices;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Runtime::CompilerServices;
-Type^ CreateType( AppDomain^ currentDomain )
-{
- // Create an assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "DynamicAssembly";
- AssemblyBuilder^ myAssembly = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Create a dynamic module in Dynamic Assembly.
- ModuleBuilder^ myModuleBuilder = myAssembly->DefineDynamicModule( "MyModule", "MyModule.mod" );
-
- // Define a public class named S"MyClass" in the assembly.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyClass", TypeAttributes::Public );
- TypeBuilder^ myTypeBuilder2 = myModuleBuilder->DefineType( "MyClass2", static_cast(TypeAttributes::Public | TypeAttributes::BeforeFieldInit | TypeAttributes::SequentialLayout | TypeAttributes::AnsiClass | TypeAttributes::Sealed) );
- FieldBuilder^ myFieldBuilder1 = myTypeBuilder2->DefineField( "myBytes1", Byte::typeid, FieldAttributes::Public );
- FieldBuilder^ myFieldBuilder2 = myTypeBuilder2->DefineField( "myBytes2", Byte::typeid, FieldAttributes::Public );
- FieldBuilder^ myFieldBuilder3 = myTypeBuilder2->DefineField( "myErrorCode", short::typeid, FieldAttributes::Public );
- FieldBuilder^ myFieldBuilder4 = myTypeBuilder2->DefineField( "myReserved1", short::typeid, FieldAttributes::Public );
- FieldBuilder^ myFieldBuilder5 = myTypeBuilder2->DefineField( "myReserved2", short::typeid, FieldAttributes::Public );
- FieldBuilder^ myFieldBuilder6 = myTypeBuilder2->DefineField( "myPathName", array::typeid,FieldAttributes::Public );
- myFieldBuilder6->SetMarshal( UnmanagedMarshal::DefineByValArray( 128 ) );
- myFieldBuilder6->SetOffset( 4 );
- Type^ myType1 = myTypeBuilder2->CreateType();
-
- // Create the PInvoke method for 'OpenFile' method of 'Kernel32.dll'.
- array^myParameters = {String::typeid,myType1,UInt32::typeid};
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefinePInvokeMethod( "OpenFile", "kernel32.dll", static_cast(MethodAttributes::Public | MethodAttributes::Static | MethodAttributes::HideBySig), CallingConventions::Standard, IntPtr::typeid, myParameters, CallingConvention::Winapi, CharSet::None );
- Type^ myAttributeType = MethodImplAttribute::typeid;
- array^type1 = {MethodImplOptions::typeid};
- ConstructorInfo^ myConstructorInfo = myAttributeType->GetConstructor( type1 );
- array^obj1 = {MethodImplOptions::PreserveSig};
- CustomAttributeBuilder^ myAttributeBuilder = gcnew CustomAttributeBuilder( myConstructorInfo,obj1 );
- myMethodBuilder->SetCustomAttribute( myAttributeBuilder );
- ParameterBuilder^ myParameterBuilder2 = myMethodBuilder->DefineParameter( 2, ParameterAttributes::Out, "myClass2" );
- Type^ myType = myTypeBuilder->CreateType();
- myAssembly->Save( "EmittedAssembly.dll" );
- return myType;
-}
-
-int main()
-{
- try
- {
- Type^ myType = CreateType( Thread::GetDomain() );
- Type^ myClass2 = myType->Module->GetType( "MyClass2" );
- Object^ myParam2 = Activator::CreateInstance( myClass2 );
- UInt32 myUint = 0x00000800;
- array^myArgs = {"MyFile.Txt",myParam2,myUint};
- Object^ myObject = myType->InvokeMember( "OpenFile", static_cast(BindingFlags::Public | BindingFlags::InvokeMethod | BindingFlags::Static), nullptr, nullptr, myArgs );
- Console::WriteLine( "MyClass::OpenFile method returned: \"{0}\"", myObject );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception Caught {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo/CPP/fieldinfo.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo/CPP/fieldinfo.cpp
deleted file mode 100644
index 58a29d2bc11..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo/CPP/fieldinfo.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-public ref class FieldInfoClass
-{
-public:
- int myField1;
-
-protected:
- String^ myField2;
-};
-
-int main()
-{
- array^myFieldInfo;
- Type^ myType = FieldInfoClass::typeid;
-
- // Get the type and fields of FieldInfoClass.
- myFieldInfo = myType->GetFields( static_cast(BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::Public) );
- Console::WriteLine( "\nThe fields of FieldInfoClass are \n" );
-
- // Display the field information of FieldInfoClass.
- for ( int i = 0; i < myFieldInfo->Length; i++ )
- {
- Console::WriteLine( "\nName : {0}", myFieldInfo[ i ]->Name );
- Console::WriteLine( "Declaring Type : {0}", myFieldInfo[ i ]->DeclaringType );
- Console::WriteLine( "IsPublic : {0}", myFieldInfo[ i ]->IsPublic );
- Console::WriteLine( "MemberType : {0}", myFieldInfo[ i ]->MemberType );
- Console::WriteLine( "FieldType : {0}", myFieldInfo[ i ]->FieldType );
- Console::WriteLine( "IsFamily : {0}", myFieldInfo[ i ]->IsFamily );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_FieldHandle/CPP/fieldinfo_fieldhandle.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_FieldHandle/CPP/fieldinfo_fieldhandle.cpp
deleted file mode 100644
index 8d70ea8d553..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_FieldHandle/CPP/fieldinfo_fieldhandle.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class MyClass
-{
-public:
- String^ MyField;
-};
-
-void DisplayFieldHandle( RuntimeFieldHandle myFieldHandle )
-{
- // Get the type from the handle.
- FieldInfo^ myField = FieldInfo::GetFieldFromHandle( myFieldHandle );
-
- // Display the type.
- Console::WriteLine( "\nDisplaying the field from the handle.\n" );
- Console::WriteLine( "The type is {0}.", myField );
-}
-
-int main()
-{
- MyClass^ myClass = gcnew MyClass;
-
- // Get the type of MyClass.
- Type^ myType = MyClass::typeid;
- try
- {
- // Get the field information of MyField.
- FieldInfo^ myFieldInfo = myType->GetField( "MyField", static_cast(BindingFlags::Public | BindingFlags::Instance) );
-
- // Determine whether or not the FieldInfo Object* is 0.
- if ( myFieldInfo != nullptr )
- {
- // Get the handle for the field.
- RuntimeFieldHandle myFieldHandle = myFieldInfo->FieldHandle;
- DisplayFieldHandle( myFieldHandle );
- }
- else
- {
- Console::WriteLine( "The myFieldInfo Object* is 0." );
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception: {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_GetFieldFromHandle/CPP/fieldinfo_getfieldfromhandle.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_GetFieldFromHandle/CPP/fieldinfo_getfieldfromhandle.cpp
deleted file mode 100644
index 558c1eaa9ca..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_GetFieldFromHandle/CPP/fieldinfo_getfieldfromhandle.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class FieldInfo_GetFieldFromHandle
-{
-public:
- String^ x;
- Char y;
- float a;
- int b;
-};
-
-int main()
-{
- // Get the type of the FieldInfo_GetFieldFromHandle class.
- Type^ myType = FieldInfo_GetFieldFromHandle::typeid;
-
- // Get the fields of the FieldInfo_GetFieldFromHandle class.
- array^myFieldInfoArray = myType->GetFields();
- Console::WriteLine( "\nThe field information of the declared fields x, y, a, and b is:\n" );
- RuntimeFieldHandle myRuntimeFieldHandle;
- for ( int i = 0; i < myFieldInfoArray->Length; i++ )
- {
- // Get the RuntimeFieldHandle of myFieldInfoArray.
- myRuntimeFieldHandle = myFieldInfoArray[ i ]->FieldHandle;
-
- // Call the GetFieldFromHandle method.
- FieldInfo^ myFieldInfo = FieldInfo::GetFieldFromHandle( myRuntimeFieldHandle );
-
- // Display the FieldInfo of myFieldInfo.
- Console::WriteLine( " {0}", myFieldInfo );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_GetValue/CPP/fieldinfo_getvalue.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_GetValue/CPP/fieldinfo_getvalue.cpp
deleted file mode 100644
index b4d9d357a06..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_GetValue/CPP/fieldinfo_getvalue.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class FieldsClass
-{
- public:
- String^ fieldA;
- String^ fieldB;
-
- FieldsClass()
- {
- fieldA = "A public field";
- fieldB = "Another public field";
- }
-};
-
-int main()
-{
- FieldsClass^ fieldsInst = gcnew FieldsClass;
-
- // Get the type of FieldsClass.
- Type^ fieldsType = FieldsClass::typeid;
-
- // Get the FieldInfo of FieldsClass.
- array^ fields = fieldsType->GetFields(static_cast(BindingFlags::Public | BindingFlags::Instance));
-
- // Display the values of the fields.
- Console::WriteLine("Displaying the values of the fields of {0}:", fieldsType);
- for (int i = 0; i < fields->Length; i++)
- {
- Console::WriteLine(" {0}:\t'{1}'",
- fields[i]->Name, fields[i]->GetValue(fieldsInst));
- }
-}
-// The example displays the following output:
-// Displaying the values of the fields of FieldsClass:
-// fieldA: 'A public field'
-// fieldB: 'Another public field'
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsNotSerialized/CPP/fieldinfo_isnotserialized.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsNotSerialized/CPP/fieldinfo_isnotserialized.cpp
deleted file mode 100644
index 49b86026b86..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsNotSerialized/CPP/fieldinfo_isnotserialized.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::Serialization;
-
-public ref class MyClass
-{
-public:
- short myShort;
-
- // The following field will not be serialized.
-
- [NonSerialized]
- int myInt;
-};
-
-int main()
-{
- // Get the type of MyClass.
- Type^ myType = MyClass::typeid;
-
- // Get the fields of MyClass.
- array^myFields = myType->GetFields( static_cast(BindingFlags::Public | BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::Static) );
- Console::WriteLine( "\nDisplaying whether or not the field is serializable.\n" );
-
- // Display whether or not the field is serializable.
- for ( int i = 0; i < myFields->Length; i++ )
- if ( myFields[ i ]->IsNotSerialized )
- Console::WriteLine( "The {0} field is not serializable.", myFields[ i ] );
- else
- Console::WriteLine( "The {0} field is serializable.", myFields[ i ] );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsPInvokeImpl/CPP/fieldinfo_ispinvokeimpl.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsPInvokeImpl/CPP/fieldinfo_ispinvokeimpl.cpp
deleted file mode 100644
index 5d8ebfb8a80..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsPInvokeImpl/CPP/fieldinfo_ispinvokeimpl.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class Fieldinfo_IsPinvoke
-{
-public:
- String^ myField;
- Fieldinfo_IsPinvoke()
- {
- myField = "A public field";
- }
-};
-
-int main()
-{
- Fieldinfo_IsPinvoke^ myObject = gcnew Fieldinfo_IsPinvoke;
-
- // Get the Type and FieldInfo.
- Type^ myType1 = Fieldinfo_IsPinvoke::typeid;
- FieldInfo^ myFieldInfo = myType1->GetField( "myField", static_cast(BindingFlags::Public | BindingFlags::Instance) );
-
- // Display the name, field and the PInvokeImpl attribute for the field.
- Console::Write( "\n Name of class: {0}", myType1->FullName );
- Console::Write( "\n Value of field: {0}", myFieldInfo->GetValue( myObject ) );
- Console::Write( "\n IsPinvokeImpl: {0}", myFieldInfo->IsPinvokeImpl );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsPrivate/CPP/fieldinfo_isprivate.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsPrivate/CPP/fieldinfo_isprivate.cpp
deleted file mode 100644
index 19e2ca9f358..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsPrivate/CPP/fieldinfo_isprivate.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-ref class MyClass
-{
-private:
- String^ myField;
-
-public:
- array^myArray;
- MyClass()
- {
- myField = "Microsoft";
- array^s = {"New York","New Jersey"};
- myArray = s;
- }
-
- property String^ GetField
- {
- String^ get()
- {
- return myField;
- }
- }
-};
-
-int main()
-{
- try
- {
- // Gets the type of MyClass.
- Type^ myType = MyClass::typeid;
-
- // Gets the field information of MyClass.
- array^myFields = myType->GetFields( static_cast(BindingFlags::NonPublic | BindingFlags::Public | BindingFlags::Instance) );
- Console::WriteLine( "\nDisplaying whether the fields of {0} are private or not:\n", myType );
- for ( int i = 0; i < myFields->Length; i++ )
- {
- // Check whether the field is private or not.
- if ( myFields[ i ]->IsPrivate )
- Console::WriteLine( " {0} is a private field.", myFields[ i ]->Name );
- else
- Console::WriteLine( " {0} is not a private field.", myFields[ i ]->Name );
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception : {0} ", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsSpecialName/CPP/fieldinfo_isspecialname.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsSpecialName/CPP/fieldinfo_isspecialname.cpp
deleted file mode 100644
index 0e31a95a459..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_IsSpecialName/CPP/fieldinfo_isspecialname.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-//
-#using
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::ComponentModel::Design;
-
-int main()
-{
- try
- {
- // Get the type handle of a specified class.
- Type^ myType = ViewTechnology::typeid;
-
- // Get the fields of the specified class.
- array^myField = myType->GetFields();
- Console::WriteLine( "\nDisplaying fields that have SpecialName attributes:\n" );
- for ( int i = 0; i < myField->Length; i++ )
- {
- // Determine whether or not each field is a special name.
- if ( myField[ i ]->IsSpecialName )
- {
- Console::WriteLine( "The field {0} has a SpecialName attribute.", myField[ i ]->Name );
- }
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception : {0} ", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/FieldInfo_SetValue/CPP/fieldinfo_setvalue.cpp b/snippets/cpp/VS_Snippets_CLR/FieldInfo_SetValue/CPP/fieldinfo_setvalue.cpp
deleted file mode 100644
index 5ba37dacd8a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/FieldInfo_SetValue/CPP/fieldinfo_setvalue.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Globalization;
-
-public ref class Example
-{
-private:
- String^ myString;
-
-public:
- Example()
- {
- myString = "Old value";
- }
-
- property String^ StringProperty
- {
- String^ get()
- {
- return myString;
- }
- }
-};
-
-int main()
-{
- Example^ myObject = gcnew Example;
- Type^ myType = Example::typeid;
- FieldInfo^ myFieldInfo = myType->GetField( "myString",
- BindingFlags::NonPublic | BindingFlags::Instance);
-
- // Display the string before applying SetValue to the field.
- Console::WriteLine( "\nThe field value of myString is \"{0}\".",
- myFieldInfo->GetValue( myObject ) );
- // Display the SetValue signature used to set the value of a field.
- Console::WriteLine( "Applying SetValue(Object, Object)." );
-
- // Change the field value using the SetValue method.
- myFieldInfo->SetValue( myObject, "New value" );
- // Display the string after applying SetValue to the field.
- Console::WriteLine( "The field value of mystring is \"{0}\".",
- myFieldInfo->GetValue(myObject));
-}
-/* This code produces the following output:
-
-The field value of myString is "Old value".
-Applying SetValue(Object, Object).
-The field value of mystring is "New value".
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/GenericMethodBuilder/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/GenericMethodBuilder/cpp/source.cpp
deleted file mode 100644
index 9f909725077..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/GenericMethodBuilder/cpp/source.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class GenericReflectionSample
-{
-};
-
-int main()
-{
- // Creating a dynamic assembly requires an AssemblyName
- // object, and the current application domain.
- //
- AssemblyName^ asmName =
- gcnew AssemblyName("EmittedAssembly");
- AppDomain^ domain = AppDomain::CurrentDomain;
- AssemblyBuilder^ sampleAssemblyBuilder =
- domain->DefineDynamicAssembly(asmName,
- AssemblyBuilderAccess::RunAndSave);
-
- // Define the module that contains the code. For an
- // assembly with one module, the module name is the
- // assembly name plus a file extension.
- ModuleBuilder^ sampleModuleBuilder =
- sampleAssemblyBuilder->DefineDynamicModule(asmName->Name,
- asmName->Name + ".dll");
-
- TypeBuilder^ sampleTypeBuilder =
- sampleModuleBuilder->DefineType("SampleType",
- TypeAttributes::Public | TypeAttributes::Abstract);
-
- //
- // Define a Shared, Public method with standard calling
- // conventions. Do not specify the parameter types or the
- // return type, because type parameters will be used for
- // those types, and the type parameters have not been
- // defined yet.
- MethodBuilder^ sampleMethodBuilder =
- sampleTypeBuilder->DefineMethod("SampleMethod",
- MethodAttributes::Public | MethodAttributes::Static);
- //
-
- //
- // Defining generic parameters for the method makes it a
- // generic method. By convention, type parameters are
- // single alphabetic characters. T and U are used here.
- //
- array^ genericTypeNames = {"T", "U"};
- array^ genericTypes =
- sampleMethodBuilder->DefineGenericParameters(
- genericTypeNames);
- //
-
- //
- // Use the IsGenericMethod property to find out if a
- // dynamic method is generic, and IsGenericMethodDefinition
- // to find out if it defines a generic method.
- Console::WriteLine("Is SampleMethod generic? {0}",
- sampleMethodBuilder->IsGenericMethod);
- Console::WriteLine(
- "Is SampleMethod a generic method definition? {0}",
- sampleMethodBuilder->IsGenericMethodDefinition);
- //
-
- //
- // Set parameter types for the method. The method takes
- // one parameter, and its type is specified by the first
- // type parameter, T.
- array^ parameterTypes = {genericTypes[0]};
- sampleMethodBuilder->SetParameters(parameterTypes);
-
- // Set the return type for the method. The return type is
- // specified by the second type parameter, U.
- sampleMethodBuilder->SetReturnType(genericTypes[1]);
- //
-
- // Generate a code body for the method. The method doesn't
- // do anything except return null.
- //
- ILGenerator^ ilgen = sampleMethodBuilder->GetILGenerator();
- ilgen->Emit(OpCodes::Ldnull);
- ilgen->Emit(OpCodes::Ret);
-
- //
- // Complete the type.
- Type^ sampleType = sampleTypeBuilder->CreateType();
-
- // To bind types to a dynamic generic method, you must
- // first call the GetMethod method on the completed type.
- // You can then define an array of types, and bind them
- // to the method.
- MethodInfo^ sampleMethodInfo = sampleType->GetMethod("SampleMethod");
- array^ boundParameters =
- {String::typeid, GenericReflectionSample::typeid};
- MethodInfo^ boundMethodInfo =
- sampleMethodInfo->MakeGenericMethod(boundParameters);
- // Display a string representing the bound method.
- Console::WriteLine(boundMethodInfo);
- //
-
- // Save the assembly, so it can be examined with Ildasm.exe.
- sampleAssemblyBuilder->Save(asmName->Name + ".dll");
-}
-
-/* This code example produces the following output:
-Is SampleMethod generic? True
-Is SampleMethod a generic method definition? True
-GenericReflectionSample SampleMethod[String,GenericReflectionSample](System.String)
-*/
-//
-
-
-
diff --git a/snippets/cpp/VS_Snippets_CLR/GetFldVal/CPP/getfldval.cpp b/snippets/cpp/VS_Snippets_CLR/GetFldVal/CPP/getfldval.cpp
deleted file mode 100644
index 4fd14cbab59..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/GetFldVal/CPP/getfldval.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-ref class Example
-{
- public:
- static String^ val = "test";
-};
-
-int main()
-{
- FieldInfo^ fld = Example::typeid->GetField( "val" );
- Console::WriteLine(fld->GetValue(nullptr) );
- Example::val = "hi";
- Console::WriteLine(fld->GetValue(nullptr) );
-}
-// The example displays the following output:
-// test
-// hi
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ILGenerator_BeginFaultBlock/CPP/ilgenerator_beginfaultblock.cpp b/snippets/cpp/VS_Snippets_CLR/ILGenerator_BeginFaultBlock/CPP/ilgenerator_beginfaultblock.cpp
deleted file mode 100644
index 59545a35ced..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ILGenerator_BeginFaultBlock/CPP/ilgenerator_beginfaultblock.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-
-// System.Reflection.Emit.ILGenerator.BeginFaultBlock()
-/*
-The following program demonstrates the 'BeginFaultBlock()' method of 'ILGenerator'
-class. Exception is raised by passing two integer values which are out of range,
-the same is caught in the 'BeginExceptionBlock' which is non-filtered. First it
-checks for the exception thrown in the 'BeginFaultBlock' and then emits the MSIL
-instructions in 'BeginExceptFilterBlock'.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-Type^ AddType()
-{
- // Create an assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "AdderExceptionAsm";
-
- // Create dynamic assembly.
- AppDomain^ myAppDomain = Thread::GetDomain();
- AssemblyBuilder^ myAssemblyBuilder = myAppDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "AdderExceptionMod" );
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "Adder" );
- array^myAdderParams = {int::typeid,int::typeid};
-
- // Method to add two numbers.
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "DoAdd", static_cast(MethodAttributes::Public | MethodAttributes::Static), int::typeid, myAdderParams );
- ILGenerator^ myAdderIL = myMethodBuilder->GetILGenerator();
-
- // Create constructor.
- array^temp0 = {String::typeid};
- ConstructorInfo^ myConstructorInfo = OverflowException::typeid->GetConstructor( temp0 );
- MethodInfo^ myExToStrMI = OverflowException::typeid->GetMethod( "ToString" );
- array^temp1 = {String::typeid,Object::typeid};
- MethodInfo^ myWriteLineMI = Console::typeid->GetMethod( "WriteLine", temp1 );
-
- // Declare local variable.
- LocalBuilder^ myLocalBuilder1 = myAdderIL->DeclareLocal( int::typeid );
- LocalBuilder^ myLocalBuilder2 = myAdderIL->DeclareLocal( OverflowException::typeid );
-
- // Define label.
- Label myFailedLabel = myAdderIL->DefineLabel();
- Label myEndOfMethodLabel = myAdderIL->DefineLabel();
-
- // Begin exception block.
- Label myLabel = myAdderIL->BeginExceptionBlock();
- myAdderIL->Emit( OpCodes::Ldarg_0 );
- myAdderIL->Emit( OpCodes::Ldc_I4_S, 10 );
- myAdderIL->Emit( OpCodes::Bgt_S, myFailedLabel );
- myAdderIL->Emit( OpCodes::Ldarg_1 );
- myAdderIL->Emit( OpCodes::Ldc_I4_S, 10 );
- myAdderIL->Emit( OpCodes::Bgt_S, myFailedLabel );
- myAdderIL->Emit( OpCodes::Ldarg_0 );
- myAdderIL->Emit( OpCodes::Ldarg_1 );
- myAdderIL->Emit( OpCodes::Add_Ovf_Un );
- myAdderIL->Emit( OpCodes::Stloc_S, myLocalBuilder1 );
- myAdderIL->Emit( OpCodes::Br_S, myEndOfMethodLabel );
- myAdderIL->MarkLabel( myFailedLabel );
- myAdderIL->Emit( OpCodes::Ldstr, "Cannot accept values over 10 for addition." );
- myAdderIL->Emit( OpCodes::Newobj, myConstructorInfo );
- myAdderIL->Emit( OpCodes::Stloc_S, myLocalBuilder2 );
- myAdderIL->Emit( OpCodes::Ldloc_S, myLocalBuilder2 );
-
- // Call fault block.
- myAdderIL->BeginFaultBlock();
- Console::WriteLine( "Fault block called." );
-
- //Throw exception.
- myAdderIL->ThrowException( NotSupportedException::typeid );
-
- // Call finally block.
- myAdderIL->BeginFinallyBlock();
- myAdderIL->Emit( OpCodes::Ldstr, "{0}" );
- myAdderIL->Emit( OpCodes::Ldloc_S, myLocalBuilder2 );
- myAdderIL->EmitCall( OpCodes::Callvirt, myExToStrMI, nullptr );
- myAdderIL->EmitCall( OpCodes::Call, myWriteLineMI, nullptr );
- myAdderIL->Emit( OpCodes::Ldc_I4_M1 );
- myAdderIL->Emit( OpCodes::Stloc_S, myLocalBuilder1 );
-
- // End exception block.
- myAdderIL->EndExceptionBlock();
- myAdderIL->MarkLabel( myEndOfMethodLabel );
- myAdderIL->Emit( OpCodes::Ldloc_S, myLocalBuilder1 );
- myAdderIL->Emit( OpCodes::Ret );
- return myTypeBuilder->CreateType();
-}
-
-int main()
-{
- Type^ myAddType = AddType();
- Object^ myObject1 = Activator::CreateInstance( myAddType );
- array^myObject2 = {11,12};
-
- // Invoke member.
- myAddType->InvokeMember( "DoAdd", BindingFlags::InvokeMethod, nullptr, myObject1, myObject2 );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ILGenerator_BeginFinallyBlock_2/CPP/ILGenerator_BeginFinallyBlock_2.cpp b/snippets/cpp/VS_Snippets_CLR/ILGenerator_BeginFinallyBlock_2/CPP/ILGenerator_BeginFinallyBlock_2.cpp
deleted file mode 100644
index bc0c0c8e893..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ILGenerator_BeginFinallyBlock_2/CPP/ILGenerator_BeginFinallyBlock_2.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-
-// System::Reflection::Emit::ILGenerator.BeginExceptFilterBlock()
-// System::Reflection::Emit::ILGenerator.BeginFinallyBlock()
-/*
- The following program demonstrates the 'BeginExceptFilterBlock()' method and
- 'BeginFinallyBlock()' of 'ILGenerator' class. Exception is raised by passing
- two integer values which are out of range, the same is caught in the
- 'BeginExceptionBlock' which is non-filtered and then emits the MSIL
- instructions in 'BeginExceptFilterBlock' and 'BeginFinallyBlock'.
-*/
-//
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class ILGenerator_BeginFinallyBlock
-{
-public:
- static Type^ AddType()
- {
- // Create an assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "AdderExceptionAsm";
-
- // Create dynamic assembly.
- AppDomain^ myAppDomain = Thread::GetDomain();
- AssemblyBuilder^ myAssemblyBuilder = myAppDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "AdderExceptionMod" );
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "Adder" );
- array^adderParams = {int::typeid,int::typeid};
-
- // Define method to add two numbers.
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "DoAdd", static_cast(MethodAttributes::Public | MethodAttributes::Static), int::typeid, adderParams );
- ILGenerator^ myAdderIL = myMethodBuilder->GetILGenerator();
-
- // Create constructor.
- array^type1 = {String::typeid};
- ConstructorInfo^ myConstructorInfo = OverflowException::typeid->GetConstructor( type1 );
- MethodInfo^ myExToStrMI = OverflowException::typeid->GetMethod( "ToString" );
- array^type2 = {String::typeid,Object::typeid};
- MethodInfo^ myWriteLineMI = Console::typeid->GetMethod( "WriteLine", type2 );
-
- // Declare local variable.
- LocalBuilder^ myLocalBuilder1 = myAdderIL->DeclareLocal( int::typeid );
- LocalBuilder^ myLocalBuilder2 = myAdderIL->DeclareLocal( OverflowException::typeid );
-
- // Define label.
- Label myFailedLabel = myAdderIL->DefineLabel();
- Label myEndOfMethodLabel = myAdderIL->DefineLabel();
-
- // Begin exception block.
- Label myLabel = myAdderIL->BeginExceptionBlock();
- myAdderIL->Emit( OpCodes::Ldarg_0 );
- myAdderIL->Emit( OpCodes::Ldc_I4_S, 10 );
- myAdderIL->Emit( OpCodes::Bgt_S, myFailedLabel );
- myAdderIL->Emit( OpCodes::Ldarg_1 );
- myAdderIL->Emit( OpCodes::Ldc_I4_S, 10 );
- myAdderIL->Emit( OpCodes::Bgt_S, myFailedLabel );
- myAdderIL->Emit( OpCodes::Ldarg_0 );
- myAdderIL->Emit( OpCodes::Ldarg_1 );
- myAdderIL->Emit( OpCodes::Add_Ovf_Un );
- myAdderIL->Emit( OpCodes::Stloc_S, myLocalBuilder1 );
- myAdderIL->Emit( OpCodes::Br_S, myEndOfMethodLabel );
- myAdderIL->MarkLabel( myFailedLabel );
- myAdderIL->Emit( OpCodes::Ldstr, "Cannot accept values over 10 for add." );
- myAdderIL->Emit( OpCodes::Newobj, myConstructorInfo );
- myAdderIL->Emit( OpCodes::Stloc_S, myLocalBuilder2 );
- myAdderIL->Emit( OpCodes::Ldloc_S, myLocalBuilder2 );
-
- // Throw the exception.
- myAdderIL->ThrowException( OverflowException::typeid );
-
- // Call 'BeginExceptFilterBlock'.
- myAdderIL->BeginExceptFilterBlock();
- myAdderIL->EmitWriteLine( "Except filter block called." );
-
- // Call catch block.
- myAdderIL->BeginCatchBlock( nullptr );
-
- // Call other catch block.
- myAdderIL->BeginCatchBlock( OverflowException::typeid );
- myAdderIL->Emit( OpCodes::Ldstr, "{0}" );
- myAdderIL->Emit( OpCodes::Ldloc_S, myLocalBuilder2 );
- myAdderIL->EmitCall( OpCodes::Callvirt, myExToStrMI, nullptr );
- myAdderIL->EmitCall( OpCodes::Call, myWriteLineMI, nullptr );
- myAdderIL->Emit( OpCodes::Ldc_I4_M1 );
- myAdderIL->Emit( OpCodes::Stloc_S, myLocalBuilder1 );
-
- // Call finally block.
- myAdderIL->BeginFinallyBlock();
- myAdderIL->EmitWriteLine( "Finally block called." );
-
- // End the exception block.
- myAdderIL->EndExceptionBlock();
- myAdderIL->MarkLabel( myEndOfMethodLabel );
- myAdderIL->Emit( OpCodes::Ldloc_S, myLocalBuilder1 );
- myAdderIL->Emit( OpCodes::Ret );
- return myTypeBuilder->CreateType();
- }
-};
-
-int main()
-{
- Type^ myAddType = ILGenerator_BeginFinallyBlock::AddType();
- Object^ myObject1 = Activator::CreateInstance( myAddType );
- array^myObject2 = {15,15};
- myAddType->InvokeMember( "DoAdd", BindingFlags::InvokeMethod, nullptr, myObject1, myObject2 );
-}
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ILGenerator_Begin_EndScope/CPP/ilgenerator_begin_endscope.cpp b/snippets/cpp/VS_Snippets_CLR/ILGenerator_Begin_EndScope/CPP/ilgenerator_begin_endscope.cpp
deleted file mode 100644
index 125264cb896..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ILGenerator_Begin_EndScope/CPP/ilgenerator_begin_endscope.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-
-// System.Reflection.Emit.ILGenerator
-// System.Reflection.Emit.ILGenerator.BeginScope()
-// System.Reflection.Emit.ILGenerator.EndScope()
-/*
-This program demonstrates the 'BeginScope()', 'EndScope()' methods and the class
-'ILGenerator'. A dynamic class 'myTypeBuilder' is created in which a
-constructor 'myConstructor' and a method 'myMethod' are created dynamically. Their IL's
-are generated. A local variable 'myLocalBuilder' is declared using 'DeclareLocal' property
-of 'myMethodIL'. The scope of 'myLocalBuilder' is specified using 'BeginScope' and
-'EndScope' methods. Respective messages related to scope are printed on the console.
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-int main()
-{
- try
- {
- //
- //
- // Get the current AppDomain.
- AppDomain^ myAppDomain = AppDomain::CurrentDomain;
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "SampleAssembly";
-
- // Create a dynamic assembly 'myAssembly' with access mode 'Run'.
- AssemblyBuilder^ myAssembly = myAppDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module 'myModule' in 'myAssembly'.
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "MyDynamicModule", true );
-
- // Define a public class 'MyDynamicClass'.
- TypeBuilder^ myTypeBuilder = myModule->DefineType( "MyDynamicClass", TypeAttributes::Public );
-
- // Define a public string field.
- FieldBuilder^ myField = myTypeBuilder->DefineField( "MyDynamicField", String::typeid, FieldAttributes::Public );
-
- // Create the constructor.
- array^myConstructorArgs = {String::typeid};
- ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
-
- // Generate IL for 'myConstructor'.
- ILGenerator^ myConstructorIL = myConstructor->GetILGenerator();
-
- // Emit the necessary opcodes.
- myConstructorIL->Emit( OpCodes::Ldarg_0 );
- ConstructorInfo^ mySuperConstructor = Object::typeid->GetConstructor( gcnew array(0) );
- myConstructorIL->Emit( OpCodes::Call, mySuperConstructor );
- myConstructorIL->Emit( OpCodes::Ldarg_0 );
- myConstructorIL->Emit( OpCodes::Ldarg_1 );
- myConstructorIL->Emit( OpCodes::Stfld, myField );
- myConstructorIL->Emit( OpCodes::Ret );
-
- // Define a dynamic method named 'MyDynamicMethod'.
- MethodBuilder^ myMethod = myTypeBuilder->DefineMethod( "MyDynamicMethod", MethodAttributes::Public, String::typeid, nullptr );
-
- // Generate IL for 'myMethod'.
- ILGenerator^ myMethodIL = myMethod->GetILGenerator();
-
- // Begin the scope for a local variable.
- myMethodIL->BeginScope();
- LocalBuilder^ myLocalBuilder = myMethodIL->DeclareLocal( int::typeid );
- Console::WriteLine( "\nTrying to access the local variable within the scope." );
- Console::WriteLine( "'myLocalBuilder' type is :{0}", myLocalBuilder->LocalType );
- myMethodIL->Emit( OpCodes::Ldstr, "Local value" );
- myMethodIL->Emit( OpCodes::Stloc_0, myLocalBuilder );
-
- // End the scope of 'myLocalBuilder'.
- myMethodIL->EndScope();
-
- // Access the local variable outside the scope.
- Console::WriteLine( "\nTrying to access the local variable outside the scope:\n" );
- myMethodIL->Emit( OpCodes::Stloc_0, myLocalBuilder );
- myMethodIL->Emit( OpCodes::Ldloc_0 );
- myMethodIL->Emit( OpCodes::Ret );
-
- // Create 'MyDynamicClass' class.
- Type^ myType1 = myTypeBuilder->CreateType();
- //
- //
-
- // Create an instance of the 'MyDynamicClass'.
- array^temp0 = {"HelloWorld"};
- Object^ myObject1 = Activator::CreateInstance( myType1, temp0 );
-
- // Invoke 'MyDynamicMethod' method of 'MyDynamicClass'.
- Object^ myObject2 = myType1->InvokeMember( "MyDynamicMethod", BindingFlags::InvokeMethod, nullptr, myObject1, nullptr );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception :{0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/IndentedTextWriterExample/CPP/form1.cpp b/snippets/cpp/VS_Snippets_CLR/IndentedTextWriterExample/CPP/form1.cpp
deleted file mode 100644
index 4c29bcd1705..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/IndentedTextWriterExample/CPP/form1.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-//
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::CodeDom;
-using namespace System::CodeDom::Compiler;
-using namespace System::ComponentModel;
-using namespace System::IO;
-using namespace System::Windows::Forms;
-public ref class Form1: public System::Windows::Forms::Form
-{
-private:
- System::Windows::Forms::TextBox^ textBox1;
-
- //
- String^ CreateMultilevelIndentString()
- {
-
- //
- // Creates a TextWriter to use as the base output writer.
- System::IO::StringWriter^ baseTextWriter = gcnew System::IO::StringWriter;
-
- // Create an IndentedTextWriter and set the tab string to use
- // as the indentation string for each indentation level.
- System::CodeDom::Compiler::IndentedTextWriter^ indentWriter = gcnew IndentedTextWriter( baseTextWriter," " );
-
- //
- //
- // Sets the indentation level.
- indentWriter->Indent = 0;
-
- //
- // Output test strings at stepped indentations through a recursive loop method.
- WriteLevel( indentWriter, 0, 5 );
-
- // Return the resulting string from the base StringWriter.
- return baseTextWriter->ToString();
- }
-
-
- //
- void WriteLevel( IndentedTextWriter^ indentWriter, int level, int totalLevels )
- {
-
- // Output a test string with a new-line character at the end.
- indentWriter->WriteLine( "This is a test phrase. Current indentation level: {0}", level );
-
- // If not yet at the highest recursion level, call this output method for the next level of indentation.
- if ( level < totalLevels )
- {
-
- // Increase the indentation count for the next level of indented output.
- indentWriter->Indent++;
-
- // Call the WriteLevel method to write test output for the next level of indentation.
- WriteLevel( indentWriter, level + 1, totalLevels );
-
- // Restores the indentation count for this level after the recursive branch method has returned.
- indentWriter->Indent--;
- }
- else
- //
- // Outputs a string using the WriteLineNoTabs method.
- indentWriter->WriteLineNoTabs( "This is a test phrase written with the IndentTextWriter.WriteLineNoTabs method." );
- //
- // Outputs a test string with a new-line character at the end.
- indentWriter->WriteLine( "This is a test phrase. Current indentation level: {0}", level );
- }
-
-
- //
- //
- void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
- {
- textBox1->Text = CreateMultilevelIndentString();
- }
-
-
-public:
- Form1()
- {
- System::Windows::Forms::Button^ button1 = gcnew System::Windows::Forms::Button;
- this->textBox1 = gcnew System::Windows::Forms::TextBox;
- this->SuspendLayout();
- this->textBox1->Anchor = (System::Windows::Forms::AnchorStyles)(System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left | System::Windows::Forms::AnchorStyles::Right);
- this->textBox1->Location = System::Drawing::Point( 8, 40 );
- this->textBox1->Multiline = true;
- this->textBox1->Name = "textBox1";
- this->textBox1->Size = System::Drawing::Size( 391, 242 );
- this->textBox1->TabIndex = 0;
- this->textBox1->Text = "";
- button1->Location = System::Drawing::Point( 11, 8 );
- button1->Name = "button1";
- button1->Size = System::Drawing::Size( 229, 23 );
- button1->TabIndex = 1;
- button1->Text = "Generate string using IndentedTextWriter";
- button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );
- this->AutoScaleBaseSize = System::Drawing::Size( 5, 13 );
- this->ClientSize = System::Drawing::Size( 407, 287 );
- this->Controls->Add( button1 );
- this->Controls->Add( this->textBox1 );
- this->Name = "Form1";
- this->Text = "IndentedTextWriter example";
- this->ResumeLayout( false );
- }
-
-};
-
-
-[STAThread]
-int main()
-{
- Application::Run( gcnew Form1 );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/LocalBuilder_Sample_SetLocalSymInfo/CPP/localbuilder_sample_4.cpp b/snippets/cpp/VS_Snippets_CLR/LocalBuilder_Sample_SetLocalSymInfo/CPP/localbuilder_sample_4.cpp
deleted file mode 100644
index 75e16a96906..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/LocalBuilder_Sample_SetLocalSymInfo/CPP/localbuilder_sample_4.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-
-// System.Reflection.Emit.LocalBuilder
-// System.Reflection.Emit.ILGenerator.DeclareLocal(Type)
-// System.Reflection.Emit.LocalBuilder.SetLocalSymInfo(String)
-// System.Reflection.Emit.LocalBuilder.LocalType()
-// System.Reflection.Emit.LocalBuilder.SetLocalSymInfo(String, Int32, Int32)
-/*
-
-This program demonstrates 'LocalType' property, 'SetLocalSymInfo(String)',
-'SetLocalSymInfo(String, Int32,Int32)' methods, class level for 'LocalBuilder' and
-'DeclareLocal(Type)' method of ILGenerator class. An assembly 'myClass' is created using
-AssemblyBuilder, ModuleBuilder, FieldBuilder, TypeBuilder, ConstructorBuilder classes.
-Localbuilder class is used to create local variables of the specified type.
-
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Threading;
-int main()
-{
- // Create an assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "SampleAssembly";
- AssemblyBuilder^ myAssembly = Thread::GetDomain()->DefineDynamicAssembly(
- myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Create a module. For a single-file assembly the module
- // name is usually the same as the assembly name.
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule(
- myAssemblyName->Name, myAssemblyName->Name + ".dll", true );
-
- // Define a public class 'Example'.
- TypeBuilder^ myTypeBuilder = myModule->DefineType( "Example", TypeAttributes::Public );
-
- // Create the 'Function1' public method, which takes an integer
- // and returns a string.
- MethodBuilder^ myMethod = myTypeBuilder->DefineMethod( "Function1",
- MethodAttributes::Public | MethodAttributes::Static, String::typeid,
- gcnew array { int::typeid } );
-
- // Generate IL for 'Function1'. The function body demonstrates
- // assigning an argument to a local variable, assigning a
- // constant string to a local variable, and putting the contents
- // of local variables on the stack.
- ILGenerator^ myMethodIL = myMethod->GetILGenerator();
-
- //
- // Create local variables named myString and myInt.
- LocalBuilder^ myLB1 = myMethodIL->DeclareLocal( String::typeid );
- myLB1->SetLocalSymInfo( "myString" );
- Console::WriteLine( "local 'myString' type is: {0}", myLB1->LocalType );
-
- LocalBuilder^ myLB2 = myMethodIL->DeclareLocal( int::typeid );
- myLB2->SetLocalSymInfo( "myInt", 1, 2 );
- Console::WriteLine( "local 'myInt' type is: {0}", myLB2->LocalType );
- //
-
- // Store the function argument in myInt.
- myMethodIL->Emit( OpCodes::Ldarg_0 );
- myMethodIL->Emit( OpCodes::Stloc_1 );
-
- // Store a literal value in myString, and return the value.
- myMethodIL->Emit( OpCodes::Ldstr, "string value" );
- myMethodIL->Emit( OpCodes::Stloc_0 );
- myMethodIL->Emit( OpCodes::Ldloc_0 );
- myMethodIL->Emit( OpCodes::Ret );
-
- // Create "Example" class.
- Type^ myType1 = myTypeBuilder->CreateType();
- Console::WriteLine( "'Example' is created." );
-
- myAssembly->Save(myAssemblyName->Name + ".dll");
- Console::WriteLine( "'{0}' is created.", myAssemblyName->Name + ".dll" );
-
- // Invoke 'Function1' method of 'Example', passing the value 42.
- Object^ myObject2 = myType1->InvokeMember( "Function1",
- BindingFlags::InvokeMethod, nullptr, nullptr,
- gcnew array { 42 } );
-
- Console::WriteLine( "Example::Function1 returned: {0}", myObject2 );
-}
-/* This code example produces the following output:
-
-local 'myString' type is: System.String
-local 'myInt' type is: System.Int32
-'Example' is created.
-'SampleAssembly.dll' is created.
-Example::Function1 returned: string value
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/MakeXxxGenericTypeParameterBuilder/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/MakeXxxGenericTypeParameterBuilder/cpp/source.cpp
deleted file mode 100644
index e978a2ab18b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/MakeXxxGenericTypeParameterBuilder/cpp/source.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-int main()
-{
- // Define a dynamic assembly to contain the sample type. The
- // assembly will not be run, but only saved to disk, so
- // AssemblyBuilderAccess.Save is specified.
- //
- AppDomain^ appDomain = AppDomain::CurrentDomain;
- AssemblyName^ assemblyName = gcnew
- AssemblyName("MakeXxxGenericTypeParameterExample");
- AssemblyBuilder^ assemblyBuilder = appDomain->DefineDynamicAssembly
- (assemblyName, AssemblyBuilderAccess::Save);
-
- // An assembly is made up of executable modules. For a single
- // module assembly, the module name and file name are the
- // same as the assembly name.
- ModuleBuilder^ moduleBuilder = assemblyBuilder->DefineDynamicModule
- (assemblyName->Name, assemblyName->Name + ".dll");
-
- // Define the sample type.
- TypeBuilder^ typeBuilder = moduleBuilder->DefineType("Sample",
- TypeAttributes::Public | TypeAttributes::Abstract);
-
- // Make the sample type a generic type, by defining a type
- // parameter T. All type parameters are defined at the same
- // time, by passing an array containing the type parameter
- // names.
- array^ typeParamNames = {"T"};
- array^ typeParams =
- typeBuilder->DefineGenericParameters(typeParamNames);
-
- // Define a method that takes a ByRef argument of type T, a
- // pointer to type T, and one-dimensional array of type T.
- // The method returns a two-dimensional array of type T.
- //
- // To create this method, you need Type objects that repre-
- // sent the parameter types and the return type. Use the
- // MakeByRefType, MakePointerType, and MakeArrayType methods
- // to create the Type objects, using the generic type para-
- // meter T.
- //
- Type^ byRefType = typeParams[0]->MakeByRefType();
- Type^ pointerType = typeParams[0]->MakePointerType();
- Type^ arrayType = typeParams[0]->MakeArrayType();
- Type^ twoDimArrayType = typeParams[0]->MakeArrayType(2);
-
- // Create the array of parameter types.
- array^ parameterTypes = {byRefType, pointerType, arrayType};
-
- // Define the abstract Test method. After you have compiled
- // and run this example code, you can use ildasm.exe to open
- // MakeXxxGenericTypeParameterExample.dll, examine the Sample
- // type, and verify the parameter types and return type of
- // the TestMethod method.
- //
- MethodBuilder^ methodBuilder = typeBuilder->DefineMethod("TestMethod",
- MethodAttributes::Abstract | MethodAttributes::Virtual
- | MethodAttributes::Public, twoDimArrayType, parameterTypes);
-
- // Create the type and save the assembly. For a single-file
- // assembly, there is only one module to store the manifest
- // information in.
- //
- typeBuilder->CreateType();
- assemblyBuilder->Save(assemblyName->Name + ".dll");
-};
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/MemberInfo_GetCustomAttribute_IsDefined/CPP/memberinfo_getcustomattribute_isdefined.cpp b/snippets/cpp/VS_Snippets_CLR/MemberInfo_GetCustomAttribute_IsDefined/CPP/memberinfo_getcustomattribute_isdefined.cpp
deleted file mode 100644
index 3586a67f36a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/MemberInfo_GetCustomAttribute_IsDefined/CPP/memberinfo_getcustomattribute_isdefined.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define a custom attribute with one named parameter.
-
-[AttributeUsage(AttributeTargets::All)]
-public ref class MyAttribute: public Attribute
-{
-private:
- String^ myName;
-
-public:
- MyAttribute( String^ name )
- {
- myName = name;
- }
-
- property String^ Name
- {
- String^ get()
- {
- return myName;
- }
- }
-};
-
-// Define a class that has the custom attribute associated with one of its members.
-public ref class MyClass1
-{
-public:
-
- [MyAttribute("This is an example attribute.")]
- void MyMethod( int i ){}
-};
-
-int main()
-{
- try
- {
- // Get the type of MyClass1.
- Type^ myType = MyClass1::typeid;
-
- // Get the members associated with MyClass1.
- array^myMembers = myType->GetMembers();
-
- // Display the attributes for each of the members of MyClass1.
- for ( int i = 0; i < myMembers->Length; i++ )
- {
- // Display the attribute if it is of type MyAttribute.
- if ( myMembers[ i ]->IsDefined( MyAttribute::typeid, false ) )
- {
- array^myAttributes = myMembers[ i ]->GetCustomAttributes( MyAttribute::typeid, false );
- Console::WriteLine( "\nThe attributes of type MyAttribute for the member {0} are: \n", myMembers[ i ] );
- for ( int j = 0; j < myAttributes->Length; j++ )
-
- // Display the value associated with the attribute.
- Console::WriteLine( "The value of the attribute is : \"{0}\"",
- (safe_cast(myAttributes[ j ]))->Name );
- }
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "An exception occurred: {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/MemberInfo_GetCustomAttributes1/CPP/memberinfo_getcustomattributes1.cpp b/snippets/cpp/VS_Snippets_CLR/MemberInfo_GetCustomAttributes1/CPP/memberinfo_getcustomattributes1.cpp
deleted file mode 100644
index 6153b2ffb03..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/MemberInfo_GetCustomAttributes1/CPP/memberinfo_getcustomattributes1.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define a custom attribute with one named parameter.
-
-[AttributeUsage(AttributeTargets::All)]
-public ref class MyAttribute: public Attribute
-{
-private:
- String^ myName;
-
-public:
- MyAttribute( String^ name )
- {
- myName = name;
- }
-
- property String^ Name
- {
- String^ get()
- {
- return myName;
- }
- }
-};
-
-// Define a class that has the custom attribute associated with one of its members.
-public ref class MyClass1
-{
-public:
-
- [MyAttribute("This is an example attribute.")]
- void MyMethod( int i )
- {
- return;
- }
-};
-
-int main()
-{
- try
- {
- // Get the type of MyClass1.
- Type^ myType = MyClass1::typeid;
-
- // Get the members associated with MyClass1.
- array^myMembers = myType->GetMembers();
-
- // Display the attributes for each of the members of MyClass1.
- for ( int i = 0; i < myMembers->Length; i++ )
- {
- array^myAttributes = myMembers[ i ]->GetCustomAttributes( true );
- if ( myAttributes->Length > 0 )
- {
- Console::WriteLine( "\nThe attributes for the member {0} are: \n", myMembers[ i ] );
- for ( int j = 0; j < myAttributes->Length; j++ )
- Console::WriteLine( "The type of the attribute is {0}.", myAttributes[ j ] );
- }
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "An exception occurred: {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/MethodBody/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/MethodBody/cpp/source.cpp
deleted file mode 100644
index 44d2576e6eb..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/MethodBody/cpp/source.cpp
+++ /dev/null
@@ -1,157 +0,0 @@
-// 1 - (entire sample) MethodBody class
-// 2 - (everything through GetMethodBody and displaying InitLocals & MaxStackSize)
-// 3 - (displaying locals)
-// 4 - (displaying exception clauses)
-// 5 - (end of Main, example method, beginning of output through output for snippet 2)
-// 6 - (output for snippet 3 (locals))
-// 7 - (output for snippet 4 (clauses))
-// 2,5 - InitLocals, MaxStackSize
-// 2,3,5,6 - lvis property, lviInfo class
-// 2,4,5,7 - ExceptionHandlingClauses property, ExceptionHandlingClause class, ExceptionHandlingClauseFlags enum
-//
-//
-//
-#using
-
-using namespace System;
-using namespace System::Reflection;
-
-public ref class Example
-{
- //
- // The Main method contains code to analyze this method, using
- // the properties and methods of the MethodBody class.
-public:
- void MethodBodyExample(Object^ arg)
- {
- // Define some local variables. In addition to these variables,
- // the local variable list includes the variables scoped to
- // the catch clauses.
- int var1 = 42;
- String^ var2 = "Forty-two";
-
- try
- {
- // Depending on the input value, throw an ArgumentException or
- // an ArgumentNullException to test the Catch clauses.
- if (arg == nullptr)
- {
- throw gcnew ArgumentNullException("The argument cannot " +
- "be null.");
- }
- if (arg->GetType() == String::typeid)
- {
- throw gcnew ArgumentException("The argument cannot " +
- "be a string.");
- }
- }
-
- // There is no Filter clause in this code example. See the Visual
- // Basic code for an example of a Filter clause.
-
- // This catch clause handles the ArgumentException class, and
- // any other class derived from Exception.
- catch (ArgumentException^ ex)
- {
- Console::WriteLine("Ordinary exception-handling clause caught:" +
- " {0}", ex->GetType());
- }
- finally
- {
- var1 = 3033;
- var2 = "Another string.";
- }
- }
- //
-};
-
-int main()
-{
- // Get method body information.
- MethodInfo^ mi =
- Example::typeid->GetMethod("MethodBodyExample");
-
- MethodBody^ mb = mi->GetMethodBody();
- Console::WriteLine("\r\nMethod: {0}", mi);
-
- // Display the general information included in the
- // MethodBody object.
- Console::WriteLine(" Local variables are initialized: {0}",
- mb->InitLocals);
- Console::WriteLine(" Maximum number of items on the operand " +
- "stack: {0}", mb->MaxStackSize);
- //
- //
-
- // Display information about the local variables in the
- // method body.
- Console::WriteLine();
- for each (LocalVariableInfo^ lvi in mb->LocalVariables)
- {
- Console::WriteLine("Local variable: {0}", lvi);
- }
- //
- //
-
- // Display exception handling clauses.
- Console::WriteLine();
- for each(ExceptionHandlingClause^ exhc in mb->ExceptionHandlingClauses)
- {
- Console::WriteLine(exhc->Flags.ToString());
-
- // The FilterOffset property is meaningful only for Filter
- // clauses. The CatchType property is not meaningful for
- // Filter or Finally clauses.
- switch(exhc->Flags)
- {
- case ExceptionHandlingClauseOptions::Filter:
- Console::WriteLine(" Filter Offset: {0}",
- exhc->FilterOffset);
- break;
- case ExceptionHandlingClauseOptions::Finally:
- break;
- default:
- Console::WriteLine(" Type of exception: {0}",
- exhc->CatchType);
- break;
- }
-
- Console::WriteLine(" Handler Length: {0}",
- exhc->HandlerLength);
- Console::WriteLine(" Handler Offset: {0}",
- exhc->HandlerOffset);
- Console::WriteLine(" Try Block Length: {0}", exhc->TryLength);
- Console::WriteLine(" Try Block Offset: {0}", exhc->TryOffset);
- }
- //
-}
-
-//This code example produces output similar to the following:
-//
-//Method: Void MethodBodyExample(System.Object)
-// Local variables are initialized: False
-// Maximum number of items on the operand stack: 4
-//
-//
-//Local variable: System.ArgumentException (0)
-//Local variable: System.String (1)
-//Local variable: System.Int32 (2)
-//
-//
-//Clause
-// Type of exception: System.ArgumentException
-// Handler Length: 29
-// Handler Offset: 78
-// Try Block Length: 65
-// Try Block Offset: 13
-//Finally
-// Handler Length: 13
-// Handler Offset: 113
-// Try Block Length: 100
-// Try Block Offset: 13
-//
-//
-
-
-
-
diff --git a/snippets/cpp/VS_Snippets_CLR/MethodBuilder.MakeGenericMethod/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/MethodBuilder.MakeGenericMethod/cpp/source.cpp
deleted file mode 100644
index 546d0961119..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/MethodBuilder.MakeGenericMethod/cpp/source.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-void main()
-{
- // Define a transient dynamic assembly (only to run, not
- // to save) with one module and a type "Test".
- //
- AssemblyName^ aName = gcnew AssemblyName("MyDynamic");
- AssemblyBuilder^ ab =
- AppDomain::CurrentDomain->DefineDynamicAssembly(
- aName,
- AssemblyBuilderAccess::Run);
- ModuleBuilder^ mb = ab->DefineDynamicModule(aName->Name);
- TypeBuilder^ tb = mb->DefineType("Test");
-
- // Add a public static method "M" to Test, and make it a
- // generic method with one type parameter named "T").
- //
- MethodBuilder^ meb = tb->DefineMethod("M",
- MethodAttributes::Public | MethodAttributes::Static);
- array^ typeParams =
- meb->DefineGenericParameters(gcnew array { "T" });
-
- // Give the method one parameter, of type T, and a
- // return type of T.
- meb->SetParameters(typeParams);
- meb->SetReturnType(typeParams[0]);
-
- // Create a MethodInfo for M, which can be used in
- // emitted code. This is possible even though the method
- // does not yet have a body, and the enclosing type is not
- // created.
- MethodInfo^ mi = meb->MakeGenericMethod(String::typeid);
- // Note that this is actually a subclass of MethodInfo,
- // which has rather limited capabilities -- for
- // example, you cannot reflect on its parameters.
-}
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR/MethodBuilderClass_TypeSample/CPP/methodbuilderclass.cpp b/snippets/cpp/VS_Snippets_CLR/MethodBuilderClass_TypeSample/CPP/methodbuilderclass.cpp
deleted file mode 100644
index f43a09ff0c7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/MethodBuilderClass_TypeSample/CPP/methodbuilderclass.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-
-// System.Reflection.Emit.MethodBuilder
-/*
-This program demonstrates 'MethodBuilder' class. A dynamic class 'myTypeBuilder'
-is created in which a constructor 'myConstructorBuilder' and a method 'myMethodBuilder'
-are created dynamically. Their IL's are generated. The Non-Public methods of the class
-are printed on the console. The attributes and signature of 'MyDynamicMethod' are displayed
-on the console using 'Attributes' and 'Signature' properties of the 'MethodBuilder' class.
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-int main()
-{
- try
- {
- // Get the current AppDomain.
- AppDomain^ myAppDomain = AppDomain::CurrentDomain;
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "MyDynamicAssembly";
-
- // Create the dynamic assembly and set its access mode to 'Save'.
- AssemblyBuilder^ myAssemblyBuilder = myAppDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Save );
-
- // Create a dynamic module 'myModuleBuilder'.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "MyDynamicModule", true );
-
- // Define a public class 'MyDynamicClass'.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyDynamicClass", TypeAttributes::Public );
-
- // Define a public string field named 'myField'.
- FieldBuilder^ myField = myTypeBuilder->DefineField( "MyDynamicField", String::typeid, FieldAttributes::Public );
-
- // Define the dynamic method 'MyDynamicMethod'.
- array^temp0 = gcnew array(0);
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyDynamicMethod", MethodAttributes::Private, int::typeid, temp0 );
-
- // Generate the IL for 'myMethodBuilder'.
- ILGenerator^ myMethodIL = myMethodBuilder->GetILGenerator();
-
- // Emit the necessary opcodes.
- myMethodIL->Emit( OpCodes::Ldarg_0 );
- myMethodIL->Emit( OpCodes::Ldfld, myField );
- myMethodIL->Emit( OpCodes::Ret );
-
- // Create 'myTypeBuilder' class.
- Type^ myType1 = myTypeBuilder->CreateType();
-
- // Get the method information of 'myTypeBuilder'.
- array^myInfo = myType1->GetMethods( static_cast(BindingFlags::NonPublic | BindingFlags::Instance) );
-
- // Print non-public methods present of 'myType1'.
- Console::WriteLine( "\nThe Non-Public methods present in 'myType1' are:\n" );
- for ( int i = 0; i < myInfo->Length; i++ )
- {
- Console::WriteLine( myInfo[ i ]->Name );
- }
- Console::WriteLine( "\nThe Attribute of 'MyDynamicMethod' is :{0}", myMethodBuilder->Attributes );
- Console::WriteLine( "\nThe Signature of 'MyDynamicMethod' is : \n{0}", myMethodBuilder->Signature );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception :{0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/MethodInfo.Generics/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/MethodInfo.Generics/cpp/source.cpp
deleted file mode 100644
index f2e621d6748..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/MethodInfo.Generics/cpp/source.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-//
-// Define a class with a generic method.
-ref class Example
-{
-public:
- generic static void Generic(T toDisplay)
- {
- Console::WriteLine("\r\nHere it is: {0}", toDisplay);
- }
-};
-//
-
-void DisplayGenericMethodInfo(MethodInfo^ mi)
-{
- Console::WriteLine("\r\n{0}", mi);
-
- //
- Console::WriteLine("\tIs this a generic method definition? {0}",
- mi->IsGenericMethodDefinition);
- //
-
- //
- Console::WriteLine("\tIs it a generic method? {0}",
- mi->IsGenericMethod);
- //
-
- //
- Console::WriteLine("\tDoes it have unassigned generic parameters? {0}",
- mi->ContainsGenericParameters);
- //
-
- //
- // If this is a generic method, display its type arguments.
- //
- if (mi->IsGenericMethod)
- {
- array^ typeArguments = mi->GetGenericArguments();
-
- Console::WriteLine("\tList type arguments ({0}):",
- typeArguments->Length);
-
- for each (Type^ tParam in typeArguments)
- {
- // IsGenericParameter is true only for generic type
- // parameters.
- //
- if (tParam->IsGenericParameter)
- {
- Console::WriteLine("\t\t{0} parameter position {1}" +
- "\n\t\t declaring method: {2}",
- tParam,
- tParam->GenericParameterPosition,
- tParam->DeclaringMethod);
- }
- else
- {
- Console::WriteLine("\t\t{0}", tParam);
- }
- }
- }
- //
-};
-
-void main()
-{
- Console::WriteLine("\r\n--- Examine a generic method.");
-
- //
- // Create a Type object representing class Example, and
- // get a MethodInfo representing the generic method.
- //
- Type^ ex = Example::typeid;
- MethodInfo^ mi = ex->GetMethod("Generic");
-
- DisplayGenericMethodInfo(mi);
-
- // Assign the int type to the type parameter of the Example
- // method.
- //
- MethodInfo^ miConstructed = mi->MakeGenericMethod(int::typeid);
-
- DisplayGenericMethodInfo(miConstructed);
- //
-
- // Invoke the method.
- array^ args = { 42 };
- miConstructed->Invoke((Object^) 0, args);
-
- // Invoke the method normally.
- Example::Generic(42);
-
- //
- // Get the generic type definition from the closed method,
- // and show it's the same as the original definition.
- //
- MethodInfo^ miDef = miConstructed->GetGenericMethodDefinition();
- Console::WriteLine("\r\nThe definition is the same: {0}",
- miDef == mi);
- //
-};
-
-/* This example produces the following output:
-
---- Examine a generic method.
-
-Void Generic[T](T)
- Is this a generic method definition? True
- Is it a generic method? True
- Does it have unassigned generic parameters? True
- List type arguments (1):
- T parameter position 0
- declaring method: Void Generic[T](T)
-
-Void Generic[Int32](Int32)
- Is this a generic method definition? False
- Is it a generic method? True
- Does it have unassigned generic parameters? False
- List type arguments (1):
- System.Int32
-
-Here it is: 42
-
-Here it is: 42
-
-The definition is the same: True
-
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_Class/CPP/modulebuilder.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_Class/CPP/modulebuilder.cpp
deleted file mode 100644
index f498738331b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_Class/CPP/modulebuilder.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-
-// System.Reflection.Emit.ModuleBuilder
-/*
-The following example demonstrates the 'ModuleBuilder' class.
-A dynamic assembly with a module in it is created in 'CodeGenerator' class.
-A run time class having a method and a field is created using the 'ModuleBuilder'
-class and created class is called from the 'TestClass'.
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-public ref class CodeGenerator
-{
-private:
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- CodeGenerator()
- {
- // Get the current application domain for the current thread.
- AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Define a dynamic assembly in the current application domain.
- myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Define a dynamic module in this assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
-
- // Define a runtime class with specified name and attributes.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
-
- // Add 'Greeting' field to the class, with the specified attribute and type.
- FieldBuilder^ greetingField = myTypeBuilder->DefineField( "Greeting", String::typeid, FieldAttributes::Public );
- array^myMethodArgs = {String::typeid};
-
- // Add 'MyMethod' method to the class, with the specified attribute and signature.
- MethodBuilder^ myMethod = myTypeBuilder->DefineMethod( "MyMethod", MethodAttributes::Public, CallingConventions::Standard, nullptr, myMethodArgs );
- ILGenerator^ methodIL = myMethod->GetILGenerator();
- methodIL->EmitWriteLine( "In the method..." );
- methodIL->Emit( OpCodes::Ldarg_0 );
- methodIL->Emit( OpCodes::Ldarg_1 );
- methodIL->Emit( OpCodes::Stfld, greetingField );
- methodIL->Emit( OpCodes::Ret );
- myTypeBuilder->CreateType();
- }
-
- property AssemblyBuilder^ MyAssembly
- {
- AssemblyBuilder^ get()
- {
- return this->myAssemblyBuilder;
- }
- }
-};
-
-int main()
-{
- CodeGenerator^ myCodeGenerator = gcnew CodeGenerator;
-
- // Get the assembly builder for 'myCodeGenerator' object.
- AssemblyBuilder^ myAssemblyBuilder = myCodeGenerator->MyAssembly;
-
- // Get the module builder for the above assembly builder object .
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->GetDynamicModule( "TempModule" );
- Console::WriteLine( "The fully qualified name and path to this module is :{0}", myModuleBuilder->FullyQualifiedName );
- Type^ myType = myModuleBuilder->GetType( "TempClass" );
- MethodInfo^ myMethodInfo = myType->GetMethod( "MyMethod" );
-
- // Get the token used to identify the method within this module.
- MethodToken myMethodToken = myModuleBuilder->GetMethodToken( myMethodInfo );
- Console::WriteLine( "Token used to identify the method of 'myType'"
- " within the module is {0:x}", myMethodToken.Token );
- array^args = {"Hello."};
- Object^ myObject = Activator::CreateInstance( myType, nullptr, nullptr );
- myMethodInfo->Invoke( myObject, args );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_CreateGlobalFunctions/CPP/modulebuilder_createglobalfunctions.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_CreateGlobalFunctions/CPP/modulebuilder_createglobalfunctions.cpp
deleted file mode 100644
index 3979e2356e6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_CreateGlobalFunctions/CPP/modulebuilder_createglobalfunctions.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// System.Reflection.Emit.ModuleBuilder.DefineGlobalMethod(String,MethodAttributes,Type,Type[])
-// System.Reflection.Emit.ModuleBuilder.CreateGlobalFunctions
-
-/*
-The following example demonstrates the 'DefineGlobalMethod(String,MethodAttributes,Type,Type[])'
-and 'CreateGlobalFunctions' methods of 'ModuleBuilder' class.
-A dynamic assembly with a module in it is created in 'CodeGenerator' class. Then a global method
-is created in the module using the 'DefineGlobalMethod' method. The global method is called from
-the 'CallerClass'.
-*/
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class CodeGenerator
-{
-private:
- ModuleBuilder^ myModuleBuilder;
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- CodeGenerator()
- {
- myModuleBuilder = nullptr;
- myAssemblyBuilder = nullptr;
-
- //
- //
- AppDomain^ currentDomain;
- AssemblyName^ myAssemblyName;
- MethodBuilder^ myMethodBuilder = nullptr;
- ILGenerator^ myILGenerator;
-
- // Get the current application domain for the current thread.
- currentDomain = AppDomain::CurrentDomain;
- myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Define a dynamic assembly in the 'currentDomain'.
- myAssemblyBuilder =
- currentDomain->DefineDynamicAssembly(
- myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Define a dynamic module in "TempAssembly" assembly.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
-
- // Define a global method in the 'TempModule' module.
- myMethodBuilder = myModuleBuilder->DefineGlobalMethod(
- "MyMethod1", (MethodAttributes)(MethodAttributes::Static | MethodAttributes::Public),
- nullptr, nullptr );
- myILGenerator = myMethodBuilder->GetILGenerator();
- myILGenerator->EmitWriteLine( "Hello World from global method." );
- myILGenerator->Emit( OpCodes::Ret );
-
- // Fix up the 'TempModule' module .
- myModuleBuilder->CreateGlobalFunctions();
- //
- //
- }
-
- property AssemblyBuilder^ MyAssembly
- {
- AssemblyBuilder^ get()
- {
- return this->myAssemblyBuilder;
- }
- }
-};
-
-int main()
-{
- CodeGenerator^ myGenerator = gcnew CodeGenerator;
- AssemblyBuilder^ myAssembly = myGenerator->MyAssembly;
- ModuleBuilder^ myBuilder = myAssembly->GetDynamicModule( "TempModule" );
- Console::WriteLine( "Invoking the global method..." );
- MethodInfo^ myMethodInfo = myBuilder->GetMethod( "MyMethod1" );
- myMethodInfo->Invoke( nullptr, nullptr );
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineEnum/CPP/modulebuilder_defineenum.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineEnum/CPP/modulebuilder_defineenum.cpp
deleted file mode 100644
index b40b5fe22cc..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineEnum/CPP/modulebuilder_defineenum.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-void main()
-{
- // Get the current application domain for the current thread.
- AppDomain^ currentDomain = AppDomain::CurrentDomain;
-
- // Create a dynamic assembly in the current application domain,
- // and allow it to be executed and saved to disk.
- AssemblyName^ aName = gcnew AssemblyName("TempAssembly");
- AssemblyBuilder^ ab = currentDomain->DefineDynamicAssembly(
- aName, AssemblyBuilderAccess::RunAndSave);
-
- // Define a dynamic module in "TempAssembly" assembly. For a single-
- // module assembly, the module has the same name as the assembly.
- ModuleBuilder^ mb =
- ab->DefineDynamicModule(aName->Name, aName->Name + ".dll");
-
- // Define a public enumeration with the name "Elevation" and an
- // underlying type of Int32.
- EnumBuilder^ eb =
- mb->DefineEnum("Elevation", TypeAttributes::Public, int::typeid);
-
- // Define two members, "High" and "Low".
- eb->DefineLiteral("Low", (Object^) 0);
- eb->DefineLiteral("High", 1);
-
- // Create the type and save the assembly.
- Type^ finished = eb->CreateType();
- ab->Save(aName->Name + ".dll");
-
- for each (Object^ o in Enum::GetValues(finished))
- {
- Console::WriteLine("{0}.{1} = {2}", finished, o, (int)o);
- }
-}
-
-/* This code example produces the following output:
-
-Elevation.Low = 0
-Elevation.High = 1
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineInitializedData/CPP/modulebuilder_defineinitializeddata.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineInitializedData/CPP/modulebuilder_defineinitializeddata.cpp
deleted file mode 100644
index d87da81e582..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineInitializedData/CPP/modulebuilder_defineinitializeddata.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-// System.Reflection.Emit.ModuleBuilder.DefineInitializedData
-
-/*
-The following example demonstrates the 'DefineInitializedData' method of
-'ModuleBuilder' class.
-A dynamic assembly with a module in it is created in 'CodeGenerator' class.
-A initialized data field is created using 'DefineInitializedData'
-method for creating the initialized data.
-*/
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class CodeGenerator
-{
-private:
- ModuleBuilder^ myModuleBuilder;
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- CodeGenerator()
- {
- //
- AppDomain^ currentDomain;
- AssemblyName^ myAssemblyName;
-
- // Get the current application domain for the current thread.
- currentDomain = AppDomain::CurrentDomain;
- myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Define a dynamic assembly in the 'currentDomain'.
- myAssemblyBuilder =
- currentDomain->DefineDynamicAssembly(
- myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Define a dynamic module in "TempAssembly" assembly.
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
-
- // Define the initialized data field in the .sdata section of the PE file.
- array^ temp0 = {01,00,01};
- FieldBuilder^ myFieldBuilder =
- myModuleBuilder->DefineInitializedData( "MyField", temp0,
- (FieldAttributes)(FieldAttributes::Static | FieldAttributes::Public) );
- myModuleBuilder->CreateGlobalFunctions();
- //
- }
-
- property AssemblyBuilder^ MyAssembly
- {
- AssemblyBuilder^ get()
- {
- return this->myAssemblyBuilder;
- }
- }
-};
-
-int main()
-{
- CodeGenerator^ myGenerator = gcnew CodeGenerator;
- AssemblyBuilder^ myAssembly = myGenerator->MyAssembly;
- ModuleBuilder^ myBuilder = myAssembly->GetDynamicModule( "TempModule" );
- FieldInfo^ myInfo = myBuilder->GetField( "MyField" );
- Console::WriteLine( "The name of the initialized data field is :" + myInfo->Name );
- Console::WriteLine( "The object having the field value is :" + myInfo->GetValue( myBuilder ) );
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefinePInvokeMethod1/CPP/modulebuilder_definepinvokemethod1.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefinePInvokeMethod1/CPP/modulebuilder_definepinvokemethod1.cpp
deleted file mode 100644
index 3e81dcf0345..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefinePInvokeMethod1/CPP/modulebuilder_definepinvokemethod1.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-// System.Reflection.Emit.ModuleBuilder.DefinePInvokeMethod(String,String,MethodAttributes,
-// CallingConventions,Type,Type[],CallingConvention,CharSet)
-/*
- The following example demonstrates that DefinePInvokeMethod doesn't work unless you
- add a DLLImportAttribute...which you can do just as well with DefineGlobalMethod.
-
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Runtime::InteropServices;
-
-const int MB_RETRYCANCEL = 5;
-
-void main()
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName("TempAssembly");
-
- // Define a dynamic assembly in the current application domain.
- AssemblyBuilder^ myAssemblyBuilder =
- AppDomain::CurrentDomain->DefineDynamicAssembly(
- myAssemblyName, AssemblyBuilderAccess::Run);
-
- // Define a dynamic module in "TempAssembly" assembly.
- ModuleBuilder^ myModuleBuilder =
- myAssemblyBuilder->DefineDynamicModule("TempModule");
-
- array^ paramTypes =
- { int::typeid, String::typeid, String::typeid, int::typeid };
-
- // Define a PInvoke method.
- MethodBuilder^ piMethodBuilder = myModuleBuilder->DefinePInvokeMethod(
- "MessageBoxA",
- "user32.dll",
- MethodAttributes::Public | MethodAttributes::Static | MethodAttributes::PinvokeImpl,
- CallingConventions::Standard,
- int::typeid,
- paramTypes,
- CallingConvention::Winapi,
- CharSet::Ansi);
-
- // Add PreserveSig to the method implementation flags. NOTE: If this line
- // is commented out, the return value will be zero when the method is
- // invoked.
- piMethodBuilder->SetImplementationFlags(
- piMethodBuilder->GetMethodImplementationFlags() | MethodImplAttributes::PreserveSig);
-
- // Create global methods.
- myModuleBuilder->CreateGlobalFunctions();
-
- // Arguments for calling the method.
- array^ arguments =
- { (Object^)(int) 0, "Hello World", "Title", MB_RETRYCANCEL };
-
- MethodInfo^ pinvokeMethod = myModuleBuilder->GetMethod("MessageBoxA");
- Console::WriteLine("Testing module-level PInvoke method created with DefinePInvokeMethod...");
- Console::WriteLine("Message box returned: {0}",
- pinvokeMethod->Invoke(nullptr, arguments));
-};
-
-
-/* This code example produces input similar to the following:
-
-Testing module-level PInvoke method created with DefinePInvokeMethod...
-Message box returned: 4
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineResource1/CPP/modulebuilder_defineresource1.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineResource1/CPP/modulebuilder_defineresource1.cpp
deleted file mode 100644
index 8cbc472c421..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineResource1/CPP/modulebuilder_defineresource1.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-
-// System::Reflection::Emit::ModuleBuilder.DefineResource(String, String)
-/*
-The following example demonstrates the 'DefineResource(String, String)' method
-of 'ModuleBuilder' class.
-A dynamic assembly with a module in it is created in 'CodeGenerator' class.
-Then a managed resource is defined in the module using the 'DefineResource'
-method.
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Resources;
-public ref class CodeGenerator
-{
-public:
- CodeGenerator()
- {
-
- // Get the current application domain for the current thread.
- AppDomain^ currentDomain = AppDomain::CurrentDomain;
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Define 'TempAssembly' assembly in the current application domain.
- AssemblyBuilder^ myAssemblyBuilder = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Define 'TempModule' module in 'TempAssembly' assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule", "TempModule.netmodule", true );
-
- // Define the managed embedded resource, 'MyResource' in 'TempModule'.
- IResourceWriter^ myResourceWriter = myModuleBuilder->DefineResource( "MyResource.resource", "Description" );
-
- // Add resources to the resource writer.
- myResourceWriter->AddResource( "String 1", "First String" );
- myResourceWriter->AddResource( "String 2", "Second String" );
- myResourceWriter->AddResource( "String 3", "Third String" );
- myAssemblyBuilder->Save( "MyAssembly.dll" );
- }
-
-};
-
-int main()
-{
- CodeGenerator^ myGenerator = gcnew CodeGenerator;
- Console::WriteLine( "A resource named 'MyResource.resource' has been created and can be viewed in the 'MyAssembly.dll'" );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineResource2/CPP/modulebuilder_defineresource2.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineResource2/CPP/modulebuilder_defineresource2.cpp
deleted file mode 100644
index 5caa523989d..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_DefineResource2/CPP/modulebuilder_defineresource2.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-
-// System::Reflection::Emit::ModuleBuilder.DefineResource(String, String, ResourceAttributes)
-/*
-The following example demonstrates the 'DefineResource(String, String, ResourceAttributes)'
-method of 'ModuleBuilder' class.
-A dynamic assembly with a module in it is created in 'CodeGenerator' class.
-Then a managed resource is defined in the module using the 'DefineResource' method.
-*/
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Resources;
-public ref class CodeGenerator
-{
-public:
- CodeGenerator()
- {
-
- // Get the current application domain for the current thread.
- AppDomain^ currentDomain = AppDomain::CurrentDomain;
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Define 'TempAssembly' assembly in the current application domain.
- AssemblyBuilder^ myAssemblyBuilder = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Define 'TempModule' module in 'TempAssembly' assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule", "TempModule.netmodule", true );
-
- // Define the managed embedded resource, 'MyResource' in 'TempModule'
- // with the specified attribute.
- IResourceWriter^ writer = myModuleBuilder->DefineResource( "MyResource.resource", "Description", ResourceAttributes::Public );
-
- // Add resources to the resource writer.
- writer->AddResource( "String 1", "First String" );
- writer->AddResource( "String 2", "Second String" );
- writer->AddResource( "String 3", "Third String" );
- myAssemblyBuilder->Save( "MyAssembly.dll" );
- }
-
-};
-
-int main()
-{
- CodeGenerator^ myGenerator = gcnew CodeGenerator;
- Console::WriteLine( "A resource named 'MyResource::resource' has been created and can be viewed in the 'MyAssembly.dll'" );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_GetArrayMethod/CPP/modulebuilder_getarraymethod.cpp b/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_GetArrayMethod/CPP/modulebuilder_getarraymethod.cpp
deleted file mode 100644
index 574e5fa1686..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ModuleBuilder_GetArrayMethod/CPP/modulebuilder_getarraymethod.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-// System.Reflection.Emit.ModuleBuilder.GetArrayMethod
-// System.Reflection.Emit.ModuleBuilder.GetArrayMethodToken
-
-/*
-The following example demonstrates 'GetArrayMethod' and 'GetArrayMethodToken'
-methods of 'ModuleBuilder' class.
-A dynamic assembly with a module having a runtime class, 'TempClass' is created.
-This class defines a method, 'SortArray', which sorts the elements of the array
-passed to it. The 'GetArrayMethod' method is used to obtain the 'MethodInfo' object
-corresponding to the 'Sort' method of the 'Array'. The token used to identify the 'Sort'
-method in dynamic module is displayed using 'GetArrayMethodToken' method.
-*/
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class CodeGenerator
-{
-private:
- AssemblyBuilder^ myAssemblyBuilder;
-
-public:
- CodeGenerator()
- {
- AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "TempAssembly";
-
- // Define a dynamic assembly in the current application domain.
- myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
-//
-//
- // Define a dynamic module in "TempAssembly" assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->
- DefineDynamicModule( "TempModule" );
-
- // Define a runtime class with specified name and attributes.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType(
- "TempClass", TypeAttributes::Public );
- array^ paramArray = { Array::typeid };
- // Add 'SortArray' method to the class, with the given signature.
- MethodBuilder^ myMethod = myTypeBuilder->DefineMethod( "SortArray",
- MethodAttributes::Public, Array::typeid, paramArray );
-
- array^ myArrayClass = gcnew array( 1 );
- array^ parameterTypes = { Array::typeid };
- // Get the 'MethodInfo' object corresponding to 'Sort' method of 'Array' class.
- MethodInfo^ myMethodInfo = myModuleBuilder->GetArrayMethod(
- myArrayClass->GetType(), "Sort", CallingConventions::Standard,
- nullptr, parameterTypes );
-
- // Get the token corresponding to 'Sort' method of 'Array' class.
- MethodToken myMethodToken = myModuleBuilder->GetArrayMethodToken(
- myArrayClass->GetType(), "Sort", CallingConventions::Standard,
- nullptr, parameterTypes );
- Console::WriteLine( "Token used by module to identify the 'Sort' method"
- + " of 'Array' class is : {0:x} ", myMethodToken.Token );
-
- ILGenerator^ methodIL = myMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldarg_1 );
- methodIL->Emit( OpCodes::Call, myMethodInfo );
- methodIL->Emit( OpCodes::Ldarg_1 );
- methodIL->Emit( OpCodes::Ret );
-
- // Complete the creation of type.
- myTypeBuilder->CreateType();
- //
- //
- }
-
- property AssemblyBuilder^ MyBuilder
- {
- AssemblyBuilder^ get()
- {
- return this->myAssemblyBuilder;
- }
- }
-};
-
-int main()
-{
- CodeGenerator^ myCodeGenerator = gcnew CodeGenerator;
- AssemblyBuilder^ myAssemblyBuilder = myCodeGenerator->MyBuilder;
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->
- GetDynamicModule( "TempModule" );
- Type^ myType = myModuleBuilder->GetType( "TempClass" );
- Object^ myObject = Activator::CreateInstance( myType );
- MethodInfo^ sortArray = myType->GetMethod( "SortArray" );
- if ( nullptr != sortArray )
- {
- array^ arrayToSort = {"I","am","not","sorted"};
- Console::WriteLine( "Array elements before sorting " );
- for ( int i = 0; i < arrayToSort->Length; i++ )
- {
- Console::WriteLine( "Array element {0} : {1} ", i, arrayToSort[ i ] );
- }
- array^arguments = {arrayToSort};
- Console::WriteLine( "Invoking our dynamically "
- + "created SortArray method..." );
- Object^ myOutput = sortArray->Invoke( myObject, arguments );
- array^ mySortedArray = ( array^ )myOutput;
- Console::WriteLine( "Array elements after sorting " );
- for ( int i = 0; i < mySortedArray->Length; i++ )
- {
- Console::WriteLine( "Array element {0} : {1} ", i, mySortedArray[ i ] );
- }
- }
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_Attributes1/CPP/parameterinfo_attributes1.cpp b/snippets/cpp/VS_Snippets_CLR/ParameterInfo_Attributes1/CPP/parameterinfo_attributes1.cpp
deleted file mode 100644
index a0934b9b3d7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_Attributes1/CPP/parameterinfo_attributes1.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-
-// System::Reflection::ParameterInfo::Attributes
-/*
- The following example displays the attributes associated with the
- parameters of the method called 'MyMethod' of class 'ParameterInfo_Example'.
- */
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::InteropServices;
-public ref class MyClass1
-{
-public:
- int MyMethod( int i, [Out]short * j, long * k )
- {
- *j = 2;
- return 0;
- }
-
-};
-
-void main()
-{
- // Get the type.
- Type^ myType = MyClass1::typeid;
-
- // Get the method named 'MyMethod' from the type.
- MethodBase^ myMethodBase = myType->GetMethod( "MyMethod" );
-
- // Get the parameters associated with the method.
- array^myParameters = myMethodBase->GetParameters();
- Console::WriteLine( "\nThe method {0} has the {1} parameters :", "ParameterInfo_Example::MyMethod", myParameters->Length );
-
- // Print the attributes associated with each of the parameters.
- for ( int i = 0; i < myParameters->Length; i++ )
- Console::WriteLine( "\tThe {0} parameter has the attribute : {1}", i + 1, myParameters[ i ]->Attributes );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_GetCustomAttribute_IsDefined/CPP/ParameterInfo_GetCustomAttribute_IsDefined.cpp b/snippets/cpp/VS_Snippets_CLR/ParameterInfo_GetCustomAttribute_IsDefined/CPP/ParameterInfo_GetCustomAttribute_IsDefined.cpp
deleted file mode 100644
index 06e6497934c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_GetCustomAttribute_IsDefined/CPP/ParameterInfo_GetCustomAttribute_IsDefined.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-//
-// System::Reflection::ParameterInfo::GetCustomAttributes(Type, bool)
-// System::Reflection::ParameterInfo::IsDefined(Type, bool)
-using namespace System;
-using namespace System::Reflection;
-
-// Define a custom attribute with one named parameter.
-[AttributeUsage(AttributeTargets::Parameter)]
-public ref class MyAttribute: public Attribute
-{
-private:
- String^ myName;
-
-public:
- MyAttribute( String^ name )
- {
- myName = name;
- }
-
- property String^ Name
- {
- String^ get()
- {
- return myName;
- }
- }
-};
-
-// Derive another custom attribute from MyAttribute.
-[AttributeUsage(AttributeTargets::Parameter)]
-public ref class MyDerivedAttribute: public MyAttribute
-{
-public:
- MyDerivedAttribute( String^ name ) : MyAttribute( name ) {}
-};
-
-// Define a class with a method that has three parameters. Apply
-// MyAttribute to one parameter, MyDerivedAttribute to another, and
-// no attributes to the third.
-public ref class MyClass1
-{
-public:
- void MyMethod( [MyAttribute("This is an example parameter attribute")]
- int i,
- [MyDerivedAttribute("This is another parameter attribute")]
- int j,
- int k ){}
-};
-
-void main()
-{
- // Get the type of the class 'MyClass1'.
- Type^ myType = MyClass1::typeid;
-
- // Get the members associated with the class 'MyClass1'.
- array^myMethods = myType->GetMethods();
-
- // For each method of the class 'MyClass1', display all the parameters
- // to which MyAttribute or its derived types have been applied.
- for each ( MethodInfo^ mi in myMethods )
- {
- // Get the parameters for the method.
- array^ myParameters = mi->GetParameters();
- if ( myParameters->Length > 0 )
- {
- Console::WriteLine("\nThe following parameters of {0} have MyAttribute or a derived type:", mi);
- for each ( ParameterInfo^ pi in myParameters)
- {
- if (pi->IsDefined(MyAttribute::typeid, false))
- {
- Console::WriteLine("Parameter {0}, name = {1}, type = {2}",
- pi->Position, pi->Name, pi->ParameterType);
- }
- }
- }
- }
-}
-
-/* This code example produces the following output:
-
-The following parameters of Void MyMethod(Int32, Int32, Int32) have MyAttribute or a derived type:
-Parameter 0, name = i, type = System.Int32
-Parameter 1, name = j, type = System.Int32
-
-The following parameters of Boolean Equals(System.Object) have MyAttribute or a derived type:
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_GetCustomAttributes/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR/ParameterInfo_GetCustomAttributes/CPP/source.cpp
deleted file mode 100644
index f864dfbd878..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_GetCustomAttributes/CPP/source.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define a custom attribute with one named parameter.
-[AttributeUsage(AttributeTargets::Parameter)]
-public ref class MyAttribute: public Attribute
-{
-private:
- String^ myName;
-
-public:
- MyAttribute( String^ name )
- {
- myName = name;
- }
-
- property String^ Name
- {
- String^ get()
- {
- return myName;
- }
- }
-};
-
-// Define a class which has a custom attribute associated with one of the
-// parameters of a method.
-public ref class MyClass1
-{
-public:
- void MyMethod(
- [MyAttribute("This is an example parameter attribute")]
- int i ) {}
-};
-
-void main()
-{
- // Get the type of the class 'MyClass1'.
- Type^ myType = MyClass1::typeid;
-
- // Get the members associated with the class 'MyClass1'.
- array^myMethods = myType->GetMethods();
-
- // Display the attributes for each of the parameters of each method of the class 'MyClass1'.
- for ( int i = 0; i < myMethods->Length; i++ )
- {
- // Get the parameters for the method.
- array^myParameters = myMethods[ i ]->GetParameters();
-
- if ( myParameters->Length > 0 )
- {
- Console::WriteLine( "\nThe parameters for the method \"{0}\" that have custom attributes are:", myMethods[ i ] );
- for ( int j = 0; j < myParameters->Length; j++ )
- {
- // Get the attributes of type 'MyAttribute' for each parameter.
- array^myAttributes = myParameters[ j ]->GetCustomAttributes( MyAttribute::typeid, false );
-
- if ( myAttributes->Length > 0 )
- {
- Console::WriteLine( "Parameter {0}, name = {1}, type = {2} has attributes:",
- myParameters[ j ]->Position,
- myParameters[ j ]->Name,
- myParameters[ j ]->ParameterType );
- for ( int k = 0; k < myAttributes->Length; k++ )
- {
- Console::WriteLine( "\t{0}", myAttributes[ k ] );
- }
- }
- }
- }
- }
-}
-/* This code example produces the following output:
-
-The parameters for the method Void MyMethod(Int32) that have custom attributes are :
-Parameter 0, name = i, type = System.Int32 has attributes:
- MyAttribute
-
-The parameters for the method Boolean Equals(System.Object) that have custom attributes are :
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_IsIn_IsOut_IsOptional/CPP/ParameterInfo_IsIn_IsOut_IsOptional.cpp b/snippets/cpp/VS_Snippets_CLR/ParameterInfo_IsIn_IsOut_IsOptional/CPP/ParameterInfo_IsIn_IsOut_IsOptional.cpp
deleted file mode 100644
index c568d6441a6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/ParameterInfo_IsIn_IsOut_IsOptional/CPP/ParameterInfo_IsIn_IsOut_IsOptional.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-
-// System::Reflection::ParameterInfo::IsIn
-// System::Reflection::ParameterInfo::IsOptional
-// System::Reflection::ParameterInfo::IsOut
-/*
-The following program creates a dynamic assembly named 'MyAssembly', defines a
-module named 'MyModule' within the assembly. It defines a type called 'MyType'
-within the module and also defines a static method named 'MyMethod' for the
-type. This dynamic assembly is then queried for the type defined within it and
-then the attributes of all the parameters of the method named 'MyMethod' is
-displayed.
-*/
-//
-//
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Threading;
-using namespace System::Reflection::Emit;
-void DefineMethod()
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "MyAssembly";
-
- // Get the assembly builder from the application domain associated with the current thread.
- AssemblyBuilder^ myAssemblyBuilder = Thread::GetDomain()->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
-
- // Create a dynamic module in the assembly.
- ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "MyModule", "MyAssembly.dll" );
-
- // Create a type in the module.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyType" );
-
- // Create a method called MyMethod.
- array^type1 = {int::typeid,short::typeid,long::typeid};
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyMethod", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::Static), String::typeid, type1 );
-
- // Set the attributes for the parameters of the method.
- // Set the attribute for the first parameter to IN.
- ParameterBuilder^ myParameterBuilder = myMethodBuilder->DefineParameter( 1, ParameterAttributes::In, "MyIntParameter" );
-
- // Set the attribute for the second parameter to OUT.
- myParameterBuilder = myMethodBuilder->DefineParameter( 2, ParameterAttributes::Out, "MyShortParameter" );
-
- // Set the attribute for the third parameter to OPTIONAL.
- myParameterBuilder = myMethodBuilder->DefineParameter( 3, static_cast(ParameterAttributes::Optional | ParameterAttributes::HasDefault), "MyLongParameter" );
-
- // Get the Microsoft Intermediate Language generator for the method.
- ILGenerator^ myILGenerator = myMethodBuilder->GetILGenerator();
-
- // Use the utility method to generate the MSIL instructions that print a String* to the console.
- myILGenerator->EmitWriteLine( "Hello World!" );
-
- // Generate the S"ret" MSIL instruction.
- myILGenerator->Emit( OpCodes::Ret );
-
- // End the creation of the type.
- myTypeBuilder->CreateType();
-}
-
-int main()
-{
- // Create a dynamic assembly with a type named MyType.
- DefineMethod();
-
- // Get the assemblies currently loaded in the application domain.
- array^myAssemblies = Thread::GetDomain()->GetAssemblies();
- Assembly^ myAssembly = nullptr;
-
- // Get the assembly named MyAssembly.
- for ( int i = 0; i < myAssemblies->Length; i++ )
- if ( String::Compare( myAssemblies[ i ]->GetName( false )->Name, "MyAssembly" ) == 0 )
- myAssembly = myAssemblies[ i ];
-
- if ( myAssembly != nullptr )
- {
- // Get a type named MyType.
- Type^ myType = myAssembly->GetType( "MyType" );
-
- // Get a method named MyMethod from the type.
- MethodBase^ myMethodBase = myType->GetMethod( "MyMethod" );
-
- // Get the parameters associated with the method.
- array^myParameters = myMethodBase->GetParameters();
- Console::WriteLine( "\nThe method {0} has the {1} parameters :", myMethodBase, myParameters->Length );
-
- // Print the IN, OUT and OPTIONAL attributes associated with each of the parameters.
- for ( int i = 0; i < myParameters->Length; i++ )
- {
- if ( myParameters[ i ]->IsIn )
- Console::WriteLine( "\tThe {0} parameter has the In attribute", i + 1 );
- if ( myParameters[ i ]->IsOptional )
- Console::WriteLine( "\tThe {0} parameter has the Optional attribute", i + 1 );
- if ( myParameters[ i ]->IsOut )
- Console::WriteLine( "\tThe {0} parameter has the Out attribute", i + 1 );
- }
- }
- else
- Console::WriteLine( "Could not find a assembly named 'MyAssembly' for the current application domain" );
-}
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/PropertyBuilder_SetGetMethod_4/CPP/propertybuilder_setgetmethod_4.cpp b/snippets/cpp/VS_Snippets_CLR/PropertyBuilder_SetGetMethod_4/CPP/propertybuilder_setgetmethod_4.cpp
deleted file mode 100644
index f64e0f64c9b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/PropertyBuilder_SetGetMethod_4/CPP/propertybuilder_setgetmethod_4.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-
-// System.Reflection.Emit.PropertyBuilder.SetGetMethod
-// System.Reflection.Emit.PropertyBuilder.SetSetMethod
-// System.Reflection.Emit.PropertyBuilder.AddOtherMethod
-// System.Reflection.Emit.PropertyBuilder
-/*
-This following program demonstrates methods 'SetGetMethod','SetSetMethod' and
-'AddOtherMethod' of class 'PropertyBuilder'.
-
-A dynamic assembly is generated with a class having a property 'Greeting'.
-Its 'get' and 'set' method are created by returning and setting a string respectively.
-This property value is reset with default string using othermethod.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-// Create the callee transient dynamic assembly.
-Type^ CreateCallee( AppDomain^ myAppDomain, AssemblyBuilderAccess access )
-{
- // Create a simple name for the callee assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Create the callee dynamic assembly.
- AssemblyBuilder^ myAssemblyBuilder = myAppDomain->DefineDynamicAssembly( myAssemblyName, access );
-
- // Create a dynamic module named "EmittedModule" in the callee assembly.
- ModuleBuilder^ myModule;
- if ( access == AssemblyBuilderAccess::Run )
- {
- myModule = myAssemblyBuilder->DefineDynamicModule( "EmittedModule" );
- }
- else
- {
- myModule = myAssemblyBuilder->DefineDynamicModule( "EmittedModule", "EmittedModule.mod" );
- }
-
- //
- TypeBuilder^ helloWorldTypeBuilder = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
-
- // Define a private String field named "m_greeting" in "HelloWorld" class.
- FieldBuilder^ greetingFieldBuilder = helloWorldTypeBuilder->DefineField( "m_greeting", String::typeid, FieldAttributes::Private );
-
- // Create constructor args and define constructor.
- array^constructorArgs = {String::typeid};
- ConstructorBuilder^ constructor = helloWorldTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, constructorArgs );
-
- // Generate IL code for the method. The constructor stores its argument in the private field.
- ILGenerator^ constructorIL = constructor->GetILGenerator();
- constructorIL->Emit( OpCodes::Ldarg_0 );
- constructorIL->Emit( OpCodes::Ldarg_1 );
- constructorIL->Emit( OpCodes::Stfld, greetingFieldBuilder );
- constructorIL->Emit( OpCodes::Ret );
-
- //
- // Define property Greeting.
- PropertyBuilder^ greetingPropertyBuilder = helloWorldTypeBuilder->DefineProperty( "Greeting", PropertyAttributes::None, String::typeid, nullptr );
-
- // Define the 'get_Greeting' method.
- MethodBuilder^ getGreetingMethod = helloWorldTypeBuilder->DefineMethod( "get_Greeting", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::SpecialName), String::typeid, nullptr );
-
- // Generate IL code for 'get_Greeting' method.
- ILGenerator^ methodIL = getGreetingMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldarg_0 );
- methodIL->Emit( OpCodes::Ldfld, greetingFieldBuilder );
- methodIL->Emit( OpCodes::Ret );
- greetingPropertyBuilder->SetGetMethod( getGreetingMethod );
- //
-
-
- // Define the set_Greeting method.
- array^methodArgs = {String::typeid};
- MethodBuilder^ setGreetingMethod = helloWorldTypeBuilder->DefineMethod( "set_Greeting", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig | MethodAttributes::SpecialName), void::typeid, methodArgs );
-
- // Generate IL code for set_Greeting method.
- methodIL = setGreetingMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldarg_0 );
- methodIL->Emit( OpCodes::Ldarg_1 );
- methodIL->Emit( OpCodes::Stfld, greetingFieldBuilder );
- methodIL->Emit( OpCodes::Ret );
- greetingPropertyBuilder->SetSetMethod( setGreetingMethod );
- //
-
- //
- // Define the reset_Greeting method.
- MethodBuilder^ otherGreetingMethod = helloWorldTypeBuilder->DefineMethod( "reset_Greeting", static_cast(MethodAttributes::Public | MethodAttributes::HideBySig), void::typeid, nullptr );
-
- // Generate IL code for reset_Greeting method.
- methodIL = otherGreetingMethod->GetILGenerator();
- methodIL->Emit( OpCodes::Ldarg_0 );
- methodIL->Emit( OpCodes::Ldstr, "Default String." );
- methodIL->Emit( OpCodes::Stfld, greetingFieldBuilder );
- methodIL->Emit( OpCodes::Ret );
- greetingPropertyBuilder->AddOtherMethod( otherGreetingMethod );
- //
-
- // Create the class HelloWorld.
- return (helloWorldTypeBuilder->CreateType());
-}
-
-int main()
-{
- // Create the "HelloWorld" type in an assembly with mode 'RunAndSave'.
- Type^ helloWorldType = CreateCallee( Thread::GetDomain(), AssemblyBuilderAccess::RunAndSave );
-
- // Create an instance of the "HelloWorld" class.
- array^temp0 = {"HelloWorld"};
- Object^ helloWorld = Activator::CreateInstance( helloWorldType, temp0 );
- Object^ returnValue = helloWorldType->InvokeMember( "Greeting", static_cast(BindingFlags::Default | BindingFlags::GetProperty), nullptr, helloWorld, nullptr );
- Console::WriteLine( "HelloWorld.GetGreeting returned: \"{0}\"", returnValue );
-
- // Set 'Greeting' property with 'NewMessage!!!'.
- array^temp1 = {"New Message !!!"};
- helloWorldType->InvokeMember( "Greeting", static_cast(BindingFlags::Default | BindingFlags::SetProperty), nullptr, helloWorld, temp1 );
- returnValue = helloWorldType->InvokeMember( "Greeting", static_cast(BindingFlags::Default | BindingFlags::GetProperty), nullptr, helloWorld, nullptr );
- Console::WriteLine( "After Set operation HelloWorld.GetGreeting returned: \"{0}\"", returnValue );
-
- // Reset 'Greeting' property to 'Default String'.
- helloWorldType->InvokeMember( "reset_Greeting", static_cast(BindingFlags::Default | BindingFlags::InvokeMethod), nullptr, helloWorld, nullptr );
- returnValue = helloWorldType->InvokeMember( "Greeting", static_cast(BindingFlags::Default | BindingFlags::GetProperty), nullptr, helloWorld, nullptr );
- Console::WriteLine( "After Reset operation HelloWorld.GetGreeting returned: \"{0}\"", returnValue );
- AssemblyBuilder^ myAssembly = dynamic_cast(helloWorldType->Assembly);
-
- // Save to disk.
- myAssembly->Save( "EmittedAssembly.dll" );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/PropertyInfo.SetValue/cpp/Example.cpp b/snippets/cpp/VS_Snippets_CLR/PropertyInfo.SetValue/cpp/Example.cpp
deleted file mode 100644
index 3ec2d28a977..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/PropertyInfo.SetValue/cpp/Example.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Collections::Generic;
-
-ref class Example
-{
-private:
- int static _sharedProperty = 41;
- int _instanceProperty;
- Dictionary^ _indexedInstanceProperty;
-
-public:
- Example()
- {
- _instanceProperty = 42;
- _indexedInstanceProperty = gcnew Dictionary();
- };
-
- static property int SharedProperty
- {
- int get() { return _sharedProperty; }
- void set(int value) { _sharedProperty = value; }
- };
-
- property int InstanceProperty
- {
- int get() { return _instanceProperty; }
- void set(int value) { _instanceProperty = value; }
- };
-
- // By default, the name of the default indexed property (class
- // indexer) is Item, and that name must be used to search for the
- // property with reflection. The property can be given a different
- // name by using the IndexerNameAttribute attribute.
- property String^ default[int]
- {
- String^ get(int key)
- {
- String^ returnValue;
- if (_indexedInstanceProperty->TryGetValue(key, returnValue))
- {
- return returnValue;
- }
- else
- {
- return nullptr;
- }
- }
- void set(int key, String^ value)
- {
- if (value == nullptr)
- {
- throw gcnew ArgumentNullException(
- "IndexedInstanceProperty value can be an empty string, but it cannot be null.");
- }
- else
- {
- if (_indexedInstanceProperty->ContainsKey(key))
- {
- _indexedInstanceProperty[key] = value;
- }
- else
- {
- _indexedInstanceProperty->Add(key, value);
- }
- }
- }
- };
-};
-
-void main()
-{
- Console::WriteLine("Initial value of class-level property: {0}",
- Example::SharedProperty);
-
- PropertyInfo^ piShared =
- Example::typeid->GetProperty("SharedProperty");
- piShared->SetValue(nullptr, 76, nullptr);
-
- Console::WriteLine("Final value of class-level property: {0}",
- Example::SharedProperty);
-
-
- Example^ exam = gcnew Example();
-
- Console::WriteLine("\nInitial value of instance property: {0}",
- exam->InstanceProperty);
-
- PropertyInfo^ piInstance =
- Example::typeid->GetProperty("InstanceProperty");
- piInstance->SetValue(exam, 37, nullptr);
-
- Console::WriteLine("Final value of instance property: {0}",
- exam->InstanceProperty);
-
-
- exam[17] = "String number 17";
- exam[46] = "String number 46";
- exam[9] = "String number 9";
-
- Console::WriteLine(
- "\nInitial value of indexed instance property(17): '{0}'",
- exam[17]);
-
- // By default, the name of the default indexed property (class
- // indexer) is Item, and that name must be used to search for the
- // property with reflection. The property can be given a different
- // name by using the IndexerNameAttribute attribute.
- PropertyInfo^ piIndexedInstance =
- Example::typeid->GetProperty("Item");
- piIndexedInstance->SetValue(
- exam,
- "New value for string number 17",
- gcnew array { 17 });
-
- Console::WriteLine("Final value of indexed instance property(17): '{0}'",
- exam[17]);
-};
-
-/* This example produces the following output:
-
-Initial value of class-level property: 41
-Final value of class-level property: 76
-
-Initial value of instance property: 42
-Final value of instance property: 37
-
-Initial value of indexed instance property(17): 'String number 17'
-Final value of indexed instance property(17): 'New value for string number 17'
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/PropertyInfo.SetValue/cpp/example2.cpp b/snippets/cpp/VS_Snippets_CLR/PropertyInfo.SetValue/cpp/example2.cpp
deleted file mode 100644
index f6ea3e649aa..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/PropertyInfo.SetValue/cpp/example2.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-ref class Example
-{
-private:
- int static _sharedProperty = 41;
- int _instanceProperty;
-
-
-public:
- Example()
- {
- _instanceProperty = 42;
- };
-
- static property int SharedProperty
- {
- int get() { return _sharedProperty; }
- void set(int value) { _sharedProperty = value; }
- };
-
- property int InstanceProperty
- {
- int get() { return _instanceProperty; }
- void set(int value) { _instanceProperty = value; }
- };
-
-};
-
-void main()
-{
- Console::WriteLine("Initial value of static property: {0}",
- Example::SharedProperty);
-
- PropertyInfo^ piShared =
- Example::typeid->GetProperty("SharedProperty");
- piShared->SetValue(nullptr, 76, nullptr);
-
- Console::WriteLine("New value of static property: {0}",
- Example::SharedProperty);
-
-
- Example^ exam = gcnew Example();
-
- Console::WriteLine("\nInitial value of instance property: {0}",
- exam->InstanceProperty);
-
- PropertyInfo^ piInstance =
- Example::typeid->GetProperty("InstanceProperty");
- piInstance->SetValue(exam, 37, nullptr);
-
- Console::WriteLine("New value of instance property: {0}",
- exam->InstanceProperty);
-};
-
-/* The example displays the following output:
- Initial value of static property: 41
- New value of static property: 76
-
- Initial value of instance property: 42
- New value of instance property: 37
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/Reflection.DynamicMethod.All/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/Reflection.DynamicMethod.All/cpp/source.cpp
deleted file mode 100644
index 28a75c1bc29..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Reflection.DynamicMethod.All/cpp/source.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Globalization;
-
-// Declare a delegate type that can be used to execute the completed
-// dynamic method.
-private delegate int HelloDelegate(String^ msg, int ret);
-
-void main()
-{
- // Create an array that specifies the types of the parameters
- // of the dynamic method. This dynamic method has a String
- // parameter and an Integer parameter.
- array^ helloArgs = { String::typeid, int::typeid };
-
- // Create a dynamic method with the name "Hello", a return type
- // of Integer, and two parameters whose types are specified by
- // the array helloArgs. Create the method in the module that
- // defines the String class.
- DynamicMethod^ hello = gcnew DynamicMethod("Hello",
- int::typeid,
- helloArgs,
- String::typeid->Module);
-
- //
- // Create an array that specifies the parameter types of the
- // overload of Console::WriteLine to be used in Hello.
- array^ writeStringArgs = { String::typeid };
- // Get the overload of Console::WriteLine that has one
- // String parameter.
- MethodInfo^ writeString = Console::typeid->GetMethod("WriteLine",
- writeStringArgs);
-
- // Get an ILGenerator and emit a body for the dynamic method,
- // using a stream size larger than the IL that will be
- // emitted.
- ILGenerator^ il = hello->GetILGenerator(256);
- // Load the first argument, which is a string, onto the stack.
- il->Emit(OpCodes::Ldarg_0);
- // Call the overload of Console::WriteLine that prints a string.
- il->EmitCall(OpCodes::Call, writeString, nullptr);
- // The Hello method returns the value of the second argument;
- // to do this, load the onto the stack and return.
- il->Emit(OpCodes::Ldarg_1);
- il->Emit(OpCodes::Ret);
- //
-
- //
- // Add parameter information to the dynamic method. (This is not
- // necessary, but can be useful for debugging.) For each parameter,
- // identified by position, supply the parameter attributes and a
- // parameter name.
- hello->DefineParameter(1, ParameterAttributes::In, "message");
- hello->DefineParameter(2, ParameterAttributes::In, "valueToReturn");
- //
-
- //
- // Create a delegate that represents the dynamic method. This
- // action completes the method. Any further attempts to
- // change the method are ignored.
- HelloDelegate^ hi =
- (HelloDelegate^) hello->CreateDelegate(HelloDelegate::typeid);
-
- // Use the delegate to execute the dynamic method.
- Console::WriteLine("\r\nUse the delegate to execute the dynamic method:");
- int retval = hi("\r\nHello, World!", 42);
- Console::WriteLine("Invoking delegate hi(\"Hello, World!\", 42) returned: " + retval);
-
- // Execute it again, with different arguments.
- retval = hi("\r\nHi, Mom!", 5280);
- Console::WriteLine("Invoking delegate hi(\"Hi, Mom!\", 5280) returned: " + retval);
- //
-
- //
- Console::WriteLine("\r\nUse the Invoke method to execute the dynamic method:");
- // Create an array of arguments to use with the Invoke method.
- array^ invokeArgs = { "\r\nHello, World!", 42 };
- // Invoke the dynamic method using the arguments. This is much
- // slower than using the delegate, because you must create an
- // array to contain the arguments, and value-type arguments
- // must be boxed.
- Object^ objRet = hello->Invoke(nullptr, BindingFlags::ExactBinding, nullptr, invokeArgs, gcnew CultureInfo("en-us"));
- Console::WriteLine("hello.Invoke returned: " + objRet);
- //
-
- Console::WriteLine("\r\n ----- Display information about the dynamic method -----");
- //
- // Display MethodAttributes for the dynamic method, set when
- // the dynamic method was created.
- Console::WriteLine("\r\nMethod Attributes: {0}", hello->Attributes);
- //
-
- //
- // Display the calling convention of the dynamic method, set when the
- // dynamic method was created.
- Console::WriteLine("\r\nCalling convention: {0}", hello->CallingConvention);
- //
-
- //
- // Display the declaring type, which is always null for dynamic
- // methods.
- if (hello->DeclaringType == nullptr)
- {
- Console::WriteLine("\r\nDeclaringType is always null for dynamic methods.");
- }
- else
- {
- Console::WriteLine("DeclaringType: {0}", hello->DeclaringType);
- }
- //
-
- //
- // Display the default value for InitLocals.
- if (hello->InitLocals)
- {
- Console::Write("\r\nThis method contains verifiable code.");
- }
- else
- {
- Console::Write("\r\nThis method contains unverifiable code.");
- }
- Console::WriteLine(" (InitLocals = {0})", hello->InitLocals);
- //
-
- //
- // Display the module specified when the dynamic method was created.
- Console::WriteLine("\r\nModule: {0}", hello->Module);
- //
-
- //
- // Display the name specified when the dynamic method was created.
- // Note that the name can be blank.
- Console::WriteLine("\r\nName: {0}", hello->Name);
- //
-
- //
- // For dynamic methods, the reflected type is always null.
- if (hello->ReflectedType == nullptr)
- {
- Console::WriteLine("\r\nReflectedType is null.");
- }
- else
- {
- Console::WriteLine("\r\nReflectedType: {0}", hello->ReflectedType);
- }
- //
-
- //
- if (hello->ReturnParameter == nullptr)
- {
- Console::WriteLine("\r\nMethod has no return parameter.");
- }
- else
- {
- Console::WriteLine("\r\nReturn parameter: {0}", hello->ReturnParameter);
- }
- //
-
- //
- // If the method has no return type, ReturnType is System.Void.
- Console::WriteLine("\r\nReturn type: {0}", hello->ReturnType);
- //
-
- //
- // ReturnTypeCustomAttributes returns an ICustomeAttributeProvider
- // that can be used to enumerate the custom attributes of the
- // return value. At present, there is no way to set such custom
- // attributes, so the list is empty.
- if (hello->ReturnType == Void::typeid)
- {
- Console::WriteLine("The method has no return type.");
- }
- else
- {
- ICustomAttributeProvider^ caProvider = hello->ReturnTypeCustomAttributes;
- array^ returnAttributes = caProvider->GetCustomAttributes(true);
- if (returnAttributes->Length == 0)
- {
- Console::WriteLine("\r\nThe return type has no custom attributes.");
- }
- else
- {
- Console::WriteLine("\r\nThe return type has the following custom attributes:");
- for each (Object^ attr in returnAttributes)
- {
- Console::WriteLine("\t{0}", attr->ToString());
- }
- }
- }
- //
-
- //
- Console::WriteLine("\r\nToString: {0}", hello->ToString());
- //
-
- //
- // Display parameter information.
- array^ parameters = hello->GetParameters();
- Console::WriteLine("\r\nParameters: name, type, ParameterAttributes");
- for each (ParameterInfo^ p in parameters)
- {
- Console::WriteLine("\t{0}, {1}, {2}",
- p->Name, p->ParameterType, p->Attributes);
- }
- //
-}
-
-/* This code example produces the following output:
-
-Use the delegate to execute the dynamic method:
-
-Hello, World!
-Invoking delegate hi("Hello, World!", 42) returned: 42
-
-Hi, Mom!
-Invoking delegate hi("Hi, Mom!", 5280) returned: 5280
-
-Use the Invoke method to execute the dynamic method:
-
-Hello, World!
-hello.Invoke returned: 42
-
- ----- Display information about the dynamic method -----
-
-Method Attributes: PrivateScope, Public, Static
-
-Calling convention: Standard
-
-DeclaringType is always null for dynamic methods.
-
-This method contains verifiable code. (InitLocals = True)
-
-Module: CommonLanguageRuntimeLibrary
-
-Name: Hello
-
-ReflectedType is null.
-
-Method has no return parameter.
-
-Return type: System.Int32
-
-The return type has no custom attributes.
-
-ToString: Int32 Hello(System.String, Int32)
-
-Parameters: name, type, ParameterAttributes
- message, System.String, In
- valueToReturn, System.Int32, In
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/Reflection.DynamicMethod.ctor1/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/Reflection.DynamicMethod.ctor1/cpp/source.cpp
deleted file mode 100644
index 86d3112fd26..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Reflection.DynamicMethod.ctor1/cpp/source.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class Test
-{
-};
-
-// Declare a delegate that will be used to execute the completed
-// dynamic method.
-delegate int HelloInvoker(String^ msg, int ret);
-
-int main()
-{
- // Create an array that specifies the types of the parameters
- // of the dynamic method. This method has a string parameter
- // and an int parameter.
- array^ helloArgs = {String::typeid, int::typeid};
-
- // Create a dynamic method with the name "Hello", a return type
- // of int, and two parameters whose types are specified by the
- // array helloArgs. Create the method in the module that
- // defines the Test class.
- DynamicMethod^ hello = gcnew DynamicMethod("Hello",
- int::typeid,
- helloArgs,
- Test::typeid->Module);
-
- //
- // Create an array that specifies the parameter types of the
- // overload of Console.WriteLine to be used in Hello.
- array^ writeStringArgs = {String::typeid};
- // Get the overload of Console.WriteLine that has one
- // String parameter.
- MethodInfo^ writeString =
- Console::typeid->GetMethod("WriteLine", writeStringArgs);
-
- // Get an ILGenerator and emit a body for the dynamic method.
- ILGenerator^ ilgen = hello->GetILGenerator();
- // Load the first argument, which is a string, onto the stack.
- ilgen->Emit(OpCodes::Ldarg_0);
- // Call the overload of Console.WriteLine that prints a string.
- ilgen->EmitCall(OpCodes::Call, writeString, nullptr);
- // The Hello method returns the value of the second argument;
- // to do this, load the onto the stack and return.
- ilgen->Emit(OpCodes::Ldarg_1);
- ilgen->Emit(OpCodes::Ret);
- //
-
- //
- // Create a delegate that represents the dynamic method. This
- // action completes the method, and any further attempts to
- // change the method will cause an exception.
- HelloInvoker^ helloDelegate =
- (HelloInvoker^) hello->CreateDelegate(HelloInvoker::typeid);
- //
-
- // Use the delegate to execute the dynamic method. Save and
- // print the return value.
- int returnValue = helloDelegate("\r\nHello, World!", 42);
- Console::WriteLine("helloDelegate(\"Hello, World!\", 42) returned {0}",
- returnValue);
-
- // Do it again, with different arguments.
- returnValue = helloDelegate("\r\nHi, Mom!", 5280);
- Console::WriteLine("helloDelegate(\"Hi, Mom!\", 5280) returned {0}",
- returnValue);
-
- //
- // Create an array of arguments to use with the Invoke method.
- array^ delegateArgs = {"\r\nHello, World!", 42};
- // Invoke the dynamic method using the arguments. This is much
- // slower than using the delegate, because you must create an
- // array to contain the arguments, and ValueType arguments
- // must be boxed.
- Object^ returnValueObject = hello->Invoke(nullptr, delegateArgs);
- Console::WriteLine("hello.Invoke returned {0}", returnValueObject);
- //
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/Reflection/CPP/reflection.cpp b/snippets/cpp/VS_Snippets_CLR/Reflection/CPP/reflection.cpp
deleted file mode 100644
index f6f2d74c1e0..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Reflection/CPP/reflection.cpp
+++ /dev/null
@@ -1,172 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-static void Display(Int32 indent, String^ format, ... array^param)
-{
- Console::Write("{0}", gcnew String (' ', indent));
- Console::WriteLine(format, param);
-}
-
-// Displays the custom attributes applied to the specified member.
-static void DisplayAttributes(Int32 indent, MemberInfo^ mi)
-{
- // Get the set of custom attributes; if none exist, just return.
- array^attrs = mi->GetCustomAttributes(false);
-
- if (attrs->Length==0)
- {
- return;
- }
-
- // Display the custom attributes applied to this member.
- Display(indent+1, "Attributes:");
- for each ( Object^ o in attrs )
- {
- Display(indent*2, "{0}", o);
- }
-}
-
-void main()
-{
- try
- {
- // This variable holds the amount of indenting that
- // should be used when displaying each line of information.
- Int32 indent = 0;
- // Display information about the EXE assembly.
- //
- Assembly^ a = System::Reflection::Assembly::GetExecutingAssembly();
-
- Display(indent, "Assembly identity={0}", gcnew array {a->FullName});
- Display(indent+1, "Codebase={0}", gcnew array {a->CodeBase});
-
- // Display the set of assemblies our assemblies reference.
-
- Display(indent, "Referenced assemblies:");
-
- for each ( AssemblyName^ an in a->GetReferencedAssemblies() )
- {
- Display(indent + 1, "Name={0}, Version={1}, Culture={2}, PublicKey token={3}", gcnew array {an->Name, an->Version, an->CultureInfo, (BitConverter::ToString(an->GetPublicKeyToken()))});
- }
- //
- Display(indent, "");
- // Display information about each assembly loading into this AppDomain.
- for each ( Assembly^ b in AppDomain::CurrentDomain->GetAssemblies())
- {
- Display(indent, "Assembly: {0}", gcnew array {b});
- // Display information about each module of this assembly.
-
- for each ( Module^ m in b->GetModules(true) )
- {
- Display(indent+1, "Module: {0}", gcnew array {m->Name});
- }
- // Display information about each type exported from this assembly.
-
- indent += 1;
- for each ( Type^ t in b->GetExportedTypes() )
- {
- Display(0, "");
- Display(indent, "Type: {0}", gcnew array {t});
-
- // For each type, show its members & their custom attributes.
-
- indent += 1;
- for each (MemberInfo^ mi in t->GetMembers() )
- {
- Display(indent, "Member: {0}", gcnew array {mi->Name});
- DisplayAttributes(indent, mi);
-
- // If the member is a method, display information about its parameters.
- if (mi->MemberType==MemberTypes::Method)
- {
-
- for each ( ParameterInfo^ pi in (((MethodInfo^) mi)->GetParameters()))
- {
- Display(indent+1, "Parameter: Type={0}, Name={1}", gcnew array {pi->ParameterType, pi->Name});
- }
- }
-
- // If the member is a property, display information about the property's accessor methods.
- if (mi->MemberType==MemberTypes::Property)
- {
- for each ( MethodInfo^ am in (((PropertyInfo^) mi)->GetAccessors()) )
- {
- Display(indent+1, "Accessor method: {0}", gcnew array {am});
- }
- }
- }
- // Display a formatted string indented by the specified amount.
- indent -= 1;
- }
- indent -= 1;
- }
- }
- catch (Exception^ e)
- {
- Console::WriteLine(e->Message);
- }
-}
-
-// The output shown below is abbreviated.
-//
-//Assembly identity=Reflection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
-// Codebase=file:///C:/Reflection.exe
-//Referenced assemblies:
-// Name=mscorlib, Version=1.0.5000.0, Culture=, PublicKey token=B7-7A-5C-56-19-34-E0-89
-// Name=Microsoft.VisualBasic, Version=7.0.5000.0, Culture=, PublicKey token=B0-3F-5F-7F-11-D5-0A-3A
-//
-//Assembly: mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-// Module: mscorlib.dll
-// Module: prc.nlp
-// Module: prcp.nlp
-// Module: ksc.nlp
-// Module: ctype.nlp
-// Module: xjis.nlp
-// Module: bopomofo.nlp
-// Module: culture.nlp
-// Module: region.nlp
-// Module: sortkey.nlp
-// Module: charinfo.nlp
-// Module: big5.nlp
-// Module: sorttbls.nlp
-// Module: l_intl.nlp
-// Module: l_except.nlp
-//
-// Type: System.Object
-// Member: GetHashCode
-// Member: Equals
-// Parameter: Type=System.Object, Name=obj
-// Member: ToString
-// Member: Equals
-// Parameter: Type=System.Object, Name=objA
-// Parameter: Type=System.Object, Name=objB
-// Member: ReferenceEquals
-// Parameter: Type=System.Object, Name=objA
-// Parameter: Type=System.Object, Name=objB
-// Member: GetType
-// Member: .ctor
-//
-// Type: System.ICloneable
-// Member: Clone
-//
-// Type: System.Collections.IEnumerable
-// Member: GetEnumerator
-// Attributes:
-// System.Runtime.InteropServices.DispIdAttribute
-//
-// Type: System.Collections.ICollection
-// Member: get_IsSynchronized
-// Member: get_SyncRoot
-// Member: get_Count
-// Member: CopyTo
-// Parameter: Type=System.Array, Name=array
-// Parameter: Type=System.Int32, Name=index
-// Member: Count
-// Accessor method: Int32 get_Count()
-// Member: SyncRoot
-// Accessor method: System.Object get_SyncRoot()
-// Member: IsSynchronized
-// Accessor method: Boolean get_IsSynchronized()
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/StrongNameKeyPairX/cpp/strongnamekeypairx.cpp b/snippets/cpp/VS_Snippets_CLR/StrongNameKeyPairX/cpp/strongnamekeypairx.cpp
deleted file mode 100644
index 97c560511ad..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/StrongNameKeyPairX/cpp/strongnamekeypairx.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-//Types:System.Reflection.StrongNameKeyPair
-//
-using namespace System;
-using namespace System::IO;
-using namespace System::Reflection;
-
-ref class snkX
-{
-public:
- static void Main()
- {
- // Open a file that contains a public key value. The line below
- // assumes that the Strong Name tool (SN.exe) was executed from
- // a command prompt as follows:
- // SN.exe -k C:\Company.keys
- FileStream^ fs = File::Open("C:\\Company.keys", FileMode::Open);
-
- //
- // Construct a StrongNameKeyPair object. This object should obtain
- // the public key from the Company.keys file.
- StrongNameKeyPair^ k = gcnew StrongNameKeyPair(fs);
- //
-
- //
- // Display the bytes that make up the public key.
- Console::WriteLine(BitConverter::ToString(k->PublicKey));
- //
-
- // Close the file.
- fs->Close();
- }
-};
-
-int main()
-{
- snkX::Main();
-}
-
-// Output will vary by user.
-//
-// 00-24-00-00-04-80-00-00-94-69-89-78-BB-F1-F2-71-00-00-00-34-26-
-// 69-89-78-BB-F1-F2-71-00-F1-FA-F2-F9-4A-A8-5E-82-55-AB-49-4D-A6-
-// ED-AB-5F-CE-DE-59-49-8D-63-01-B0-E1-BF-43-07-FA-55-D4-36-75-EE-
-// 8B-83-32-39-B7-02-DE-3D-81-29-7B-E8-EA-F0-2E-78-94-96-F1-73-79-
-// 69-89-78-BB-F1-F2-71-0E-4E-F4-5D-DD-A4-7F-11-54-DF-65-DE-89-23-
-// 91-AD-53-E1-C0-DA-9E-0C-88-BE-AA-7B-39-20-9C-9B-55-34-26-3B-1A-
-// 53-41-31-00-04-00-00-01-00-01-00-9D-F1-EA-14-4C-88-34-26-3B-1A-
-// 2D-D7-A0-AB-F6-7E-B7-24-7F-87-DF-3E-97
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder.DefineMethodOverride/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder.DefineMethodOverride/cpp/source.cpp
deleted file mode 100644
index c9151536fe5..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder.DefineMethodOverride/cpp/source.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public interface class I
-{
- void M();
-};
-
-public ref class A
-{
-public:
- virtual void M() { Console::WriteLine("In method A.M"); }
-};
-
-// The object of this code example is to emit code equivalent to
-// the following C++ code:
-//
-public ref class C : A, I
-{
-public:
- virtual void M() override
- {
- Console::WriteLine("Overriding A.M from C.M");
- }
-
-private:
- // In order to provide a different implementation from C.M when
- // emitting the following explicit interface implementation,
- // it is necessary to use a MethodImpl.
- //
- virtual void IM() sealed = I::M
- {
- Console::WriteLine("The I::M implementation of C");
- }
-};
-
-void main()
-{
- String^ name = "DefineMethodOverrideExample";
- AssemblyName^ asmName = gcnew AssemblyName(name);
- AssemblyBuilder^ ab =
- AppDomain::CurrentDomain->DefineDynamicAssembly(
- asmName, AssemblyBuilderAccess::RunAndSave);
- ModuleBuilder^ mb = ab->DefineDynamicModule(name, name + ".dll");
-
- TypeBuilder^ tb =
- mb->DefineType("C", TypeAttributes::Public, A::typeid);
- tb->AddInterfaceImplementation(I::typeid);
-
- // Build the method body for the explicit interface
- // implementation. The name used for the method body
- // can be anything. Here, it is the name of the method,
- // qualified by the interface name.
- //
- MethodBuilder^ mbIM = tb->DefineMethod("I.M",
- MethodAttributes::Private | MethodAttributes::HideBySig |
- MethodAttributes::NewSlot | MethodAttributes::Virtual |
- MethodAttributes::Final,
- nullptr,
- Type::EmptyTypes);
- ILGenerator^ il = mbIM->GetILGenerator();
- il->Emit(OpCodes::Ldstr, "The I.M implementation of C");
- il->Emit(OpCodes::Call, Console::typeid->GetMethod("WriteLine",
- gcnew array { String::typeid }));
- il->Emit(OpCodes::Ret);
-
- // DefineMethodOverride is used to associate the method
- // body with the interface method that is being implemented.
- //
- tb->DefineMethodOverride(mbIM, I::typeid->GetMethod("M"));
-
- MethodBuilder^ mbM = tb->DefineMethod("M",
- MethodAttributes::Public | MethodAttributes::ReuseSlot |
- MethodAttributes::Virtual | MethodAttributes::HideBySig,
- nullptr,
- Type::EmptyTypes);
- il = mbM->GetILGenerator();
- il->Emit(OpCodes::Ldstr, "Overriding A.M from C.M");
- il->Emit(OpCodes::Call, Console::typeid->GetMethod("WriteLine",
- gcnew array { String::typeid }));
- il->Emit(OpCodes::Ret);
-
- Type^ tc = tb->CreateType();
-
- // Save the emitted assembly, to examine with Ildasm.exe.
- ab->Save(name + ".dll");
-
- Object^ test = Activator::CreateInstance(tc);
-
- MethodInfo^ mi = I::typeid->GetMethod("M");
- mi->Invoke(test, nullptr);
-
- mi = A::typeid->GetMethod("M");
- mi->Invoke(test, nullptr);
-}
-
-/* This code example produces the following output:
-
-The I.M implementation of C
-Overriding A.M from C.M
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_AddDeclarativeSecurity/CPP/typebuilder_adddeclarativesecurity.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder_AddDeclarativeSecurity/CPP/typebuilder_adddeclarativesecurity.cpp
deleted file mode 100644
index 6ea81968d31..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_AddDeclarativeSecurity/CPP/typebuilder_adddeclarativesecurity.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-
-// System::Reflection::Emit::TypeBuilder.AddDeclarativeSecurity
-/* The following example demonstrates method AddDeclarativeSecurity
-of 'TypeBuilder' class.
-The program creates a dynamic assembly and a type in it having support for declarative security.
-It demands an Environmentpermission read access on 'TEMP'.
-Caller (main) is able to create an instance successfully with
-default permission(as local machine executes with full trust permission set).
-*/
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-
-int main()
-{
- // Create a simple name for the assembly; create the assembly and module.
- AssemblyName^ myAssemblyName = gcnew AssemblyName("EmittedAssembly");
- AssemblyBuilder^ myAssemblyBuilder =
- AppDomain::CurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ myModuleBuilder =
- myAssemblyBuilder->DefineDynamicModule( "EmittedAssembly", "EmittedAssembly.dll");
-
- // Define a public class named "MyDynamicClass" in the assembly.
- TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyDynamicClass", TypeAttributes::Public );
-
-
- // Create a permission set and add a security permission
- // with the ControlEvidence flag.
- //
- PermissionSet^ myPermissionSet = gcnew PermissionSet(PermissionState::None);
- myPermissionSet->AddPermission(
- gcnew SecurityPermission(SecurityPermissionFlag::ControlEvidence));
-
- // Add the permission set to the MyDynamicClass type,
- // as a declarative security demand.
- //
- myTypeBuilder->AddDeclarativeSecurity(SecurityAction::Demand, myPermissionSet);
-
-
- Type^ myType = myTypeBuilder->CreateType();
- myAssemblyBuilder->Save("EmittedAssembly.dll");
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefineNestedType1/CPP/typebuilder_definenestedtype1.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefineNestedType1/CPP/typebuilder_definenestedtype1.cpp
deleted file mode 100644
index c19e9adcb71..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefineNestedType1/CPP/typebuilder_definenestedtype1.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-
-// System.Reflection.Emit.TypeBuilder.DefineNestedType(string, TypeAttributes, Type, Type[])
-// System.Reflection.Emit.TypeBuilder.DefineMethodOverride(MethodInfo, MethodInfo)
-// System.Reflection.Emit.TypeBuilder.DefineMethod(string, MethodAttributes,Type,Type[])
-/*
-The following program demonstrates the 'DefineNestedType', 'DefineMethodOverride' and
-'DefineMethod' methods of 'TypeBuilder' class. It builds an assembly by defining
-'MyHelloWorld' type. 'MyHelloWorld' class has a nested class 'MyNestedClass' which extends
-'EmittedClass' and implements 'IMyInterface' interface. Then it creates and instance of
-'MyNestedClass' type and calls the 'HelloMethod' using 'IMyInterface' object and
-results are displayed to the console.
-*/
-//
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-public interface class IMyInterface
-{
- String^ HelloMethod( String^ parameter );
-};
-
-public ref class EmittedClass
-{
-public:
- // Because this method calls Activator::CreateInstance,
- // it requires full trust.
- [System::Security::Permissions::PermissionSetAttribute
- (System::Security::Permissions::SecurityAction::Demand, Name = "FullTrust")]
- static void Main()
- {
- Type^ myNestedClassType = CreateCallee( Thread::GetDomain() );
-
- // Create an instance of 'MyNestedClass'.
- IMyInterface^ myInterface = dynamic_cast(Activator::CreateInstance( myNestedClassType ));
- Console::WriteLine( myInterface->HelloMethod( "Bill" ) );
- }
-
-private:
-
- // Create the callee transient dynamic assembly.
- static Type^ CreateCallee( AppDomain^ myAppDomain )
- {
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedClass";
-
- // Create the callee dynamic assembly.
- AssemblyBuilder^ myAssembly = myAppDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module in the callee assembly.
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Define a public class named "MyHelloWorld".
- TypeBuilder^ myHelloWorldType = myModule->DefineType( "MyHelloWorld", TypeAttributes::Public );
-
- // Define a public nested class named 'MyNestedClass'.
- array^temp0 = {IMyInterface::typeid};
- TypeBuilder^ myNestedClassType = myHelloWorldType->DefineNestedType( "MyNestedClass", TypeAttributes::NestedPublic, EmittedClass::typeid, temp0 );
-
- // Implement 'IMyInterface' interface.
- myNestedClassType->AddInterfaceImplementation( IMyInterface::typeid );
-
- // Define 'HelloMethod' of 'IMyInterface'.
- array^temp1 = {String::typeid};
- MethodBuilder^ myHelloMethod = myNestedClassType->DefineMethod( "HelloMethod", static_cast(MethodAttributes::Public | MethodAttributes::Virtual), String::typeid, temp1 );
-
- // Generate IL for 'GetGreeting' method.
- ILGenerator^ myMethodIL = myHelloMethod->GetILGenerator();
- myMethodIL->Emit( OpCodes::Ldstr, "Hi! " );
- myMethodIL->Emit( OpCodes::Ldarg_1 );
- array^temp2 = {String::typeid,String::typeid};
- MethodInfo^ infoMethod = String::typeid->GetMethod( "Concat", temp2 );
- myMethodIL->Emit( OpCodes::Call, infoMethod );
- myMethodIL->Emit( OpCodes::Ret );
- MethodInfo^ myHelloMethodInfo = IMyInterface::typeid->GetMethod( "HelloMethod" );
-
- // Implement 'HelloMethod' of 'IMyInterface'.
- myNestedClassType->DefineMethodOverride( myHelloMethod, myHelloMethodInfo );
-
- // Create 'MyHelloWorld' type.
- Type^ myType = myHelloWorldType->CreateType();
-
- // Create 'MyNestedClass' type.
- return myNestedClassType->CreateType();
- }
-};
-
-int main()
-{
- EmittedClass::Main();
-}
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefinePInvokeMethod_Fix/cpp/100656_fix.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefinePInvokeMethod_Fix/cpp/100656_fix.cpp
deleted file mode 100644
index 15212e47056..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefinePInvokeMethod_Fix/cpp/100656_fix.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-//
-using namespace System;
-using namespace System::Text;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Runtime::InteropServices;
-
- void main()
- {
- // Create the AssemblyBuilder.
- AssemblyName^ asmName = gcnew AssemblyName("PInvokeTest");
- AssemblyBuilder^ dynamicAsm = AppDomain::CurrentDomain->DefineDynamicAssembly(
- asmName,
- AssemblyBuilderAccess::RunAndSave
- );
-
- // Create the module.
- ModuleBuilder^ dynamicMod =
- dynamicAsm->DefineDynamicModule(asmName->Name, asmName->Name + ".dll");
-
- // Create the TypeBuilder for the class that will contain the
- // signature for the PInvoke call.
- TypeBuilder^ tb = dynamicMod->DefineType(
- "MyType",
- TypeAttributes::Public | TypeAttributes::UnicodeClass
- );
-
- MethodBuilder^ mb = tb->DefinePInvokeMethod(
- "GetTickCount",
- "Kernel32.dll",
- MethodAttributes::Public | MethodAttributes::Static | MethodAttributes::PinvokeImpl,
- CallingConventions::Standard,
- int::typeid,
- Type::EmptyTypes,
- CallingConvention::Winapi,
- CharSet::Ansi);
-
- // Add PreserveSig to the method implementation flags. NOTE: If this line
- // is commented out, the return value will be zero when the method is
- // invoked.
- mb->SetImplementationFlags(
- mb->GetMethodImplementationFlags() | MethodImplAttributes::PreserveSig);
-
- // The PInvoke method does not have a method body.
-
- // Create the class and test the method.
- Type^ t = tb->CreateType();
-
- MethodInfo^ mi = t->GetMethod("GetTickCount");
- Console::WriteLine("Testing PInvoke method...");
- Console::WriteLine("GetTickCount returned: {0}", mi->Invoke(nullptr, nullptr));
-
- // Produce the .dll file.
- Console::WriteLine("Saving: " + asmName->Name + ".dll");
- dynamicAsm->Save(asmName->Name + ".dll");
- };
-
-/* This example produces output similar to the following:
-
-Testing PInvoke method...
-GetTickCount returned: 1314410994
-Saving: PInvokeTest.dll
- */
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefineUninitializedData/CPP/typebuilder_defineuninitializeddata.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefineUninitializedData/CPP/typebuilder_defineuninitializeddata.cpp
deleted file mode 100644
index ad88d21ef91..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_DefineUninitializedData/CPP/typebuilder_defineuninitializeddata.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-
-
-// System::Reflection::Emit::TypeBuilder::DefineUninitializedData(string,int,FieldAttributes)
-/*
-The following program demonstrates the 'DefineUninitializedData'
-method of 'TypeBuilder' class. It builds an assembly by defining 'MyHelloWorld' type and
-it has 'MyGreeting' field. Then it displays the initial value of 'MyGreeting'
-field to the console.
-*/
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Runtime::InteropServices;
-using namespace System::Security::Permissions;
-
-public ref class Example
-{
-public:
- [SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
- static void Main()
- {
- Type^ myHelloWorldType = CreateCallee( Thread::GetDomain() );
- Object^ myHelloWorldInstance = Activator::CreateInstance( myHelloWorldType );
- FieldInfo^ myGreetingFieldInfo = myHelloWorldType->GetField( "MyGreeting" );
- Object^ oval = Activator::CreateInstance( myGreetingFieldInfo->FieldType );
- IntPtr myIntPtr = Marshal::AllocHGlobal( 4 );
- Random^ rand = gcnew Random;
- int iTempSeed = rand->Next();
- array^bINITBYTE = GetRandBytes( iTempSeed, 4 );
- IntPtr intptrTemp = myIntPtr;
- for ( int j = 0; j < 4; j++ )
- {
- Marshal::WriteByte( myIntPtr, bINITBYTE[ j ] );
- myIntPtr = (IntPtr)((int)myIntPtr + 1);
-
- }
- myIntPtr = intptrTemp;
- Object^ oValNew = Marshal::PtrToStructure( myIntPtr, myGreetingFieldInfo->FieldType );
- Marshal::FreeHGlobal( myIntPtr );
- myIntPtr = Marshal::AllocHGlobal( 4 );
- Object^ myObj = myGreetingFieldInfo->GetValue( myHelloWorldInstance );
- Marshal::StructureToPtr( myObj, myIntPtr, true );
- intptrTemp = myIntPtr;
- Console::WriteLine( "The value of 'MyGreeting' field : " );
- for ( int j = 0; j < 4; j++ )
- {
- Marshal::WriteByte( myIntPtr, bINITBYTE[ j ] );
- Console::WriteLine( bINITBYTE[ j ] );
- myIntPtr = (IntPtr)((int)myIntPtr + 1);
-
- }
- }
-
-
-private:
- static array^ GetRandBytes( int iRandSeed, int iSize )
- {
- array^barr = gcnew array(iSize);
- Random^ randTemp = gcnew Random( iRandSeed );
- randTemp->NextBytes( barr );
- return barr;
- }
-
-
- // Create the callee transient dynamic assembly.
- static Type^ CreateCallee( AppDomain^ myDomain )
- {
-
- // Create a simple name for the callee assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedClass";
-
- // Create the callee dynamic assembly.
- AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module in the callee assembly.
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Define a public class named "MyHelloWorld"
- TypeBuilder^ myHelloWorldType = myModule->DefineType( "MyHelloWorld", TypeAttributes::Public );
-
- // Define a 'MyGreeting' field and initialize it.
- FieldBuilder^ myFieldBuilder = myHelloWorldType->DefineUninitializedData( "MyGreeting", 4, FieldAttributes::Public );
-
- // Create the 'MyHelloWorld' class.
- return (myHelloWorldType->CreateType());
- }
-
-};
-
-int main()
-{
- Example::Main();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_GetEvents1/CPP/typebuilder_getevents1.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder_GetEvents1/CPP/typebuilder_getevents1.cpp
deleted file mode 100644
index e35e284ec04..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_GetEvents1/CPP/typebuilder_getevents1.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-
-// System::Reflection::Emit::TypeBuilder.GetEvents(BindingFlags)
-/*
-The program demonstrates the 'GetEvents' method of the 'TypeBuilder' class.
-It builds an assembly by defining 'HelloWorld' type and creates a 'Click' and
-'MouseUp' events on the type. Then displays all events to the Console.
-*/
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-ref class MyApplication
-{
-private:
- delegate void MyEvent( Object^ temp );
-
-public:
-
- // Create the callee transient dynamic assembly.
- static TypeBuilder^ CreateCallee( AppDomain^ myDomain )
- {
- AssemblyName^ assemblyName = gcnew AssemblyName;
- assemblyName->Name = "EmittedAssembly";
-
- // Create the callee dynamic assembly.
- AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Define a public class named "HelloWorld" in the assembly.
- TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
- array^typeArray = gcnew array(1);
- typeArray[ 0 ] = Object::typeid;
- MethodBuilder^ myMethod1 = helloWorldClass->DefineMethod( "OnClick", MethodAttributes::Public, void::typeid, typeArray );
- ILGenerator^ methodIL1 = myMethod1->GetILGenerator();
- methodIL1->Emit( OpCodes::Ret );
- MethodBuilder^ myMethod2 = helloWorldClass->DefineMethod( "OnMouseUp", MethodAttributes::Public, void::typeid, typeArray );
- ILGenerator^ methodIL2 = myMethod2->GetILGenerator();
- methodIL2->Emit( OpCodes::Ret );
-
- // Create the events.
- EventBuilder^ myEvent1 = helloWorldClass->DefineEvent( "Click", EventAttributes::None, MyEvent::typeid );
- myEvent1->SetRaiseMethod( myMethod1 );
- EventBuilder^ myEvent2 = helloWorldClass->DefineEvent( "MouseUp", EventAttributes::None, MyEvent::typeid );
- myEvent2->SetRaiseMethod( myMethod2 );
- helloWorldClass->CreateType();
- return (helloWorldClass);
- }
-};
-
-int main()
-{
- TypeBuilder^ helloWorldClass = MyApplication::CreateCallee( Thread::GetDomain() );
- array^info = helloWorldClass->GetEvents( static_cast(BindingFlags::Public | BindingFlags::Instance) );
- Console::WriteLine( "'HelloWorld' type has following events :" );
- for ( int i = 0; i < info->Length; i++ )
- Console::WriteLine( info[ i ]->Name );
- return 0;
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_Properties1/CPP/typebuilder_properties.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder_Properties1/CPP/typebuilder_properties.cpp
deleted file mode 100644
index a6d8a10bd75..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_Properties1/CPP/typebuilder_properties.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-
-// System.Reflection.Emit.TypeBuilder.FullName
-// System.Reflection.Emit.TypeBuilder.GetConstructors
-// System.Reflection.Emit.TypeBuilder.DefineTypeInitializer
-/*
-The following program demonstrates DefineTypeInitializer and 'GetConstructors' methods and
-the 'FullName' property of 'TypeBuilder' class. It builds an assembly by defining 'HelloWorld'
-type. It also defines a constructor for 'HelloWorld' type. Then it displays the
-full name of type and its constructors to the console.
-*/
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-//
-//
-//
-// Create the callee transient dynamic assembly.
-TypeBuilder^ CreateCallee( AppDomain^ myDomain )
-{
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
-
- // Create the callee dynamic assembly.
- AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module named "CalleeModule" in the callee assembly.
- ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule" );
-
- // Define a public class named "HelloWorld" in the assembly.
- TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
-
- // Define a private String field named "Greeting" in the type.
- FieldBuilder^ greetingField = helloWorldClass->DefineField( "Greeting", String::typeid, FieldAttributes::Private );
-
- // Create the constructor.
- ConstructorBuilder^ constructor = helloWorldClass->DefineTypeInitializer();
-
- // Generate IL for the method. The constructor calls its base class
- // constructor. The constructor stores its argument in the private field.
- ILGenerator^ constructorIL = constructor->GetILGenerator();
- constructorIL->Emit( OpCodes::Ldarg_0 );
- ConstructorInfo^ superConstructor = Object::typeid->GetConstructor( gcnew array(0) );
- constructorIL->Emit( OpCodes::Call, superConstructor );
- constructorIL->Emit( OpCodes::Ldarg_0 );
- constructorIL->Emit( OpCodes::Ldarg_1 );
- constructorIL->Emit( OpCodes::Stfld, greetingField );
- constructorIL->Emit( OpCodes::Ret );
- helloWorldClass->CreateType();
- return (helloWorldClass);
-}
-
-int main()
-{
- // Create the "HelloWorld" class
- TypeBuilder^ helloWorldClass = CreateCallee( Thread::GetDomain() );
- Console::WriteLine( "Full Name : {0}", helloWorldClass->FullName );
- Console::WriteLine( "Constructors :" );
- array^info = helloWorldClass->GetConstructors( static_cast(BindingFlags::Public | BindingFlags::Instance) );
- for ( int index = 0; index < info->Length; index++ )
- Console::WriteLine( info[ index ] );
-}
-//
-//
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_Sample_4/CPP/typebuilder_sample_4.cpp b/snippets/cpp/VS_Snippets_CLR/TypeBuilder_Sample_4/CPP/typebuilder_sample_4.cpp
deleted file mode 100644
index 073d9d96852..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/TypeBuilder_Sample_4/CPP/typebuilder_sample_4.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-// System.Reflection.Emit.TypeBuilder.DefineField()
-// System.Reflection.Emit.TypeBuilder.DefineConstructor()
-// System.Reflection.Emit.TypeBuilder.AddInterfaceImplementation()
-// System.Reflection.Emit.TypeBuilder.BaseType
-
-/* The following program demonstrates the property 'BaseType' and methods
- 'DefineField','DefineConstructor','AddInterfaceImplementation' of the
- class 'TypeBuilder'.
- The program creates a dynamic assembly and a type within it called as
- 'HelloWorld' This defines a field and implements an interface.
-*/
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Threading;
-
-// Declare the interface.
-interface class IHello
-{
- void SayHello();
-};
-
-// Create the transient dynamic assembly.
-Type^ CreateDynamicAssembly( AppDomain^ myAppDomain, AssemblyBuilderAccess myAccess )
-{
- // Create a simple name for assembly.
- AssemblyName^ myAssemblyName = gcnew AssemblyName;
- myAssemblyName->Name = "EmittedAssembly";
- // Create the dynamic assembly.
- AssemblyBuilder^ myAssemblyBuilder = myAppDomain->DefineDynamicAssembly( myAssemblyName, myAccess );
- // Create a dynamic module named 'CalleeModule' in the assembly.
- ModuleBuilder^ myModuleBuilder;
- myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "EmittedModule",
- "EmittedModule.mod" );
-//
-//
- // Define a public class named 'myHelloWorld' in the assembly.
- TypeBuilder^ helloWorldTypeBuilder =
- myModuleBuilder->DefineType( "HelloWorld", TypeAttributes::Public );
-
- // Get base type.
- Console::WriteLine( "Base Type :{0}", helloWorldTypeBuilder->BaseType->Name );
-//
-
- // Define 'myGreetingField' field.
- FieldBuilder^ myGreetingField =
- helloWorldTypeBuilder->DefineField( "myGreeting", String::typeid,
- FieldAttributes::Public );
-//
-
-//
- // Define the constructor.
- array^ constructorArgs = {String::typeid};
- ConstructorBuilder^ myConstructorBuilder =
- helloWorldTypeBuilder->DefineConstructor( MethodAttributes::Public,
- CallingConventions::Standard, constructorArgs );
- // Generate IL for the method. The constructor stores its argument in the private field.
- ILGenerator^ myConstructorIL = myConstructorBuilder->GetILGenerator();
- myConstructorIL->Emit( OpCodes::Ldarg_0 );
- myConstructorIL->Emit( OpCodes::Ldarg_1 );
- myConstructorIL->Emit( OpCodes::Stfld, myGreetingField );
- myConstructorIL->Emit( OpCodes::Ret );
-//
-
-//
- // Mark the class as implementing 'IHello' interface.
- helloWorldTypeBuilder->AddInterfaceImplementation( IHello::typeid );
- MethodBuilder^ myMethodBuilder =
- helloWorldTypeBuilder->DefineMethod( "SayHello",
- (MethodAttributes)(MethodAttributes::Public | MethodAttributes::Virtual),
- nullptr,
- nullptr );
- // Generate IL for 'SayHello' method.
- ILGenerator^ myMethodIL = myMethodBuilder->GetILGenerator();
- myMethodIL->EmitWriteLine( myGreetingField );
- myMethodIL->Emit( OpCodes::Ret );
- MethodInfo^ sayHelloMethod = IHello::typeid->GetMethod( "SayHello" );
- helloWorldTypeBuilder->DefineMethodOverride( myMethodBuilder, sayHelloMethod );
-//
- return (helloWorldTypeBuilder->CreateType());
-}
-
-int main()
-{
- Console::WriteLine( "TypeBuilder Sample" );
- Console::WriteLine( "----------------------" );
-
- // Create 'helloWorldType' .
- Type^ helloWorldType = CreateDynamicAssembly( Thread::GetDomain(), AssemblyBuilderAccess::RunAndSave );
-
- // Create an instance of 'HelloWorld' class.
- array^ temp0 = {"Called HelloWorld"};
- Object^ helloWorld = Activator::CreateInstance( helloWorldType, temp0 );
-
- // Invoke 'SayHello' method.
- helloWorldType->InvokeMember( "SayHello", static_cast(BindingFlags::Default | BindingFlags::InvokeMethod), nullptr, helloWorld, nullptr );
-
- // Get defined field in the class.
- Console::WriteLine( "Defined Field :{0}", helloWorldType->GetField( "myGreeting" )->Name );
- AssemblyBuilder^ myAssemblyBuilder = dynamic_cast(helloWorldType->Assembly);
- myAssemblyBuilder->Save( "EmittedAssembly.dll" );
-}
diff --git a/snippets/cpp/VS_Snippets_CLR/Type_GetConstructor3/CPP/type_getconstructor3.cpp b/snippets/cpp/VS_Snippets_CLR/Type_GetConstructor3/CPP/type_getconstructor3.cpp
deleted file mode 100644
index 6d911a7f1cd..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Type_GetConstructor3/CPP/type_getconstructor3.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Security;
-public ref class MyClass1
-{
-public:
- MyClass1( int i ){}
-
-};
-
-int main()
-{
- try
- {
- Type^ myType = MyClass1::typeid;
- array^types = gcnew array(1);
- types[ 0 ] = int::typeid;
-
- // Get the public instance constructor that takes an integer parameter.
- ConstructorInfo^ constructorInfoObj = myType->GetConstructor( static_cast(BindingFlags::Instance | BindingFlags::Public), nullptr, CallingConventions::HasThis, types, nullptr );
- if ( constructorInfoObj != nullptr )
- {
- Console::WriteLine( "The constructor of MyClass1 that is a public instance method and takes an integer as a parameter is: " );
- Console::WriteLine( constructorInfoObj );
- }
- else
- {
- Console::WriteLine( "The constructor of MyClass1 that is a public instance method and takes an integer as a parameter is not available." );
- }
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "ArgumentNullException: {0}", e->Message );
- }
- catch ( ArgumentException^ e )
- {
- Console::WriteLine( "ArgumentException: {0}", e->Message );
- }
- catch ( SecurityException^ e )
- {
- Console::WriteLine( "SecurityException: {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception: {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/Type_GetDefaultMembers/CPP/type_getdefaultmembers.cpp b/snippets/cpp/VS_Snippets_CLR/Type_GetDefaultMembers/CPP/type_getdefaultmembers.cpp
deleted file mode 100644
index b924dff4307..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/Type_GetDefaultMembers/CPP/type_getdefaultmembers.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::IO;
-
-[DefaultMemberAttribute("Age")]
-public ref class MyClass
-{
-public:
- void Name( String^ s ){}
-
-
- property int Age
- {
- int get()
- {
- return 20;
- }
-
- }
-
-};
-
-int main()
-{
- try
- {
- Type^ myType = MyClass::typeid;
- array^memberInfoArray = myType->GetDefaultMembers();
- if ( memberInfoArray->Length > 0 )
- {
- System::Collections::IEnumerator^ myEnum = memberInfoArray->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- MemberInfo^ memberInfoObj = safe_cast(myEnum->Current);
- Console::WriteLine( "The default member name is: {0}", memberInfoObj );
- }
- }
- else
- {
- Console::WriteLine( "No default members are available." );
- }
- }
- catch ( InvalidOperationException^ e )
- {
- Console::WriteLine( "InvalidOperationException: {0}", e->Message );
- }
- catch ( IOException^ e )
- {
- Console::WriteLine( "IOException: {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception: {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR/type_getevent1/CPP/type_getevent1.cpp b/snippets/cpp/VS_Snippets_CLR/type_getevent1/CPP/type_getevent1.cpp
deleted file mode 100644
index 552ea842e18..00000000000
--- a/snippets/cpp/VS_Snippets_CLR/type_getevent1/CPP/type_getevent1.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-//
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Security;
-using namespace System::Windows::Forms;
-
-int main()
-{
- try
- {
- // Creates a bitmask based on BindingFlags.
- BindingFlags myBindingFlags = static_cast(BindingFlags::Instance | BindingFlags::Public | BindingFlags::NonPublic);
- Type^ myTypeBindingFlags = System::Windows::Forms::Button::typeid;
- EventInfo^ myEventBindingFlags = myTypeBindingFlags->GetEvent( "Click", myBindingFlags );
- if ( myEventBindingFlags != nullptr )
- {
- Console::WriteLine( "Looking for the Click event in the Button class with the specified BindingFlags." );
- Console::WriteLine( myEventBindingFlags );
- }
- else
- Console::WriteLine( "The Click event is not available with the Button class." );
- }
- catch ( SecurityException^ e )
- {
- Console::WriteLine( "An exception occurred." );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "An exception occurred." );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "The following exception was raised : {0}", e->Message );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic AmbiguousMatchException.AmbiguousMatchException2 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic AmbiguousMatchException.AmbiguousMatchException2 Example/CPP/source.cpp
deleted file mode 100644
index 2b2375d4317..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic AmbiguousMatchException.AmbiguousMatchException2 Example/CPP/source.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-namespace Ambiguity
-{
- ref class Myambiguous
- {
- public:
-
- //The first overload is typed to an Int32
- static void Mymethod(Int32 number)
- {
- Console::WriteLine("I am from 'Int32' method");
- }
-
- //The second overload is typed to a String^
- static void Mymethod(String^ alpha)
- {
- Console::WriteLine("I am from 'String^' method.");
- }
-
- static void Main()
- {
- try
- {
- //The following does not cause as exception
- Mymethod(2); // goes to Mymethod (Int32)
- Mymethod("3"); // goes to Mymethod (String*)
- Type^ Mytype = Type::GetType("Ambiguity.Myambiguous");
- array^temp0 = {Int32::typeid};
- MethodInfo^ Mymethodinfo32 = Mytype->GetMethod("Mymethod", temp0);
- array^temp1 = {System::String::typeid};
- MethodInfo^ Mymethodinfostr = Mytype->GetMethod("Mymethod", temp1);
-
- //Invoke a method, utilizing a Int32 integer
- array^temp2 = {2};
- Mymethodinfo32->Invoke(nullptr, temp2);
-
- //Invoke the method utilizing a String^
- array^temp3 = {"1"};
- Mymethodinfostr->Invoke(nullptr, temp3);
-
- //The following line causes an ambiguous exception
- MethodInfo^ Mymethodinfo = Mytype->GetMethod("Mymethod");
- }
- catch (AmbiguousMatchException^ ex)
- {
- Console::WriteLine("\n{0}\n{1}", ex->GetType()->FullName, ex->Message);
- }
- catch (...)
- {
- Console::WriteLine("\nSome other exception.");
- }
-
- return;
- }
- };
-}
-
-int main()
-{
- Ambiguity::Myambiguous::Main();
-}
-
-//This code produces the following output:
-//
-// I am from 'Int32' method
-// I am from 'String^' method.
-// I am from 'Int32' method
-// I am from 'String^' method.
-//
-// System.Reflection.AmbiguousMatchException
-// Ambiguous match found.
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array Example/CPP/source.cpp
deleted file mode 100644
index bc8df83efca..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array Example/CPP/source.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-//
-using namespace System;
-
-void PrintValues(array^myArr);
-void PrintValues(array^myArr);
-void main()
-{
- // Creates and initializes a new int array and a new Object array.
- array^myIntArray = { 1,2,3,4,5 };
- array^myObjArray = { 26,27,28,29,30 };
-
- // Prints the initial values of both arrays.
- Console::WriteLine("Initially:");
- Console::Write("int array: ");
- PrintValues(myIntArray);
- Console::Write("Object array:");
- PrintValues(myObjArray);
-
- // Copies the first two elements from the int array to the Object array.
- System::Array::Copy(myIntArray, myObjArray, 2);
-
- // Prints the values of the modified arrays.
- Console::WriteLine("\nAfter copying the first two elements of the int array to the Object array:");
- Console::Write("int array: ");
- PrintValues(myIntArray);
- Console::Write("Object array:");
- PrintValues(myObjArray);
-
- // Copies the last two elements from the Object array to the int array.
- System::Array::Copy(myObjArray, myObjArray->GetUpperBound(0) - 1, myIntArray, myIntArray->GetUpperBound(0) - 1, 2);
-
- // Prints the values of the modified arrays.
- Console::WriteLine("\nAfter copying the last two elements of the Object array to the int array:");
- Console::Write("int array: ");
- PrintValues(myIntArray);
- Console::Write("Object array:");
- PrintValues(myObjArray);
-}
-
-void PrintValues(array^myArr)
-{
- for (int i = 0; i < myArr->Length; i++)
- {
- Console::Write("\t{0}", myArr[i]);
-
- }
- Console::WriteLine();
-}
-
-void PrintValues(array^myArr)
-{
- for (int i = 0; i < myArr->Length; i++)
- {
- Console::Write("\t{0}", myArr[i]);
-
- }
- Console::WriteLine();
-}
-
-
-/*
-This code produces the following output.
-
-Initially:
-int array: 1 2 3 4 5
-Object array: 26 27 28 29 30
-After copying the first two elements of the int array to the Object array:
-int array: 1 2 3 4 5
-Object array: 1 2 28 29 30
-After copying the last two elements of the Object array to the int array:
-int array: 1 2 3 29 30
-Object array: 1 2 28 29 30
-*/
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array Example/CPP/source3.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array Example/CPP/source3.cpp
deleted file mode 100644
index 10f90aa8ae1..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array Example/CPP/source3.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-using namespace System;
-void PrintValues(Array^ myArr);
-void main()
-{
- // Creates and initializes a new three-dimensional Array instance of type Int32.
- Array^ myArr = Array::CreateInstance( Int32::typeid, 2, 3, 4 );
- for ( int i = myArr->GetLowerBound( 0 ); i <= myArr->GetUpperBound( 0 ); i++ )
- {
- for ( int j = myArr->GetLowerBound( 1 ); j <= myArr->GetUpperBound( 1 ); j++ )
- {
- for ( int k = myArr->GetLowerBound( 2 ); k <= myArr->GetUpperBound( 2 ); k++ )
- myArr->SetValue( (i * 100) + (j * 10) + k, i, j, k );
-
- }
- }
-
- // Displays the properties of the Array.
- Console::WriteLine( "The Array instance has {0} dimension(s) and a total of {1} elements.", myArr->Rank, myArr->Length );
- Console::WriteLine( "\tLength\tLower\tUpper" );
- for ( int i = 0; i < myArr->Rank; i++ )
- {
- Console::Write( "{0}:\t{1}", i, myArr->GetLength( i ) );
- Console::WriteLine( "\t{0}\t{1}", myArr->GetLowerBound( i ), myArr->GetUpperBound( i ) );
-
- }
- Console::WriteLine( "The Array instance contains the following values:" );
- PrintValues( myArr );
-}
-
-void PrintValues( Array^ myArr )
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength( myArr->Rank - 1 );
- while ( myEnumerator->MoveNext() )
- {
- if ( i < cols )
- i++;
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( "\t{0}", myEnumerator->Current );
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- The Array instance has 3 dimension(s) and a total of 24 elements.
- Length Lower Upper
- 0: 2 0 1
- 1: 3 0 2
- 2: 4 0 3
- The Array instance contains the following values:
- 0 1 2 3
- 10 11 12 13
- 20 21 22 23
- 100 101 102 103
- 110 111 112 113
- 120 121 122 123
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.BinarySearch Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.BinarySearch Example/CPP/source.cpp
deleted file mode 100644
index 40db20d5eb6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.BinarySearch Example/CPP/source.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-//
-using namespace System;
-
-public ref class SamplesArray
-{
-public:
- static void Main()
- {
- // Creates and initializes a new Array.
- Array^ myIntArray = Array::CreateInstance(Int32::typeid, 5);
-
- myIntArray->SetValue(8, 0);
- myIntArray->SetValue(2, 1);
- myIntArray->SetValue(6, 2);
- myIntArray->SetValue(3, 3);
- myIntArray->SetValue(7, 4);
-
- // Do the required sort first
- Array::Sort(myIntArray);
-
- // Displays the values of the Array.
- Console::WriteLine("The Int32 array contains the following:");
- PrintValues(myIntArray);
-
- // Locates a specific object that does not exist in the Array.
- Object^ myObjectOdd = 1;
- FindMyObject(myIntArray, myObjectOdd);
-
- // Locates an object that exists in the Array.
- Object^ myObjectEven = 6;
- FindMyObject(myIntArray, myObjectEven);
- }
-
- static void FindMyObject(Array^ myArr, Object^ myObject)
- {
- int myIndex = Array::BinarySearch(myArr, myObject);
- if (myIndex < 0)
- {
- Console::WriteLine("The object to search for ({0}) is not found. The next larger object is at index {1}.", myObject, ~myIndex);
- }
- else
- {
- Console::WriteLine("The object to search for ({0}) is at index {1}.", myObject, myIndex);
- }
- }
-
- static void PrintValues(Array^ myArr)
- {
- int i = 0;
- int cols = myArr->GetLength(myArr->Rank - 1);
- for each (Object^ o in myArr)
- {
- if ( i < cols )
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
- Console::Write("\t{0}", o);
- }
- Console::WriteLine();
- }
-};
-
-int main()
-{
- SamplesArray::Main();
-}
-// This code produces the following output.
-//
-//The Int32 array contains the following:
-// 2 3 6 7 8
-//The object to search for (1) is not found. The next larger object is at index 0
-//
-//The object to search for (6) is at index 2.
-//
-
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Copy1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Copy1 Example/CPP/source.cpp
deleted file mode 100644
index 16882781c33..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Copy1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-
-//
-using namespace System;
-void PrintValues( Array^ myArr );
-void main()
-{
-
- // Creates and initializes a new Array instance of type Int32.
- Array^ myIntArray = Array::CreateInstance( Type::GetType( "System.Int32" ), 5 );
- for ( int i = myIntArray->GetLowerBound( 0 ); i <= myIntArray->GetUpperBound( 0 ); i++ )
- myIntArray->SetValue( i + 1, i );
-
- // Creates and initializes a new Array instance of type Object.
- Array^ myObjArray = Array::CreateInstance( Type::GetType( "System.Object" ), 5 );
- for ( int i = myObjArray->GetLowerBound( 0 ); i <= myObjArray->GetUpperBound( 0 ); i++ )
- myObjArray->SetValue( i + 26, i );
-
- // Displays the initial values of both arrays.
- Console::WriteLine( "Int32 array:" );
- PrintValues( myIntArray );
- Console::WriteLine( "Object array:" );
- PrintValues( myObjArray );
-
- // Copies the first element from the Int32 array to the Object array.
- Array::Copy( myIntArray, myIntArray->GetLowerBound( 0 ), myObjArray, myObjArray->GetLowerBound( 0 ), 1 );
-
- // Copies the last two elements from the Object array to the Int32 array.
- Array::Copy( myObjArray, myObjArray->GetUpperBound( 0 ) - 1, myIntArray, myIntArray->GetUpperBound( 0 ) - 1, 2 );
-
- // Displays the values of the modified arrays.
- Console::WriteLine( "Int32 array - Last two elements should now be the same as Object array:" );
- PrintValues( myIntArray );
- Console::WriteLine( "Object array - First element should now be the same as Int32 array:" );
- PrintValues( myObjArray );
-}
-
-void PrintValues( Array^ myArr )
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength( myArr->Rank - 1 );
- while ( myEnumerator->MoveNext() )
- {
- if ( i < cols )
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( "\t{0}", myEnumerator->Current );
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- Int32 array:
- 1 2 3 4 5
- Object array:
- 26 27 28 29 30
- Int32 array - Last two elements should now be the same as Object array:
- 1 2 3 29 30
- Object array - First element should now be the same as Int32 array:
- 1 27 28 29 30
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CopyTo Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CopyTo Example/CPP/source.cpp
deleted file mode 100644
index 2caab9082ed..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CopyTo Example/CPP/source.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-
-//
-using namespace System;
-
-void main()
-{
- // Creates and initializes two new Array instances.
- Array^ mySourceArray = Array::CreateInstance(String::typeid, 6);
- mySourceArray->SetValue("three", 0);
- mySourceArray->SetValue("napping", 1);
- mySourceArray->SetValue("cats", 2);
- mySourceArray->SetValue("in", 3);
- mySourceArray->SetValue("the", 4);
- mySourceArray->SetValue("barn", 5);
- Array^ myTargetArray = Array::CreateInstance(String::typeid, 15);
- myTargetArray->SetValue("The", 0);
- myTargetArray->SetValue("quick", 1);
- myTargetArray->SetValue("brown", 2);
- myTargetArray->SetValue("fox", 3);
- myTargetArray->SetValue("jumps", 4);
- myTargetArray->SetValue("over", 5);
- myTargetArray->SetValue("the", 6);
- myTargetArray->SetValue("lazy", 7);
- myTargetArray->SetValue("dog", 8);
-
- // Displays the values of the Array.
- Console::WriteLine( "The target Array instance contains the following (before and after copying):");
- PrintValues(myTargetArray);
-
- // Copies the source Array to the target Array, starting at index 6.
- mySourceArray->CopyTo(myTargetArray, 6);
-
- // Displays the values of the Array.
- PrintValues(myTargetArray);
-}
-
-void PrintValues(Array^ myArr)
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength(myArr->Rank - 1);
- while (myEnumerator->MoveNext())
- {
- if (i < cols)
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( " {0}", myEnumerator->Current);
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- The target Array instance contains the following (before and after copying):
- The quick brown fox jumps over the lazy dog
- The quick brown fox jumps over three napping cats in the barn
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CopyTo Example/CPP/source2.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CopyTo Example/CPP/source2.cpp
deleted file mode 100644
index ca74d220df4..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CopyTo Example/CPP/source2.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-//
-using namespace System;
-
-void main()
-{
- // Creates and initializes the source Array.
- Array^ myArrayZero = Array::CreateInstance(String::typeid, 3);
- myArrayZero->SetValue("zero", 0);
- myArrayZero->SetValue("one", 1);
-
- // Displays the source Array.
- Console::WriteLine("The array with lowbound=0 contains:");
- PrintIndexAndValues(myArrayZero);
-
- // Creates and initializes the target Array.
- array^myArrLen = {4};
- array^myArrLow = {2};
- Array^ myArrayTwo = Array::CreateInstance(String::typeid, myArrLen, myArrLow);
- myArrayTwo->SetValue("two", 2);
- myArrayTwo->SetValue("three", 3);
- myArrayTwo->SetValue("four", 4);
- myArrayTwo->SetValue("five", 5);
-
- // Displays the target Array.
- Console::WriteLine("The array with lowbound=2 contains:");
- PrintIndexAndValues(myArrayTwo);
-
- // Copy from the array with lowbound=0 to the array with lowbound=2.
- myArrayZero->CopyTo(myArrayTwo, 3);
-
- // Displays the modified target Array.
- Console::WriteLine("\nAfter copying at relative index 1:");
- PrintIndexAndValues(myArrayTwo);
-}
-
-void PrintIndexAndValues(Array^ myArray)
-{
- for (int i = myArray->GetLowerBound(0); i <= myArray->GetUpperBound(0); i++)
- Console::WriteLine("\t[{0}]:\t{1}", i, myArray->GetValue(i));
-}
-
-/*
- This code produces the following output.
-
- The array with lowbound=0 contains:
- [0]: zero
- [1]: one
- [2]:
- The array with lowbound=2 contains:
- [2]: two
- [3]: three
- [4]: four
- [5]: five
-
- After copying at relative index 1:
- [2]: two
- [3]: zero
- [4]: one
- [5]:
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance Example/CPP/source.cpp
deleted file mode 100644
index 6fb07cb3bf1..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance Example/CPP/source.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-
-//
-using namespace System;
-void PrintValues( Array^ myArr );
-void main()
-{
- // Creates and initializes a one-dimensional Array instance of type Int32.
- Array^ my1DArray = Array::CreateInstance( Int32::typeid, 5 );
- for ( int i = my1DArray->GetLowerBound( 0 ); i <= my1DArray->GetUpperBound( 0 ); i++ )
- my1DArray->SetValue( i + 1, i );
-
- // Displays the values of the Array.
- Console::WriteLine( "The one-dimensional Array instance contains the following values:" );
- PrintValues( my1DArray );
-}
-
-void PrintValues( Array^ myArr )
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength( myArr->Rank - 1 );
- while ( myEnumerator->MoveNext() )
- {
- if ( i < cols )
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( "\t{0}", myEnumerator->Current );
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- The one-dimensional Array instance contains the following values:
- 1 2 3 4 5
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance1 Example/CPP/source.cpp
deleted file mode 100644
index 782e95f0280..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-
-//
-using namespace System;
-void PrintValues( Array^ myArr );
-void main()
-{
- // Creates and initializes a two-dimensional Array instance of type String.
- Array^ my2DArray = Array::CreateInstance( String::typeid, 2, 3 );
- for ( int i = my2DArray->GetLowerBound( 0 ); i <= my2DArray->GetUpperBound( 0 ); i++ )
- for ( int j = my2DArray->GetLowerBound( 1 ); j <= my2DArray->GetUpperBound( 1 ); j++ )
- my2DArray->SetValue( String::Concat( "abc", i, j ), i, j );
-
- // Displays the values of the Array.
- Console::WriteLine( "The two-dimensional Array instance contains the following values:" );
- PrintValues( my2DArray );
-}
-
-void PrintValues( Array^ myArr )
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength( myArr->Rank - 1 );
- while ( myEnumerator->MoveNext() )
- {
- if ( i < cols )
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( "\t{0}", myEnumerator->Current );
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- The two-dimensional Array instance contains the following values:
- abc00 abc01 abc02
- abc10 abc11 abc12
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance2 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance2 Example/CPP/source.cpp
deleted file mode 100644
index dfc52829993..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance2 Example/CPP/source.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-
-//
-using namespace System;
-void PrintValues( Array^ myArr );
-void main()
-{
- // Creates and initializes a three-dimensional Array instance of type Object.
- Array^ my3DArray = Array::CreateInstance( Object::typeid, 2, 3, 4 );
- for ( int i = my3DArray->GetLowerBound( 0 ); i <= my3DArray->GetUpperBound( 0 ); i++ )
- for ( int j = my3DArray->GetLowerBound( 1 ); j <= my3DArray->GetUpperBound( 1 ); j++ )
- for ( int k = my3DArray->GetLowerBound( 2 ); k <= my3DArray->GetUpperBound( 2 ); k++ )
- my3DArray->SetValue( String::Concat( "abc", i, j, k ), i, j, k );
-
- // Displays the values of the Array.
- Console::WriteLine( "The three-dimensional Array instance contains the following values:" );
- PrintValues( my3DArray );
-}
-
-void PrintValues( Array^ myArr )
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength( myArr->Rank - 1 );
- while ( myEnumerator->MoveNext() )
- {
- if ( i < cols )
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( "\t{0}", myEnumerator->Current );
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- The three-dimensional Array instance contains the following values:
- abc000 abc001 abc002 abc003
- abc010 abc011 abc012 abc013
- abc020 abc021 abc022 abc023
- abc100 abc101 abc102 abc103
- abc110 abc111 abc112 abc113
- abc120 abc121 abc122 abc123
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance3 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance3 Example/CPP/source.cpp
deleted file mode 100644
index cf5aac93295..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance3 Example/CPP/source.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-
-//
-using namespace System;
-void PrintValues( Array^ myArr );
-void main()
-{
- // Creates and initializes a multidimensional Array instance of type String.
- array^myLengthsArray = {2,3,4,5};
- Array^ my4DArray = Array::CreateInstance( String::typeid, myLengthsArray );
- for ( int i = my4DArray->GetLowerBound( 0 ); i <= my4DArray->GetUpperBound( 0 ); i++ )
- for ( int j = my4DArray->GetLowerBound( 1 ); j <= my4DArray->GetUpperBound( 1 ); j++ )
- for ( int k = my4DArray->GetLowerBound( 2 ); k <= my4DArray->GetUpperBound( 2 ); k++ )
- for ( int l = my4DArray->GetLowerBound( 3 ); l <= my4DArray->GetUpperBound( 3 ); l++ )
- {
- array^myIndicesArray = {i,j,k,l};
- my4DArray->SetValue( String::Concat( Convert::ToString( i ), j, k, l ), myIndicesArray );
-
- }
-
- // Displays the values of the Array.
- Console::WriteLine( "The four-dimensional Array instance contains the following values:" );
- PrintValues( my4DArray );
-}
-
-void PrintValues( Array^ myArr )
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength( myArr->Rank - 1 );
- while ( myEnumerator->MoveNext() )
- {
- if ( i < cols )
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( "\t{0}", myEnumerator->Current );
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- The four-dimensional Array instance contains the following values:
- 0000 0001 0002 0003 0004
- 0010 0011 0012 0013 0014
- 0020 0021 0022 0023 0024
- 0030 0031 0032 0033 0034
- 0100 0101 0102 0103 0104
- 0110 0111 0112 0113 0114
- 0120 0121 0122 0123 0124
- 0130 0131 0132 0133 0134
- 0200 0201 0202 0203 0204
- 0210 0211 0212 0213 0214
- 0220 0221 0222 0223 0224
- 0230 0231 0232 0233 0234
- 1000 1001 1002 1003 1004
- 1010 1011 1012 1013 1014
- 1020 1021 1022 1023 1024
- 1030 1031 1032 1033 1034
- 1100 1101 1102 1103 1104
- 1110 1111 1112 1113 1114
- 1120 1121 1122 1123 1124
- 1130 1131 1132 1133 1134
- 1200 1201 1202 1203 1204
- 1210 1211 1212 1213 1214
- 1220 1221 1222 1223 1224
- 1230 1231 1232 1233 1234
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance4 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance4 Example/CPP/source.cpp
deleted file mode 100644
index cc1ff6dbbc9..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.CreateInstance4 Example/CPP/source.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-
-//
-using namespace System;
-void PrintValues( Array^ myArr );
-void main()
-{
- // Creates and initializes a multidimensional Array instance of type String.
- array^myLengthsArray = {3,5};
- array^myBoundsArray = {2,3};
- Array^ myArray = Array::CreateInstance( String::typeid, myLengthsArray, myBoundsArray );
- for ( int i = myArray->GetLowerBound( 0 ); i <= myArray->GetUpperBound( 0 ); i++ )
- for ( int j = myArray->GetLowerBound( 1 ); j <= myArray->GetUpperBound( 1 ); j++ )
- {
- array^myIndicesArray = {i,j};
- myArray->SetValue( String::Concat( Convert::ToString( i ), j ), myIndicesArray );
-
- }
-
- // Displays the lower bounds and the upper bounds of each dimension.
- Console::WriteLine( "Bounds:\tLower\tUpper" );
- for ( int i = 0; i < myArray->Rank; i++ )
- Console::WriteLine( "{0}:\t{1}\t{2}", i, myArray->GetLowerBound( i ), myArray->GetUpperBound( i ) );
-
- // Displays the values of the Array.
- Console::WriteLine( "The Array instance contains the following values:" );
- PrintValues( myArray );
-}
-
-void PrintValues( Array^ myArr )
-{
- System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
- int i = 0;
- int cols = myArr->GetLength( myArr->Rank - 1 );
- while ( myEnumerator->MoveNext() )
- {
- if ( i < cols )
- {
- i++;
- }
- else
- {
- Console::WriteLine();
- i = 1;
- }
-
- Console::Write( "\t{0}", myEnumerator->Current );
- }
-
- Console::WriteLine();
-}
-
-/*
- This code produces the following output.
-
- Bounds: Lower Upper
- 0: 2 4
- 1: 3 7
- The Array instance contains the following values:
- 23 24 25 26 27
- 33 34 35 36 37
- 43 44 45 46 47
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.IndexOf Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.IndexOf Example/CPP/source.cpp
deleted file mode 100644
index 18923bcbb6c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.IndexOf Example/CPP/source.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-
-//
-using namespace System;
-
-void main()
-{
- // Create a string array with 3 elements having the same value.
- array^ strings = { "the", "quick", "brown", "fox",
- "jumps", "over", "the", "lazy", "dog",
- "in", "the", "barn" };
-
- // Display the elements of the array.
- Console::WriteLine("The array contains the following values:");
- for (int i = strings->GetLowerBound(0); i <= strings->GetUpperBound(0); i++)
- Console::WriteLine(" [{0,2}]: {1}", i, strings[i]);
-
- // Search for the first occurrence of the duplicated value.
- String^ searchString = "the";
- int index = Array::IndexOf(strings, searchString);
- Console::WriteLine("The first occurrence of \"{0}\" is at index {1}.",
- searchString, index);
-
- // Search for the first occurrence of the duplicated value in the last section of the array.
- index = Array::IndexOf( strings, searchString, 4);
- Console::WriteLine("The first occurrence of \"{0}\" between index 4 and the end is at index {1}.",
- searchString, index);
-
- // Search for the first occurrence of the duplicated value in a section of the array.
- int position = index + 1;
- index = Array::IndexOf(strings, searchString, position, strings->GetUpperBound(0) - position + 1);
- Console::WriteLine("The first occurrence of \"{0}\" between index {1} and index {2} is at index {3}.",
- searchString, position, strings->GetUpperBound(0), index);
-}
-// The example displays the following output:
-// The array contains the following values:
-// [ 0]: the
-// [ 1]: quick
-// [ 2]: brown
-// [ 3]: fox
-// [ 4]: jumps
-// [ 5]: over
-// [ 6]: the
-// [ 7]: lazy
-// [ 8]: dog
-// [ 9]: in
-// [10]: the
-// [11]: barn
-// The first occurrence of "the" is at index 0.
-// The first occurrence of "the" between index 4 and the end is at index 6.
-// The first occurrence of "the" between index 7 and index 11 is at index 10.
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.LastIndexOf Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.LastIndexOf Example/CPP/source.cpp
deleted file mode 100644
index 1b8d7459315..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.LastIndexOf Example/CPP/source.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-
-//
-using namespace System;
-void PrintIndexAndValues( Array^ myArray );
-
-void main()
-{
- // Creates and initializes a new Array instance with three elements of the same value.
- Array^ myArray = Array::CreateInstance( String::typeid, 12 );
- myArray->SetValue( "the", 0 );
- myArray->SetValue( "quick", 1 );
- myArray->SetValue( "brown", 2 );
- myArray->SetValue( "fox", 3 );
- myArray->SetValue( "jumps", 4 );
- myArray->SetValue( "over", 5 );
- myArray->SetValue( "the", 6 );
- myArray->SetValue( "lazy", 7 );
- myArray->SetValue( "dog", 8 );
- myArray->SetValue( "in", 9 );
- myArray->SetValue( "the", 10 );
- myArray->SetValue( "barn", 11 );
-
- // Displays the values of the Array.
- Console::WriteLine( "The Array instance contains the following values:" );
- PrintIndexAndValues( myArray );
-
- // Searches for the last occurrence of the duplicated value.
- String^ myString = "the";
- int myIndex = Array::LastIndexOf( myArray, myString );
- Console::WriteLine( "The last occurrence of \"{0}\" is at index {1}.", myString, myIndex );
-
- // Searches for the last occurrence of the duplicated value in the first section of the Array.
- myIndex = Array::LastIndexOf( myArray, myString, 8 );
- Console::WriteLine( "The last occurrence of \"{0}\" between the start and index 8 is at index {1}.", myString, myIndex );
-
- // Searches for the last occurrence of the duplicated value in a section of the Array.
- // Note that the start index is greater than the end index because the search is done backward.
- myIndex = Array::LastIndexOf( myArray, myString, 10, 6 );
- Console::WriteLine( "The last occurrence of \"{0}\" between index 5 and index 10 is at index {1}.", myString, myIndex );
-}
-
-void PrintIndexAndValues( Array^ myArray )
-{
- for ( int i = myArray->GetLowerBound( 0 ); i <= myArray->GetUpperBound( 0 ); i++ )
- Console::WriteLine( "\t[{0}]:\t{1}", i, myArray->GetValue( i ) );
-}
-
-/*
- This code produces the following output.
-
- The Array instance contains the following values:
- [0]: the
- [1]: quick
- [2]: brown
- [3]: fox
- [4]: jumps
- [5]: over
- [6]: the
- [7]: lazy
- [8]: dog
- [9]: in
- [10]: the
- [11]: barn
- The last occurrence of "the" is at index 10.
- The last occurrence of "the" between the start and index 8 is at index 6.
- The last occurrence of "the" between index 5 and index 10 is at index 10.
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Reverse Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Reverse Example/CPP/source.cpp
deleted file mode 100644
index 097d0727938..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Reverse Example/CPP/source.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-
-//
-using namespace System;
-void PrintIndexAndValues( Array^ myArray );
-void main()
-{
- // Creates and initializes a new Array instance.
- Array^ myArray = Array::CreateInstance( String::typeid, 9 );
- myArray->SetValue( "The", 0 );
- myArray->SetValue( "quick", 1 );
- myArray->SetValue( "brown", 2 );
- myArray->SetValue( "fox", 3 );
- myArray->SetValue( "jumps", 4 );
- myArray->SetValue( "over", 5 );
- myArray->SetValue( "the", 6 );
- myArray->SetValue( "lazy", 7 );
- myArray->SetValue( "dog", 8 );
-
- // Displays the values of the Array.
- Console::WriteLine( "The Array instance initially contains the following values:" );
- PrintIndexAndValues( myArray );
-
- // Reverses the sort of the values of the Array.
- Array::Reverse( myArray );
-
- // Displays the values of the Array.
- Console::WriteLine( "After reversing:" );
- PrintIndexAndValues( myArray );
-}
-
-void PrintIndexAndValues( Array^ myArray )
-{
- for ( int i = myArray->GetLowerBound( 0 ); i <= myArray->GetUpperBound( 0 ); i++ )
- Console::WriteLine( "\t[{0}]:\t{1}", i, myArray->GetValue( i ) );
-}
-
-/*
- This code produces the following output.
-
- The Array instance initially contains the following values:
- [0]: The
- [1]: quick
- [2]: brown
- [3]: fox
- [4]: jumps
- [5]: over
- [6]: the
- [7]: lazy
- [8]: dog
- After reversing:
- [0]: dog
- [1]: lazy
- [2]: the
- [3]: over
- [4]: jumps
- [5]: fox
- [6]: brown
- [7]: quick
- [8]: The
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Reverse1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Reverse1 Example/CPP/source.cpp
deleted file mode 100644
index 1f394ab0ee6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Array.Reverse1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-
-//
-using namespace System;
-void PrintIndexAndValues( Array^ myArray );
-void main()
-{
- // Creates and initializes a new Array instance.
- Array^ myArray = Array::CreateInstance( String::typeid, 9 );
- myArray->SetValue( "The", 0 );
- myArray->SetValue( "QUICK", 1 );
- myArray->SetValue( "BROWN", 2 );
- myArray->SetValue( "FOX", 3 );
- myArray->SetValue( "jumps", 4 );
- myArray->SetValue( "over", 5 );
- myArray->SetValue( "the", 6 );
- myArray->SetValue( "lazy", 7 );
- myArray->SetValue( "dog", 8 );
-
- // Displays the values of the Array.
- Console::WriteLine( "The Array instance initially contains the following values:" );
- PrintIndexAndValues( myArray );
-
- // Reverses the sort of the values of the Array.
- Array::Reverse( myArray, 1, 3 );
-
- // Displays the values of the Array.
- Console::WriteLine( "After reversing:" );
- PrintIndexAndValues( myArray );
-}
-
-void PrintIndexAndValues( Array^ myArray )
-{
- for ( int i = myArray->GetLowerBound( 0 ); i <= myArray->GetUpperBound( 0 ); i++ )
- Console::WriteLine( "\t[{0}]:\t{1}", i, myArray->GetValue( i ) );
-}
-
-/*
- This code produces the following output.
-
- The Array instance initially contains the following values:
- [0]: The
- [1]: QUICK
- [2]: BROWN
- [3]: FOX
- [4]: jumps
- [5]: over
- [6]: the
- [7]: lazy
- [8]: dog
- After reversing:
- [0]: The
- [1]: FOX
- [2]: BROWN
- [3]: QUICK
- [4]: jumps
- [5]: over
- [6]: the
- [7]: lazy
- [8]: dog
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Assembly.GetModules Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Assembly.GetModules Example/CPP/source.cpp
deleted file mode 100644
index ecaba9d9d0b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Assembly.GetModules Example/CPP/source.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Assembly^ mainAssembly = Assembly::GetExecutingAssembly();
- Console::WriteLine( "The executing assembly is {0}.", mainAssembly );
- array^mods = mainAssembly->GetModules();
- Console::WriteLine( "\tModules in the assembly:" );
- for ( int i = 0; i < mods->Length; i++ )
- Console::WriteLine( "\t{0}", mods[ i ] );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic AttributeUsageAttribute.AttributeUsageAttribute Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic AttributeUsageAttribute.AttributeUsageAttribute Example/CPP/source.cpp
deleted file mode 100644
index 2aa6055f25c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic AttributeUsageAttribute.AttributeUsageAttribute Example/CPP/source.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-#using
-
-using namespace System;
-
-//
-namespace InteropServices
-{
- [AttributeUsage(AttributeTargets::Method|
- AttributeTargets::Field|
- AttributeTargets::Property)
- ]
- public ref class DispIdAttribute: public Attribute
- {
- public:
- DispIdAttribute( int value )
- {
- // . . .
- }
-
- property int Value
- {
- int get()
- {
- // . . .
- return 0;
- }
- }
- };
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic CompilerError Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic CompilerError Example/CPP/source.cpp
deleted file mode 100644
index b9c151ae5a8..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic CompilerError Example/CPP/source.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-
-
-//
-#using
-
-using namespace System;
-using namespace System::CodeDom;
-using namespace System::CodeDom::Compiler;
-using namespace Microsoft::CSharp;
-CodeCompileUnit^ GetCompileUnit()
-{
-
- // Create a compile unit to contain a CodeDOM graph.
- CodeCompileUnit^ cu = gcnew CodeCompileUnit;
-
- // Create a namespace named TestSpace.
- CodeNamespace^ cn = gcnew CodeNamespace( "TestSpace" );
-
- // Declare a new type named TestClass.
- CodeTypeDeclaration^ cd = gcnew CodeTypeDeclaration( "TestClass" );
-
- // Declare a new member string field named TestField.
- CodeMemberField^ cmf = gcnew CodeMemberField( "System.String","TestField" );
-
- // Add the field to the type.
- cd->Members->Add( cmf );
-
- // Declare a new member method named TestMethod.
- CodeMemberMethod^ cm = gcnew CodeMemberMethod;
- cm->Name = "TestMethod";
-
- // Declare a string variable named TestVariable.
- CodeVariableDeclarationStatement^ cvd = gcnew CodeVariableDeclarationStatement( "System.String1","TestVariable" );
- cm->Statements->Add( cvd );
-
- // Cast the TestField reference expression to string and assign it to the TestVariable.
- CodeAssignStatement^ ca = gcnew CodeAssignStatement( gcnew CodeVariableReferenceExpression( "TestVariable" ),gcnew CodeCastExpression( "System.String2",gcnew CodeFieldReferenceExpression( gcnew CodeThisReferenceExpression,"TestField" ) ) );
-
- // This code can be used to generate the following code in C#:
- // TestVariable = ((string)(this.TestField));
- cm->Statements->Add( ca );
-
- // Add the TestMethod member to the TestClass type.
- cd->Members->Add( cm );
-
- // Add the TestClass type to the namespace.
- cn->Types->Add( cd );
-
- // Add the TestSpace namespace to the compile unit.
- cu->Namespaces->Add( cn );
- return cu;
-}
-
-int main()
-{
-
- // Output some program information using Console.WriteLine.
- Console::WriteLine( "This program compiles a CodeDOM program that incorrectly declares multiple data" );
- Console::WriteLine( "types to demonstrate handling compiler errors programmatically." );
- Console::WriteLine( "" );
-
- // Compile the CodeCompileUnit retrieved from the GetCompileUnit() method.
- //CSharpCodeProvider ^ provider = gcnew Microsoft::CSharp::CSharpCodeProvider;
- CodeDomProvider ^ provider = CodeDomProvider::CreateProvider("CSharp");
-
- // Initialize a CompilerParameters with the options for compilation.
- array^assemblies = {"System.dll"};
- CompilerParameters^ options = gcnew CompilerParameters( assemblies,"output.exe" );
-
- // Compile the CodeDOM graph and store the results in a CompilerResults.
- CompilerResults^ results = provider->CompileAssemblyFromDom( options, GetCompileUnit() );
-
- // Compilation produces errors. Print out each error.
- Console::WriteLine( "Listing errors from compilation: " );
- Console::WriteLine( "" );
- for ( int i = 0; i < results->Errors->Count; i++ )
- Console::WriteLine( results->Errors[ i ] );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CPP/source.cpp
deleted file mode 100644
index 494de16ea1c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CPP/source.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Globalization;
-void main()
-{
- DateTime dt = DateTime::Now;
- array^format = {L"d",L"D",L"f",L"F",L"g",L"G",L"m",L"r",L"s",L"t",L"T",L"u",L"U",L"y",L"dddd, MMMM dd yyyy",L"ddd, MMM d \"'\"yy",L"dddd, MMMM dd",L"M/yy",L"dd-MM-yy"};
- String^ date;
- for ( int i = 0; i < format->Length; i++ )
- {
- date = dt.ToString( format[ i ], DateTimeFormatInfo::InvariantInfo );
- Console::WriteLine( String::Concat( format[ i ], L" :", date ) );
-
- }
-
- /** Output.
- *
- * d :08/17/2000
- * D :Thursday, August 17, 2000
- * f :Thursday, August 17, 2000 16:32
- * F :Thursday, August 17, 2000 16:32:32
- * g :08/17/2000 16:32
- * G :08/17/2000 16:32:32
- * m :August 17
- * r :Thu, 17 Aug 2000 23:32:32 GMT
- * s :2000-08-17T16:32:32
- * t :16:32
- * T :16:32:32
- * u :2000-08-17 23:32:32Z
- * U :Thursday, August 17, 2000 23:32:32
- * y :August, 2000
- * dddd, MMMM dd yyyy :Thursday, August 17 2000
- * ddd, MMM d "'"yy :Thu, Aug 17 '00
- * dddd, MMMM dd :Thursday, August 17
- * M/yy :8/00
- * dd-MM-yy :17-08-00
- */
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Delegate Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Delegate Example/CPP/source.cpp
deleted file mode 100644
index ec2ce96c984..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Delegate Example/CPP/source.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-
-
-//
-using namespace System;
-delegate String^ myMethodDelegate( // Declares a delegate for a method that takes in an int and returns a String.
-int myInt );
-
-// Defines some methods to which the delegate can point.
-ref class mySampleClass
-{
-public:
-
- // Defines an instance method.
- String^ myStringMethod( int myInt )
- {
- if ( myInt > 0 )
- return ("positive");
-
- if ( myInt < 0 )
- return ("negative");
-
- return ("zero");
- }
-
-
- // Defines a static method.
- static String^ mySignMethod( int myInt )
- {
- if ( myInt > 0 )
- return ("+");
-
- if ( myInt < 0 )
- return ("-");
-
- return ("");
- }
-
-};
-
-int main()
-{
-
- // Creates one delegate for each method. For the instance method, an
- // instance (mySC) must be supplied. For the static method, only the
- // method name is needed.
- mySampleClass^ mySC = gcnew mySampleClass;
- myMethodDelegate^ myD1 = gcnew myMethodDelegate( mySC, &mySampleClass::myStringMethod );
- myMethodDelegate^ myD2 = gcnew myMethodDelegate( mySampleClass::mySignMethod );
-
- // Invokes the delegates.
- Console::WriteLine( "{0} is {1}; use the sign \"{2}\".", 5, myD1( 5 ), myD2( 5 ) );
- Console::WriteLine( "{0} is {1}; use the sign \"{2}\".", -3, myD1( -3 ), myD2( -3 ) );
- Console::WriteLine( "{0} is {1}; use the sign \"{2}\".", 0, myD1( 0 ), myD2( 0 ) );
-}
-
-/*
-This code produces the following output:
-
-5 is positive; use the sign "+".
--3 is negative; use the sign "-".
-0 is zero; use the sign "".
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Enum.ToString2 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Enum.ToString2 Example/CPP/source.cpp
deleted file mode 100644
index f3f215111a7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Enum.ToString2 Example/CPP/source.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-
-//
-using namespace System;
-public ref class EnumSample
-{
-public:
- enum class Colors
- {
- Red = 1,
- Blue = 2
- };
-
- static void main()
- {
- Enum ^ myColors = Colors::Red;
- Console::WriteLine( "The value of this instance is '{0}'", myColors );
- }
-
-};
-
-int main()
-{
- EnumSample::main();
-}
-
-/*
-Output.
-The value of this instance is 'Red'.
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldAttributes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldAttributes Example/CPP/source.cpp
deleted file mode 100644
index 2c4a0747c4a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldAttributes Example/CPP/source.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Security::Permissions;
-
-public ref class Demo
-{
-private:
- // Make three fields:
- // The first field is private.
- String^ m_field;
-
- // The second field is public.
-public:
- String^ Field;
-
- // The third field is public and literal.
- literal String^ FieldC = "String C";
-
- Demo() { m_field = "String A"; Field = "String B"; }
-};
-
-static void DisplayField(Object^ obj, FieldInfo^ f)
-{
- // Display the field name, value, and attributes.
- //
- Console::WriteLine("{0} = \"{1}\"; attributes: {2}",
- f->Name, f->GetValue(obj), f->Attributes);
-};
-
-void main()
-{
- Console::WriteLine ("\nReflection.FieldAttributes");
- Demo^ d = gcnew Demo();
-
- // Get a Type object for Demo, and a FieldInfo for each of
- // the three fields. Use the FieldInfo to display field
- // name, value for the Demo object in d, and attributes.
- //
- Type^ myType = Demo::typeid;
-
- FieldInfo^ fiPrivate = myType->GetField("m_field",
- BindingFlags::NonPublic | BindingFlags::Instance);
- DisplayField(d, fiPrivate);
-
- FieldInfo^ fiPublic = myType->GetField("Field",
- BindingFlags::Public | BindingFlags::Instance);
- DisplayField(d, fiPublic);
-
- FieldInfo^ fiConstant = myType->GetField("FieldC",
- BindingFlags::Public | BindingFlags::Static);
- DisplayField(d, fiConstant);
-}
-
-/* This code example produces the following output:
-
-Reflection.FieldAttributes
-m_field = "String A"; attributes: Private
-Field = "String B"; attributes: Public
-FieldC = "String C"; attributes: Public, Static, Literal, HasDefault
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.FieldType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.FieldType Example/CPP/source.cpp
deleted file mode 100644
index d04993ffecd..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.FieldType Example/CPP/source.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class TestClass
-{
- // Define a field.
- private:
- String^ field = "private field" ;
-
-// public:
-// Myfield()
-// : field( "private field" )
-// {}
-//
-//
-// property String^ Field
-// {
-// String^ get()
-// {
-// return field;
-// }
-//
-// }
-};
-
-void main()
-{
- TestClass^ cl = gcnew TestClass;
-
- // Get the type and FieldInfo.
- Type^ t = cl->GetType();
- FieldInfo^ fi = t->GetField("field",
- static_cast(BindingFlags::Instance | BindingFlags::NonPublic));
-
- // Get and display the Ftype s ieldType.
- Console::WriteLine("Field Name: {0}.{1}", t->FullName, fi->Name );
- Console::WriteLine("Field Value: '{0}'", fi->GetValue(cl));
- Console::WriteLine("Field Type: {0}", fi->FieldType);
-}
-// The example displays the following output:
-// Field Name: TestClass.field
-// Field Value: 'private field'
-// Field Type: System.String
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsAssembly Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsAssembly Example/CPP/source.cpp
deleted file mode 100644
index 11c0acbac47..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsAssembly Example/CPP/source.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class Example
-{
-public:
- int f_public;
-internal:
- int f_internal;
-protected:
- int f_protected;
-protected public:
- int f_protected_public;
-protected private:
- int f_protected_private;
-};
-
-void main()
-{
- Console::WriteLine("\n{0,-30}{1,-18}{2}", "", "IsAssembly", "IsFamilyOrAssembly");
- Console::WriteLine("{0,-21}{1,-18}{2,-18}{3}\n",
- "", "IsPublic", "IsFamily", "IsFamilyAndAssembly");
-
- for each (FieldInfo^ f in Example::typeid->GetFields(
- BindingFlags::Instance | BindingFlags::NonPublic | BindingFlags::Public))
- {
- Console::WriteLine("{0,-21}{1,-9}{2,-9}{3,-9}{4,-9}{5,-9}",
- f->Name,
- f->IsPublic,
- f->IsAssembly,
- f->IsFamily,
- f->IsFamilyOrAssembly,
- f->IsFamilyAndAssembly
- );
- }
-}
-
-/* This code example produces output similar to the following:
-
- IsAssembly IsFamilyOrAssembly
- IsPublic IsFamily IsFamilyAndAssembly
-
-f_public True False False False False
-f_internal False True False False False
-f_protected False False True False False
-f_protected_public False False False True False
-f_protected_private False False False False True
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsInitOnly Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsInitOnly Example/CPP/source.cpp
deleted file mode 100644
index e4ab406d1aa..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsInitOnly Example/CPP/source.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-//Make two fields, one public and one read-only.
-public ref class Myfielda
-{
-public:
- String^ field;
- Myfielda()
- : field( "A - public field" )
- {}
-
-
- property String^ Field
- {
- String^ get()
- {
- return field;
- }
-
- void set( String^ value )
- {
- if ( field != value )
- {
- field = value;
- }
- }
-
- }
-
-};
-
-public ref class Myfieldb
-{
-private:
- String^ const field;
-
-public:
- Myfieldb()
- : field( "B - readonly field" )
- {}
-
-
- property String^ Field
- {
- String^ get()
- {
- return field;
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.FieldInfo" );
- Myfielda^ myfielda = gcnew Myfielda;
- Myfieldb^ myfieldb = gcnew Myfieldb;
-
- //Get the Type and FieldInfo.
- Type^ MyTypea = Type::GetType( "Myfielda" );
- FieldInfo^ Myfieldinfoa = MyTypea->GetField( "field", static_cast(BindingFlags::Public | BindingFlags::Instance) );
- Type^ MyTypeb = Type::GetType( "Myfieldb" );
- FieldInfo^ Myfieldinfob = MyTypeb->GetField( "field", static_cast(BindingFlags::NonPublic | BindingFlags::Instance) );
-
- //Modify the fields.
- //Note that Myfieldb is not modified, as it is
- //read-only (IsInitOnly is True).
- myfielda->field = "A- modified";
-
- //Myfieldb.field = "B- modified";
- //For the first field, get and display the name, field, and IsInitOnly state.
- Console::Write( "\n{0} - {1}, IsInitOnly = {2} ", MyTypea->FullName, Myfieldinfoa->GetValue( myfielda ), Myfieldinfoa->IsInitOnly );
-
- //For the second field get and display the name, field, and IsInitOnly state.
- Console::Write( "\n{0} - {1}, IsInitOnly = {2} ", MyTypeb->FullName, Myfieldinfob->GetValue( myfieldb ), Myfieldinfob->IsInitOnly );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsPublic Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsPublic Example/CPP/source.cpp
deleted file mode 100644
index 622ef650283..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsPublic Example/CPP/source.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Make two fields.
-// private
-public ref class Myfielda
-{
-private:
- String^ SomeField;
-
-public:
- Myfielda()
- : SomeField( "private field" )
- {}
-
-
- property String^ Field
- {
- String^ get()
- {
- return SomeField;
- }
-
- }
-
-};
-
-
-// public
-public ref class Myfieldb
-{
-public:
- String^ SomeField;
- Myfieldb()
- : SomeField( "public field" )
- {}
-
-
- property String^ Field
- {
- String^ get()
- {
- return SomeField;
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.FieldInfo" );
- Myfielda^ myfielda = gcnew Myfielda;
- Myfieldb^ myfieldb = gcnew Myfieldb;
-
- // Get the Type and FieldInfo.
- Type^ MyTypea = Type::GetType( "Myfielda" );
- FieldInfo^ Myfieldinfoa = MyTypea->GetField( "SomeField", static_cast(BindingFlags::NonPublic | BindingFlags::Instance) );
- Type^ MyTypeb = Type::GetType( "Myfieldb" );
- FieldInfo^ Myfieldinfob = MyTypeb->GetField( "SomeField" );
-
- // Get and display the IsPublic and IsPrivate property values.
- Console::Write( "\n{0}.", MyTypea->FullName );
- Console::Write( "{0} - ", Myfieldinfoa->Name );
- Console::Write( "{0}", myfielda->Field );
- Console::Write( "\n IsPublic = {0}", Myfieldinfoa->IsPublic );
- Console::Write( "\n IsPrivate = {0}", Myfieldinfoa->IsPrivate );
- Console::Write( "\n{0}.", MyTypeb->FullName );
- Console::Write( "{0} - ", Myfieldinfob->Name );
- Console::Write( "{0};", myfieldb->Field );
- Console::Write( "\n IsPublic = {0}", Myfieldinfob->IsPublic );
- Console::Write( "\n IsPrivate = {0}", Myfieldinfob->IsPrivate );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsStatic Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsStatic Example/CPP/source.cpp
deleted file mode 100644
index cac0b79e4d2..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.IsStatic Example/CPP/source.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Make two fields.
-public ref class Myfielda
-{
-private:
- String^ field;
-
-public:
- Myfielda()
- : field( "A private field" )
- {}
-
-
- property String^ Field
- {
- String^ get()
- {
- return field;
- }
-
- void set( String^ value )
- {
- if ( field != value )
- {
- field = value;
- }
- }
-
- }
-
-};
-
-public ref class Myfieldb
-{
-private:
- static String^ field = "B static field";
-
-public:
-
- property String^ Field
- {
- String^ get()
- {
- return field;
- }
-
- void set( String^ value )
- {
- if ( field != value )
- {
- field = value;
- }
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.FieldInfo" );
- Myfielda^ myfielda = gcnew Myfielda;
- Myfieldb^ myfieldb = gcnew Myfieldb;
-
- // Get the Type and FieldInfo.
- Type^ MyTypea = Type::GetType( "Myfielda" );
- FieldInfo^ Myfieldinfoa = MyTypea->GetField( "field", static_cast(BindingFlags::NonPublic | BindingFlags::Instance) );
- Type^ MyTypeb = Type::GetType( "Myfieldb" );
- FieldInfo^ Myfieldinfob = MyTypeb->GetField( "field", static_cast(BindingFlags::NonPublic | BindingFlags::Static) );
-
- // For the first field, get and display the name, field, and IsStatic property value.
- Console::Write( "\n{0} - ", MyTypea->FullName );
- Console::Write( "{0}; ", Myfieldinfoa->GetValue( myfielda ) );
- Console::Write( "IsStatic - {0}", Myfieldinfoa->IsStatic );
-
- // For the second field get and display the name, field, and IsStatic property value.
- Console::Write( "\n{0} - ", MyTypeb->FullName );
- Console::Write( "{0}; ", Myfieldinfob->GetValue( myfieldb ) );
- Console::Write( "IsStatic - {0}", Myfieldinfob->IsStatic );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.MemberType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.MemberType Example/CPP/source.cpp
deleted file mode 100644
index 0daa04b49b6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic FieldInfo.MemberType Example/CPP/source.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Make a field.
-public ref class Myfield
-{
-private:
- String^ field;
-
-public:
- Myfield()
- : field( "a private field" )
- {}
-
-
- property String^ Field
- {
- String^ get()
- {
- return field;
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.FieldInfo" );
- Myfield^ myfield = gcnew Myfield;
-
- // Get the Type and FieldInfo.
- Type^ MyType = Type::GetType( "Myfield" );
- FieldInfo^ Myfieldinfo = MyType->GetField( "field", static_cast(BindingFlags::NonPublic | BindingFlags::Instance) );
-
- // Get and display the MemberType.
- Console::Write( "\n{0}.", MyType->FullName );
- Console::Write( "{0} - ", Myfieldinfo->Name );
- Console::Write( "{0};", myfield->Field );
- MemberTypes Mymembertypes = Myfieldinfo->MemberType;
- Console::Write( "MemberType is a {0}.", Mymembertypes );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic IReflect.InvokeMember Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic IReflect.InvokeMember Example/CPP/source.cpp
deleted file mode 100644
index adbeb6fbeac..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic IReflect.InvokeMember Example/CPP/source.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-//
-#using
-
-using namespace System;
-using namespace System::Reflection;
-
-#define NULL 0
-void main()
-{
- Type^ tDate = Type::GetType( L"System.DateTime" );
- Object^ result = tDate->InvokeMember( L"Now", BindingFlags::GetProperty, nullptr, NULL, gcnew array(0) );
- Console::WriteLine( result->ToString() );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round Example/CPP/source.cpp
deleted file mode 100644
index 13ab6a90a87..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round Example/CPP/source.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-//
-using namespace System;
-
-void main()
-{
- Console::WriteLine("Classic Math.Round in CPP");
- Console::WriteLine(Math::Round(4.4)); // 4
- Console::WriteLine(Math::Round(4.5)); // 4
- Console::WriteLine(Math::Round(4.6)); // 5
- Console::WriteLine(Math::Round(5.5)); // 6
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round2 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round2 Example/CPP/source.cpp
deleted file mode 100644
index e9c1085e6f1..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round2 Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#using
-
-using namespace System;
-
-ref class Sample
-{
-private:
- void Method()
- {
- //
- Math::Round(3.44, 1); //Returns 3.4.
- Math::Round(3.45, 1); //Returns 3.4.
- Math::Round(3.46, 1); //Returns 3.5.
-
- Math::Round(4.34, 1); // Returns 4.3
- Math::Round(4.35, 1); // Returns 4.4
- Math::Round(4.36, 1); // Returns 4.4
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.MemberType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.MemberType Example/CPP/source.cpp
deleted file mode 100644
index fca76263e2b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.MemberType Example/CPP/source.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Console::WriteLine( "\nReflection.MemberInfo" );
-
- // Get the Type and MemberInfo.
- Type^ MyType = Type::GetType( "System.Reflection.PropertyInfo" );
- array^Mymemberinfoarray = MyType->GetMembers();
-
- // Get the MemberType method and display the elements.
- Console::Write( "\nThere are {0} members in ", Mymemberinfoarray->GetLength( 0 ) );
- Console::Write( "{0}.", MyType->FullName );
- for ( int counter = 0; counter < Mymemberinfoarray->Length; counter++ )
- {
- Console::Write( "\n{0}. {1} Member type - {2}", counter, Mymemberinfoarray[ counter ]->Name, Mymemberinfoarray[ counter ]->MemberType );
-
- }
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.Name Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.Name Example/CPP/source.cpp
deleted file mode 100644
index f4a7d06c3ce..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.Name Example/CPP/source.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-void main()
-{
- // Get the Type and MemberInfo.
- Type^ t = Type::GetType("System.Empty");
- array^ memberArray = t->GetMembers();
-
- // Get and display the type that declares the member.
- Console::WriteLine("There are {0} members in {1}",
- memberArray->Length, t->FullName);
- for each (MemberInfo^ member in memberArray) {
- Console::WriteLine("Member {0} declared by {1}",
- member->Name, member->DeclaringType);
- }
-}
-// The example displays the following output:
-// There are 6 members in System.Empty
-// Member ToString declared by System.Empty
-// Member GetObjectData declared by System.Empty
-// Member Equals declared by System.Object
-// Member GetHashCode declared by System.Object
-// Member GetType declared by System.Object
-// Member Value declared by System.Empty
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.ReflectedType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.ReflectedType Example/CPP/source.cpp
deleted file mode 100644
index 04e9498bfd7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MemberInfo.ReflectedType Example/CPP/source.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-int main()
-{
- MemberInfo^ m1 = Object::typeid->GetMethod("ToString");
- MemberInfo^ m2 = MemberInfo::typeid->GetMethod("ToString");
-
- Console::WriteLine("m1.DeclaringType: {0}", m1->DeclaringType);
- Console::WriteLine("m1.ReflectedType: {0}", m1->ReflectedType);
- Console::WriteLine();
- Console::WriteLine("m2.DeclaringType: {0}", m2->DeclaringType);
- Console::WriteLine("m2.ReflectedType: {0}", m2->ReflectedType);
-
- //Console::ReadLine();
-}
-
-/* This code example produces the following output:
-
-m1.DeclaringType: System.Object
-m1.ReflectedType: System.Object
-
-m2.DeclaringType: System.Object
-m2.ReflectedType: System.Reflection.MemberInfo
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodAttributes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodAttributes Example/CPP/source.cpp
deleted file mode 100644
index d9f1db69a7b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodAttributes Example/CPP/source.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::InteropServices;
-
-public ref class AttributesSample
-{
-public:
- void Mymethod( int int1m, [Out]interior_ptr str2m, interior_ptr str3m )
- {
- *str2m = "in Mymethod";
- }
-};
-
-void PrintAttributes( Type^ attribType, int iAttribValue )
-{
- if ( !attribType->IsEnum )
- {
- Console::WriteLine( "This type is not an enum." );
- return;
- }
-
- array^fields = attribType->GetFields( static_cast(BindingFlags::Public | BindingFlags::Static) );
- for ( int i = 0; i < fields->Length; i++ )
- {
- int fieldvalue = safe_cast(fields[ i ]->GetValue( nullptr ));
- if ( (fieldvalue & iAttribValue) == fieldvalue )
- {
- Console::WriteLine( fields[ i ]->Name );
- }
- }
-}
-
-int main()
-{
- Console::WriteLine( "Reflection.MethodBase.Attributes Sample" );
-
- // Get the type of the chosen class.
- Type^ MyType = Type::GetType( "AttributesSample" );
-
- // Get the method Mymethod on the type.
- MethodBase^ Mymethodbase = MyType->GetMethod( "Mymethod" );
-
- // Display the method name and signature.
- Console::WriteLine( "Mymethodbase = {0}", Mymethodbase );
-
- // Get the MethodAttribute enumerated value.
- MethodAttributes Myattributes = Mymethodbase->Attributes;
-
- // Display the flags that are set.
- PrintAttributes( System::Reflection::MethodAttributes::typeid, (int)Myattributes );
- return 0;
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.Attributes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.Attributes Example/CPP/source.cpp
deleted file mode 100644
index b803afb891b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.Attributes Example/CPP/source.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::InteropServices;
-public ref class AttributesSample
-{
-public:
- void Mymethod( int int1m, [Out]interior_ptr str2m, interior_ptr str3m )
- {
- *str2m = "in Mymethod";
- }
-};
-
-void PrintAttributes( Type^ attribType, int iAttribValue )
-{
- if ( !attribType->IsEnum )
- {
- Console::WriteLine( "This type is not an enum." );
- return;
- }
-
- array^fields = attribType->GetFields( static_cast(BindingFlags::Public | BindingFlags::Static) );
- for ( int i = 0; i < fields->Length; i++ )
- {
- int fieldvalue = safe_cast(fields[ i ]->GetValue( nullptr ));
- if ( (fieldvalue & iAttribValue) == fieldvalue )
- {
- Console::WriteLine( fields[ i ]->Name );
- }
- }
-}
-
-int main()
-{
- Console::WriteLine( "Reflection.MethodBase.Attributes Sample" );
-
- // Get the type.
- Type^ MyType = Type::GetType( "AttributesSample" );
-
- // Get the method Mymethod on the type.
- MethodBase^ Mymethodbase = MyType->GetMethod( "Mymethod" );
-
- // Display the method name.
- Console::WriteLine( "Mymethodbase = {0}", Mymethodbase );
-
- // Get the MethodAttribute enumerated value.
- MethodAttributes Myattributes = Mymethodbase->Attributes;
-
- // Display the flags that are set.
- PrintAttributes( System::Reflection::MethodAttributes::typeid, (int)Myattributes );
- return 0;
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.Invoke1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.Invoke1 Example/CPP/source.cpp
deleted file mode 100644
index 945399096dc..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.Invoke1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class MagicClass
-{
-private:
- int magicBaseValue;
-
-public:
- MagicClass()
- {
- magicBaseValue = 9;
- }
-
- int ItsMagic(int preMagic)
- {
- return preMagic * magicBaseValue;
- }
-};
-
-public ref class TestMethodInfo
-{
-public:
- static void Main()
- {
- // Get the constructor and create an instance of MagicClass
-
- Type^ magicType = Type::GetType("MagicClass");
- ConstructorInfo^ magicConstructor = magicType->GetConstructor(Type::EmptyTypes);
- Object^ magicClassObject = magicConstructor->Invoke(gcnew array(0));
-
- // Get the ItsMagic method and invoke with a parameter value of 100
-
- MethodInfo^ magicMethod = magicType->GetMethod("ItsMagic");
- Object^ magicValue = magicMethod->Invoke(magicClassObject, gcnew array(1){100});
-
- Console::WriteLine("MethodInfo.Invoke() Example\n");
- Console::WriteLine("MagicClass.ItsMagic() returned: {0}", magicValue);
- }
-};
-
-int main()
-{
- TestMethodInfo::Main();
-}
-
-// The example program gives the following output:
-//
-// MethodInfo.Invoke() Example
-//
-// MagicClass.ItsMagic() returned: 900
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsAbstract Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsAbstract Example/CPP/source.cpp
deleted file mode 100644
index a8d47e52181..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsAbstract Example/CPP/source.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Console::WriteLine( "\nReflection.MethodBase" );
-
- // Get the types.
- Type^ MyType1 = Type::GetType( "System.Runtime.Serialization.Formatter" );
- Type^ MyType2 = Type::GetType( "System.Reflection.MethodBase" );
-
- // Get and display the methods.
- MethodBase^ Mymethodbase1 = MyType1->GetMethod( "WriteInt32", static_cast(BindingFlags::NonPublic | BindingFlags::Instance) );
- MethodBase^ Mymethodbase2 = MyType2->GetMethod( "GetCurrentMethod", static_cast(BindingFlags::Public | BindingFlags::Static) );
- Console::Write( "\nMymethodbase = {0}", Mymethodbase1 );
- if ( Mymethodbase1->IsAbstract )
- Console::Write( "\nMymethodbase is an abstract method." );
- else
- Console::Write( "\nMymethodbase is not an abstract method." );
-
- Console::Write( "\n\nMymethodbase = {0}", Mymethodbase2 );
- if ( Mymethodbase2->IsAbstract )
- Console::Write( "\nMymethodbase is an abstract method." );
- else
- Console::Write( "\nMymethodbase is not an abstract method." );
-
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsAssembly Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsAssembly Example/CPP/source.cpp
deleted file mode 100644
index 72f077ad3a4..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsAssembly Example/CPP/source.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class Example
-{
-public:
- void m_public() {};
-internal:
- void m_internal() {};
-protected:
- void m_protected() {};
-protected public:
- void m_protected_public() {};
-protected private:
- void m_protected_private() {};
-};
-
-void main()
-{
- Console::WriteLine("\n{0,-30}{1,-18}{2}", "", "IsAssembly", "IsFamilyOrAssembly");
- Console::WriteLine("{0,-21}{1,-18}{2,-18}{3}\n",
- "", "IsPublic", "IsFamily", "IsFamilyAndAssembly");
-
- for each (MethodBase^ m in Example::typeid->GetMethods(
- BindingFlags::Instance | BindingFlags::NonPublic | BindingFlags::Public))
- {
- if (m->Name->Substring(0, 1) == "m")
- {
- Console::WriteLine("{0,-21}{1,-9}{2,-9}{3,-9}{4,-9}{5,-9}",
- m->Name,
- m->IsPublic,
- m->IsAssembly,
- m->IsFamily,
- m->IsFamilyOrAssembly,
- m->IsFamilyAndAssembly
- );
- }
- }
-}
-
-/* This code example produces output similar to the following:
-
- IsAssembly IsFamilyOrAssembly
- IsPublic IsFamily IsFamilyAndAssembly
-
-m_public True False False False False
-m_internal False True False False False
-m_protected False False True False False
-m_protected_public False False False True False
-m_protected_private False False False False True
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsPublic Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsPublic Example/CPP/source.cpp
deleted file mode 100644
index a7ea8cf252b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsPublic Example/CPP/source.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-#using
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Windows::Forms;
-
-//
-int main()
-{
- Console::WriteLine( "\nReflection.MethodBase" );
-
- //Get the MethodBase of a method.
- //Get the type
- Type^ MyType = Type::GetType( "System.MulticastDelegate" );
-
- //Get and display the method
- MethodBase^ Mymethodbase = MyType->GetMethod( "RemoveImpl", static_cast(BindingFlags::NonPublic | BindingFlags::Instance) );
- Console::Write( "\nMymethodbase = {0}", Mymethodbase );
- bool Myispublic = Mymethodbase->IsPublic;
- if ( Myispublic )
- Console::Write( "\nMymethodbase is a public method" );
- else
- Console::Write( "\nMymethodbase is not a public method" );
-
- return 0;
-}
-
-/*
-Produces the following output
-
-Reflection.MethodBase
-Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
-Mymethodbase is not a public method
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsVirtual Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsVirtual Example/CPP/source.cpp
deleted file mode 100644
index f96f32346d4..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.IsVirtual Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class MyClass
-{
-public:
- void MyMethod(){}
-};
-
-int main()
-{
- MethodBase^ m = MyClass::typeid->GetMethod( "MyMethod" );
- Console::WriteLine( "The IsFinal property value of MyMethod is {0}.", m->IsFinal );
- Console::WriteLine( "The IsVirtual property value of MyMethod is {0}.", m->IsVirtual );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodInfo.MemberType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodInfo.MemberType Example/CPP/source.cpp
deleted file mode 100644
index b878d322184..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodInfo.MemberType Example/CPP/source.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Console::WriteLine( "Reflection.MethodInfo" );
-
- // Get the Type and MethodInfo.
- Type^ MyType = Type::GetType( "System.Reflection.FieldInfo" );
- MethodInfo^ Mymethodinfo = MyType->GetMethod( "GetValue" );
- Console::WriteLine( "{0}.{1}", MyType->FullName, Mymethodinfo->Name );
-
- // Get and display the MemberType property.
- MemberTypes Mymembertypes = Mymethodinfo->MemberType;
- if ( MemberTypes::Constructor == Mymembertypes )
- {
- Console::WriteLine( "MemberType is of type All." );
- }
- else
- if ( MemberTypes::Custom == Mymembertypes )
- {
- Console::WriteLine( "MemberType is of type Custom." );
- }
- else
- if ( MemberTypes::Event == Mymembertypes )
- {
- Console::WriteLine( "MemberType is of type Event." );
- }
- else
- if ( MemberTypes::Field == Mymembertypes )
- {
- Console::WriteLine( "MemberType is of type Field." );
- }
- else
- if ( MemberTypes::Method == Mymembertypes )
- {
- Console::WriteLine( "MemberType is of type Method." );
- }
- else
- if ( MemberTypes::Property == Mymembertypes )
- {
- Console::WriteLine( "MemberType is of type Property." );
- }
- else
- if ( MemberTypes::TypeInfo == Mymembertypes )
- {
- Console::WriteLine( "MemberType is of type TypeInfo." );
- }
-
-
-
-
-
-
-
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodInfo.ReturnType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodInfo.ReturnType Example/CPP/source.cpp
deleted file mode 100644
index 9e122d5e99d..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodInfo.ReturnType Example/CPP/source.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Console::WriteLine( "\nReflection.MethodInfo" );
-
- // Get the Type and MethodInfo.
- Type^ MyType = Type::GetType( "System.Reflection.FieldInfo" );
- MethodInfo^ Mymethodinfo = MyType->GetMethod( "GetValue" );
- Console::Write( "\n{0}.{1}", MyType->FullName, Mymethodinfo->Name );
-
- // Get and display the ReturnType.
- Console::Write( "\nReturnType = {0}", Mymethodinfo->ReturnType );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodRental.SwapMethodBody Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodRental.SwapMethodBody Example/CPP/source.cpp
deleted file mode 100644
index 744eed074a9..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodRental.SwapMethodBody Example/CPP/source.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Runtime::InteropServices;
-
-// First make a method that returns 0.
-// Then swap the method body with a body that returns 1.
-int main()
-{
- // Construct a dynamic assembly
- Guid g = Guid::NewGuid();
- AssemblyName^ asmname = gcnew AssemblyName;
- asmname->Name = String::Concat( "tempfile", g );
- AssemblyBuilder^ asmbuild = System::Threading::Thread::GetDomain()->DefineDynamicAssembly( asmname, AssemblyBuilderAccess::Run );
-
- // Add a dynamic module that contains one type that has one method that
- // has no arguments.
- ModuleBuilder^ modbuild = asmbuild->DefineDynamicModule( "test" );
- TypeBuilder^ tb = modbuild->DefineType( "name of the Type" );
- array^temp2;
- MethodBuilder^ somemethod = tb->DefineMethod( "My method Name", static_cast(MethodAttributes::Public | MethodAttributes::Static), int::typeid, temp2 );
-
- // Define the body of the method to return 0.
- ILGenerator^ ilg = somemethod->GetILGenerator();
- ilg->Emit( OpCodes::Ldc_I4_0 );
- ilg->Emit( OpCodes::Ret );
-
- // Complete the type and verify that it returns 0.
- Type^ tbBaked = tb->CreateType();
- array^temp0;
- int res1 = safe_cast(tbBaked->GetMethod( "My method Name" )->Invoke( nullptr, temp0 ));
- if ( res1 != 0 )
- {
- Console::WriteLine( "Err_001a, should have returned 0" );
- }
- else
- {
- Console::WriteLine( "Original method returned 0" );
- }
-
- // Define a new method body that will return a 1 instead.
-
- // code size
- // ldc_i4_1
- // ret
- array^methodBytes = {0x03,0x30,0x0A,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x17,0x2a};
-
- // Get the token for the method whose body you are replacing.
- MethodToken somemethodToken = somemethod->GetToken();
-
- // Get the pointer to the method body.
- GCHandle hmem = GCHandle::Alloc( (Object^)methodBytes, GCHandleType::Pinned );
- IntPtr addr = hmem.AddrOfPinnedObject();
- int cbSize = methodBytes->Length;
-
- // Swap the old method body with the new body.
- MethodRental::SwapMethodBody( tbBaked, somemethodToken.Token, addr, cbSize, MethodRental::JitImmediate );
-
- // Verify that the modified method returns 1.
- array^temp1;
- int res2 = safe_cast(tbBaked->GetMethod( "My method Name" )->Invoke( nullptr, temp1 ));
- if ( res2 != 1 )
- {
- Console::WriteLine( "Err_001b, should have returned 1" );
- }
- else
- {
- Console::WriteLine( "Swapped method body returned 1" );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Module.Name Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Module.Name Example/CPP/source.cpp
deleted file mode 100644
index d2aa22fa155..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Module.Name Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Module^ mod = Assembly::GetExecutingAssembly()->GetModules()[ 0 ];
- Console::WriteLine( "Module Name is {0}", mod->Name );
- Console::WriteLine( "Module FullyQualifiedName is {0}", mod->FullyQualifiedName );
- Console::WriteLine( "Module ScopeName is {0}", mod->ScopeName );
-}
-
-/*
-This code produces the following output:
-
-Module Name is modname.exe
-Module FullyQualifiedName is C:\Bin\modname.exe
-Module ScopeName is modname.exe
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Module.ScopeName Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Module.ScopeName Example/CPP/source.cpp
deleted file mode 100644
index 591da3b46bd..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Module.ScopeName Example/CPP/source.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Module^ mod = Assembly::GetExecutingAssembly()->GetModules()[ 0 ];
- Console::WriteLine( "Module Name is {0}", mod->Name );
- Console::WriteLine( "Module FullyQualifiedName is {0}", mod->FullyQualifiedName );
- Console::WriteLine( "Module ScopeName is {0}", mod->ScopeName );
-}
-
-/*
-Produces this output:
-Module Name is modname.exe
-Module FullyQualifiedName is C:\Bin\modname.exe
-Module ScopeName is modname.exe
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic ModuleBuilder.DefineType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic ModuleBuilder.DefineType Example/CPP/source.cpp
deleted file mode 100644
index 009ddd456c1..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic ModuleBuilder.DefineType Example/CPP/source.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class Sample
-{
-public:
- void Method()
- {
- //
- AssemblyName^ asmname = gcnew AssemblyName;
- asmname->Name = "assemfilename.exe";
- AssemblyBuilder^ asmbuild = System::Threading::Thread::GetDomain()->
- DefineDynamicAssembly( asmname, AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ modbuild = asmbuild->DefineDynamicModule( "modulename",
- "assemfilename.exe" );
- TypeBuilder^ typebuild1 = modbuild->DefineType( "typename" );
- typebuild1->CreateType();
- asmbuild->Save( "assemfilename.exe" );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterAttributes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterAttributes Example/CPP/source.cpp
deleted file mode 100644
index cefa875d170..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterAttributes Example/CPP/source.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::InteropServices;
-public ref class paramatt
-{
-public:
- static void mymethod( String^ str1, [Out]interior_ptr str2, interior_ptr str3 )
- {
- *str2 = "string";
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.ParameterAttributes" );
-
- // Get the Type and the method.
- Type^ Mytype = Type::GetType( "paramatt" );
- MethodBase^ Mymethodbase = Mytype->GetMethod( "mymethod" );
-
- // Display the method.
- Console::Write( "\nMymethodbase = {0}", Mymethodbase );
-
- // Get the ParameterInfo array.
- array^Myarray = Mymethodbase->GetParameters();
-
- // Get and display the attributes for the second parameter.
- ParameterAttributes Myparamattributes = Myarray[ 1 ]->Attributes;
- Console::Write( "\nFor the second parameter:\nMyparamattributes = {0}, which is an {1}", (int)Myparamattributes, Myparamattributes );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.IsOut Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.IsOut Example/CPP/source.cpp
deleted file mode 100644
index 9d1bd81902a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.IsOut Example/CPP/source.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::InteropServices;
-public ref class parminfo
-{
-public:
- static void mymethod( int int1m, [Out]interior_ptr str2m, interior_ptr str3m )
- {
- *str2m = "in mymethod";
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.Parameterinfo" );
-
- //Get the ParameterInfo parameter of a function.
- //Get the type.
- Type^ Mytype = Type::GetType( "parminfo" );
-
- //Get and display the method.
- MethodBase^ Mymethodbase = Mytype->GetMethod( "mymethod" );
- Console::Write( "\nMymethodbase = {0}", Mymethodbase );
-
- //Get the ParameterInfo array.
- array^Myarray = Mymethodbase->GetParameters();
-
- //Get and display the IsOut of each parameter.
- System::Collections::IEnumerator^ enum0 = Myarray->GetEnumerator();
- while ( enum0->MoveNext() )
- {
- ParameterInfo^ Myparam = safe_cast(enum0->Current);
- Console::Write( "\nFor parameter # {0}, the IsOut is - {1}", Myparam->Position, Myparam->IsOut );
- }
-
- return 0;
-}
-
-/*
-This code produces the following output:
-
-Reflection.ParameterInfo
-
-Mymethodbase = Void mymethod (Int32, System.String ByRef, System.String ByRef)
-For parameter # 0, the IsOut is - False
-For parameter # 1, the IsOut is - True
-For parameter # 2, the IsOut is - False
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.Name Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.Name Example/CPP/source.cpp
deleted file mode 100644
index f604a9598d8..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.Name Example/CPP/source.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::InteropServices;
-public ref class parminfo
-{
-public:
- static void mymethod( int int1m, [Out]interior_ptr str2m, interior_ptr str3m )
- {
- *str2m = "in mymethod";
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.Parameterinfo" );
-
- //Get the ParameterInfo parameter of a function.
- //Get the type.
- Type^ Mytype = Type::GetType( "parminfo" );
-
- //Get and display the method.
- MethodBase^ Mymethodbase = Mytype->GetMethod( "mymethod" );
- Console::Write( "\nMymethodbase = {0}", Mymethodbase );
-
- //Get the ParameterInfo array.
- array^Myarray = Mymethodbase->GetParameters();
-
- //Get and display the name of each parameter.
- System::Collections::IEnumerator^ enum0 = Myarray->GetEnumerator();
- while ( enum0->MoveNext() )
- {
- ParameterInfo^ Myparam = safe_cast(enum0->Current);
- Console::Write( "\nFor parameter # {0}, the Name is - {1}", Myparam->Position, Myparam->Name );
- }
-
- return 0;
-}
-
-/*
-This code produces the following output:
-
-Reflection.ParameterInfo
-
-Mymethodbase
-= Void mymethod (Int32, System.String ByRef, System.String ByRef)
-For parameter # 0, the Name is - int1m
-For parameter # 1, the Name is - str2m
-For parameter # 2, the Name is - str3m
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.ParameterType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.ParameterType Example/CPP/source.cpp
deleted file mode 100644
index e005d0ef83a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic ParameterInfo.ParameterType Example/CPP/source.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::InteropServices;
-public ref class parminfo
-{
-public:
- static void mymethod( int int1m, [Out]interior_ptr str2m, interior_ptr str3m )
- {
- *str2m = "in mymethod";
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.Parameterinfo" );
-
- //Get the ParameterInfo parameter of a function.
- //Get the type.
- Type^ Mytype = Type::GetType( "parminfo" );
-
- //Get and display the method.
- MethodBase^ Mymethodbase = Mytype->GetMethod( "mymethod" );
- Console::Write( "\nMymethodbase = {0}", Mymethodbase );
-
- //Get the ParameterInfo array.
- array^Myarray = Mymethodbase->GetParameters();
-
- //Get and display the ParameterInfo of each parameter.
- System::Collections::IEnumerator^ enum0 = Myarray->GetEnumerator();
- while ( enum0->MoveNext() )
- {
- ParameterInfo^ Myparam = safe_cast(enum0->Current);
- Console::Write( "\nFor parameter # {0}, the ParameterType is - {1}", Myparam->Position, Myparam->ParameterType );
- }
-
- return 0;
-}
-
-/*
-This code produces the following output:
-
-Reflection.Parameterinfo
-
-Mymethodbase = Void mymethod(Int32, System.String ByRef, System.String ByRef)
-For parameter # 0, the ParameterType is - System.Int32
-For parameter # 1, the ParameterType is - System.String&
-For parameter # 2, the ParameterType is - System.String&
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyAttributes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyAttributes Example/CPP/source.cpp
deleted file mode 100644
index 189cd35d9c7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyAttributes Example/CPP/source.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define three properties: one read-write, one default,
-// and one read only.
-// Define a read-write property.
-public ref class Aproperty
-{
-private:
- String^ caption;
-
-public:
- Aproperty()
- : caption( "A Default caption" )
- {}
-
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-
-// Define a default property.
-public ref class Bproperty
-{
-private:
- String^ caption;
-
-public:
- Bproperty()
- : caption( "B Default caption" )
- {}
-
-public:
- property String^ Item
- {
- String^ get()
- {
- return "1";
- }
-
- }
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-
-// Define a read-only property.
-public ref class Cproperty
-{
-private:
- String^ caption;
-
-public:
- Cproperty()
- : caption( "C Default caption" )
- {}
-
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.PropertyAttributes" );
-
- // Determine whether a property exists, and change its value.
- Aproperty^ Mypropertya = gcnew Aproperty;
- Bproperty^ Mypropertyb = gcnew Bproperty;
- Cproperty^ Mypropertyc = gcnew Cproperty;
- Console::Write( "\n1. Mypropertya->Caption = {0}", Mypropertya->Caption );
- Console::Write( "\n1. Mypropertyb->Caption = {0}", Mypropertyb->Caption );
- Console::Write( "\n1. Mypropertyc->Caption = {0}", Mypropertyc->Caption );
-
- // Only Mypropertya can be changed, as Mypropertyb is read-only.
- Mypropertya->Caption = "A- This is changed.";
- Mypropertyb->Caption = "B- This is changed.";
-
- // Note that Mypropertyc is not changed because it is read only
- Console::Write( "\n\n2. Mypropertya->Caption = {0}", Mypropertya->Caption );
- Console::Write( "\n2. Mypropertyb->Caption = {0}", Mypropertyb->Caption );
- Console::Write( "\n2. Mypropertyc->Caption = {0}", Mypropertyc->Caption );
-
- // Get the PropertyAttributes enumeration of the property.
- // Get the type.
- Type^ MyTypea = Type::GetType( "Aproperty" );
- Type^ MyTypeb = Type::GetType( "Bproperty" );
- Type^ MyTypec = Type::GetType( "Cproperty" );
-
- // Get the property attributes.
- PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
- PropertyAttributes Myattributesa = Mypropertyinfoa->Attributes;
- PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Item" );
- PropertyAttributes Myattributesb = Mypropertyinfob->Attributes;
- PropertyInfo^ Mypropertyinfoc = MyTypec->GetProperty( "Caption" );
- PropertyAttributes Myattributesc = Mypropertyinfoc->Attributes;
-
- // Display the property attributes value.
- Console::Write( "\n\na- {0}", Myattributesa );
- Console::Write( "\nb- {0}", Myattributesb );
- Console::Write( "\nc- {0}", Myattributesc );
- return 0;
-}
-
-// This example displays the following output to the console
-//
-// Reflection.PropertyAttributes
-//
-// 1. Mypropertya.Caption = A Default caption
-// 1. Mypropertyb.Caption = B Default caption
-// 1. Mypropertyc.Caption = C Default caption
-//
-// 2. Mypropertya.Caption = A- This is changed.
-// 2. Mypropertyb.Caption = B- This is changed.
-// 2. Mypropertyc.Caption = C Default caption
-//
-// a- None
-// b- None
-// c- None
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.CanRead Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.CanRead Example/CPP/source.cpp
deleted file mode 100644
index 5e3598f1d39..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.CanRead Example/CPP/source.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define one readable property and one not readable.
-public ref class Mypropertya
-{
-private:
- String^ caption;
-
-public:
- Mypropertya()
- : caption( "A Default caption" )
- {}
-
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-public ref class Mypropertyb
-{
-private:
- String^ caption;
-
-public:
- Mypropertyb()
- : caption( "B Default caption" )
- {}
-
-
- property String^ Caption
- {
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.PropertyInfo" );
-
- // Define two properties.
- Mypropertya^ mypropertya = gcnew Mypropertya;
- Mypropertyb^ mypropertyb = gcnew Mypropertyb;
- Console::Write( "\nMypropertya->Caption = {0}", mypropertya->Caption );
-
- // Mypropertyb.Caption cannot be read, because
- // there is no get accessor.
- // Get the type and PropertyInfo.
- Type^ MyTypea = Type::GetType( "Mypropertya" );
- PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
- Type^ MyTypeb = Type::GetType( "Mypropertyb" );
- PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Caption" );
-
- // Get and display the CanRead property.
- Console::Write( "\nCanRead a - {0}", Mypropertyinfoa->CanRead );
- Console::Write( "\nCanRead b - {0}", Mypropertyinfob->CanRead );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.CanWrite Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.CanWrite Example/CPP/source.cpp
deleted file mode 100644
index c83b78e6d61..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.CanWrite Example/CPP/source.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define one writable property and one not writable.
-public ref class Mypropertya
-{
-private:
- String^ caption;
-
-public:
- Mypropertya()
- : caption( "A Default caption" )
- {}
-
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-public ref class Mypropertyb
-{
-private:
- String^ caption;
-
-public:
- Mypropertyb()
- : caption( "B Default caption" )
- {}
-
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.PropertyInfo" );
-
- // Define two properties.
- Mypropertya^ mypropertya = gcnew Mypropertya;
- Mypropertyb^ mypropertyb = gcnew Mypropertyb;
-
- // Read and display the property.
- Console::Write( "\nMypropertya->Caption = {0}", mypropertya->Caption );
- Console::Write( "\nMypropertyb->Caption = {0}", mypropertyb->Caption );
-
- // Write to the property.
- mypropertya->Caption = "A- No Change";
-
- // Mypropertyb.Caption cannot be written to because
- // there is no set accessor.
- // Read and display the property.
- Console::Write( "\nMypropertya->Caption = {0}", mypropertya->Caption );
- Console::Write( "\nMypropertyb->Caption = {0}", mypropertyb->Caption );
-
- // Get the type and PropertyInfo.
- Type^ MyTypea = Type::GetType( "Mypropertya" );
- PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
- Type^ MyTypeb = Type::GetType( "Mypropertyb" );
- PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Caption" );
-
- // Get and display the CanWrite property.
- Console::Write( "\nCanWrite a - {0}", Mypropertyinfoa->CanWrite );
- Console::Write( "\nCanWrite b - {0}", Mypropertyinfob->CanWrite );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetGetMethod1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetGetMethod1 Example/CPP/source.cpp
deleted file mode 100644
index e947e02ff48..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetGetMethod1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define a property.
-public ref class Myproperty
-{
-private:
- String^ caption;
-
-public:
- Myproperty()
- : caption( "A Default caption" )
- {}
-
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.PropertyInfo" );
-
- // Get the type and PropertyInfo for two separate properties.
- Type^ MyTypea = Type::GetType( "Myproperty" );
- PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
- Type^ MyTypeb = Type::GetType( "System.Reflection.MethodInfo" );
- PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "MemberType" );
-
- // Get and display the GetGetMethod method for each property.
- MethodInfo^ Mygetmethodinfoa = Mypropertyinfoa->GetGetMethod();
- Console::Write( "\nGetAccessor for {0} returns a {1}", Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType );
- MethodInfo^ Mygetmethodinfob = Mypropertyinfob->GetGetMethod();
- Console::Write( "\nGetAccessor for {0} returns a {1}", Mypropertyinfob->Name, Mygetmethodinfob->ReturnType );
-
- // Display the GetGetMethod without using the MethodInfo.
- Console::Write( "\n{0}.{1} GetGetMethod - {2}", MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetGetMethod() );
- Console::Write( "\n{0}.{1} GetGetMethod - {2}", MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetGetMethod() );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetIndexParameters Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetIndexParameters Example/CPP/source.cpp
deleted file mode 100644
index 6c130b9d45f..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetIndexParameters Example/CPP/source.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// A class that contains some properties.
-public ref class MyProperty
-{
-private:
-
- // Define a simple string property.
- String^ caption;
-
-public:
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-private:
-
- // A very limited indexer that gets or sets one of four
- // strings.
- array^strings;
-
-public:
- MyProperty()
- {
- array^temp0 = {"abc","def","ghi","jkl"};
- strings = temp0;
- }
-
-
- property String^ Item [int]
- {
- String^ get( int Index )
- {
- return strings[ Index ];
- }
-
- void set( int Index, String^ value )
- {
- strings[ Index ] = value;
- }
-
- }
-
-};
-
-int main()
-{
-
- // Get the type and PropertyInfo.
- Type^ t = Type::GetType( "MyProperty" );
- PropertyInfo^ pi = t->GetProperty( "Caption" );
-
- // Get the public GetIndexParameters method.
- array^parms = pi->GetIndexParameters();
- Console::WriteLine( "\n{0}.{1} has {2} parameters.", t->FullName, pi->Name, parms->GetLength( 0 ) );
-
- // Display a property that has parameters.
- pi = t->GetProperty( "Item" );
- parms = pi->GetIndexParameters();
- Console::WriteLine( "{0}.{1} has {2} parameters.", t->FullName, pi->Name, parms->GetLength( 0 ) );
- for ( int i = 0; i < parms->GetLength( 0 ); i++ )
- {
- Console::WriteLine( " Parameter: {0}", parms[ i ]->Name );
-
- }
- return 0;
-}
-
-/*
- This example produces the following output:
- MyProperty.Caption has 0 parameters.
- MyProperty.Item has 1 parameters.
- Parameter: Index
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetSetMethod1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetSetMethod1 Example/CPP/source.cpp
deleted file mode 100644
index 490380e255b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.GetSetMethod1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define a property.
-public ref class Myproperty
-{
-private:
- String^ caption;
-
-public:
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-int main()
-{
- Console::WriteLine( "\nReflection.PropertyInfo" );
-
- // Get the type and PropertyInfo for two separate properties.
- Type^ MyTypea = Type::GetType( "Myproperty" );
- PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
- Type^ MyTypeb = Type::GetType( "System.Text.StringBuilder" );
- PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Length" );
-
- // Get and display the GetSetMethod method for each property.
- MethodInfo^ Mygetmethodinfoa = Mypropertyinfoa->GetSetMethod();
- Console::Write( "\nSetAccessor for {0} returns a {1}", Mypropertyinfoa->Name, Mygetmethodinfoa->ReturnType );
- MethodInfo^ Mygetmethodinfob = Mypropertyinfob->GetSetMethod();
- Console::Write( "\nSetAccessor for {0} returns a {1}", Mypropertyinfob->Name, Mygetmethodinfob->ReturnType );
-
- // Display the GetSetMethod without using the MethodInfo.
- Console::Write( "\n\n{0}.{1} GetSetMethod - {2}", MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->GetSetMethod() );
- Console::Write( "\n{0}.{1} GetSetMethod - {2}", MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->GetSetMethod() );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.MemberType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.MemberType Example/CPP/source.cpp
deleted file mode 100644
index a56525a268e..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.MemberType Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- Console::WriteLine( "\nReflection.PropertyInfo" );
-
- // Get the type and PropertyInfo.
- Type^ MyType = Type::GetType( "System.Reflection.MemberInfo" );
- PropertyInfo^ Mypropertyinfo = MyType->GetProperty( "Name" );
-
- // Read and display the MemberType property.
- Console::Write( "\nMemberType = {0}", Mypropertyinfo->MemberType );
- return 0;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.SetValue1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.SetValue1 Example/CPP/source.cpp
deleted file mode 100644
index 7c87302d269..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic PropertyInfo.SetValue1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-// Define a property.
-public ref class TestClass
-{
-private:
- String^ caption;
-
-public:
- TestClass()
- {
- caption = "A Default caption";
- }
-
-
- property String^ Caption
- {
- String^ get()
- {
- return caption;
- }
-
- void set( String^ value )
- {
- if ( caption != value )
- {
- caption = value;
- }
- }
-
- }
-
-};
-
-int main()
-{
- TestClass^ t = gcnew TestClass;
-
- // Get the type and PropertyInfo.
- Type^ myType = t->GetType();
- PropertyInfo^ pinfo = myType->GetProperty( "Caption" );
-
- // Display the property value, using the GetValue method.
- Console::WriteLine( "\nGetValue: {0}", pinfo->GetValue( t, nullptr ) );
-
- // Use the SetValue method to change the caption.
- pinfo->SetValue( t, "This caption has been changed.", nullptr );
-
- // Display the caption again.
- Console::WriteLine( "GetValue: {0}", pinfo->GetValue( t, nullptr ) );
- Console::WriteLine( "\nPress the Enter key to continue." );
- Console::ReadLine();
- return 0;
-}
-
-/*
-This example produces the following output:
-
-GetValue: A Default caption
-GetValue: This caption has been changed
-
-Press the Enter key to continue.
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Random.NextBytes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Random.NextBytes Example/CPP/source.cpp
deleted file mode 100644
index bdf0c7f6486..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Random.NextBytes Example/CPP/source.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-//
-#using
-
-using namespace System;
-
-void main()
-{
- Random^ rnd = gcnew Random;
- array^b = gcnew array(10);
- rnd->NextBytes( b );
- Console::WriteLine("The Random bytes are:");
- for ( int i = 0; i < 10; i++ )
- Console::WriteLine("{0}: {1}", i, b[i]);
-}
-// The example displays output similar to the following:
-// The Random bytes are:
-// 0: 131
-// 1: 96
-// 2: 226
-// 3: 213
-// 4: 176
-// 5: 208
-// 6: 99
-// 7: 89
-// 8: 226
-// 9: 194
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft Example/CPP/source.cpp
deleted file mode 100644
index 7c44cb174ba..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft Example/CPP/source.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#using
-
-using namespace System;
-
-ref class Sample
-{
-private:
- void Method()
- {
- //
- String^ str = "BBQ and Slaw";
- Console::WriteLine( str->PadLeft( 15 ) ); // Displays " BBQ and Slaw".
- Console::WriteLine( str->PadLeft( 5 ) ); // Displays "BBQ and Slaw".
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft1 Example/CPP/source.cpp
deleted file mode 100644
index 4f65f5fcc67..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#using
-
-//
-using namespace System;
-
-void main()
-{
- String^ str = "forty-two";
- Console::WriteLine( str->PadLeft( 15, L'.' ) );
- Console::WriteLine( str->PadLeft( 2, L'.' ) );
-}
-// The example displays the following output:
-// ......forty-two
-// forty-two
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight Example/CPP/source.cpp
deleted file mode 100644
index d313d14119e..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#using
-
-using namespace System;
-ref class Sample
-{
-private:
- void Method()
- {
-
- //
- String^ str = "BBQ and Slaw";
- Console::Write( "|" );
- Console::Write( str->PadRight( 15 ) );
- Console::WriteLine( "|" ); // Displays "|BBQ and Slaw |".
- Console::Write( "|" );
- Console::Write( str->PadRight( 5 ) );
- Console::WriteLine( "|" ); // Displays "|BBQ and Slaw|".
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight1 Example/CPP/source.cpp
deleted file mode 100644
index 0786d97857d..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#using
-
-using namespace System;
-ref class Sample
-{
-private:
- void Method()
- {
- //
- String^ str = "forty-two";
- Console::Write( "|" );
- Console::Write( str->PadRight( 15, '.' ) );
- Console::WriteLine( "|" ); // Displays "|forty-two......|".
- Console::Write( "|" );
- Console::Write( str->PadRight( 5, '.' ) );
- Console::WriteLine( "|" ); // Displays "|forty-two|".
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.DeclaringType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.DeclaringType Example/CPP/source.cpp
deleted file mode 100644
index 16e8d85658e..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.DeclaringType Example/CPP/source.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class dtype abstract
-{
-public:
- ref class MyClassA abstract
- {
- public:
- virtual int m() = 0;
- };
-
- ref class MyClassB abstract: public MyClassA{};
-};
-
-int main()
-{
- Console::WriteLine( "The declaring type of m is {0}.", dtype::MyClassB::typeid->GetMethod( "m" )->DeclaringType );
-}
-/* The example produces the following output:
-
-The declaring type of m is dtype+MyClassA.
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.EmptyTypes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.EmptyTypes Example/CPP/source.cpp
deleted file mode 100644
index ee3ada47aea..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.EmptyTypes Example/CPP/source.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-using namespace System;
-using namespace System::IO;
-using namespace System::Reflection;
-
-public ref class Sample
-{
-public:
- void Method( Type^ type )
- {
- ConstructorInfo^ cInfo;
-
- //
- cInfo = type->GetConstructor( BindingFlags::ExactBinding, nullptr,
- Type::EmptyTypes, nullptr );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.FilterName Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.FilterName Example/CPP/source.cpp
deleted file mode 100644
index eaae896f09f..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.FilterName Example/CPP/source.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-
-// Class added so sample will compile
-public ref class Application
-{
-public:
- void Method(){}
-};
-
-public ref class Sample
-{
-public:
- void Method()
- {
- //
- // Get the set of methods associated with the type
- array^ mi = Application::typeid->FindMembers(
- (MemberTypes)(MemberTypes::Constructor | MemberTypes::Method),
- (BindingFlags)(BindingFlags::Public | BindingFlags::Static |
- BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::DeclaredOnly),
- Type::FilterName, "*" );
- Console::WriteLine( "Number of methods (includes constructors): {0}", mi->Length );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source1.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source1.cpp
deleted file mode 100644
index 4c9e6c12c06..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source1.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-public ref class t
-{
-public:
- t(){}
-
- static t(){}
-
- t( int /*i*/ ){}
-
-};
-
-int main()
-{
- array^p = t::typeid->GetConstructors();
- Console::WriteLine( p->Length );
- for ( int i = 0; i < p->Length; i++ )
- {
- Console::WriteLine( p[ i ]->IsStatic );
-
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source2.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source2.cpp
deleted file mode 100644
index 881b9216d30..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source2.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-public ref class t
-{
-public:
- t(){}
-
- t( int /*i*/ ){}
-
- static t(){}
-
-};
-
-int main()
-{
- array^p = t::typeid->GetConstructors( static_cast(BindingFlags::Public | BindingFlags::Static | BindingFlags::NonPublic | BindingFlags::Instance) );
- Console::WriteLine( p->Length );
- for ( int i = 0; i < p->Length; i++ )
- {
- Console::WriteLine( p[ i ]->IsStatic );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsNotPublic Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsNotPublic Example/CPP/source.cpp
deleted file mode 100644
index f0af5fbd409..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsNotPublic Example/CPP/source.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-
-//
-using namespace System;
-using namespace System::IO;
-using namespace System::Reflection;
-
-int main()
-{
- //Get the Type and MemberInfo.
- Type^ t = Type::GetType("System.IO.File");
- array^ members = t->GetMembers();
-
- //Get and display the DeclaringType method.
- Console::WriteLine("There are {0} members in {1}.",
- members->Length, t->FullName );
- Console::WriteLine("Is {0} non-public? {1}",
- t->FullName, t->IsNotPublic );
-}
-// The example displays the following output:
-// There are 60 members in System.IO.File.
-// Is System.IO.File non-public? False
-//
-
-//
-public ref class A
-{
-public:
- ref class B{};
-
-
-private:
- ref class C{};
-
-
-};
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsSpecialName Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsSpecialName Example/CPP/source.cpp
deleted file mode 100644
index 47d546e7a06..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsSpecialName Example/CPP/source.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-
-//
-using namespace System;
-using namespace System::IO;
-using namespace System::Reflection;
-using namespace System::Text;
-public ref class Sample
-{
-protected:
- bool ShowMethods;
- StreamWriter^ myWriter;
-
-private:
- void DumpMethods( Type^ aType )
- {
- if ( !ShowMethods )
- return;
-
- array^mInfo = aType->GetMethods();
- myWriter->WriteLine( "Methods" );
- bool found = false;
- if ( mInfo->Length != 0 )
- {
- for ( int i = 0; i < mInfo->Length; i++ )
- {
-
- // Only display methods declared in this type. Also
- // filter out any methods with special names, because these
- // cannot be generally called by the user. That is, their
- // functionality is usually exposed in other ways, for example,
- // property get/set methods are exposed as properties.
- if ( mInfo[ i ]->DeclaringType == aType && !mInfo[ i ]->IsSpecialName )
- {
- found = true;
- StringBuilder^ modifiers = gcnew StringBuilder;
- if ( mInfo[ i ]->IsStatic )
- {
- modifiers->Append( "static " );
- }
- if ( mInfo[ i ]->IsPublic )
- {
- modifiers->Append( "public " );
- }
- if ( mInfo[ i ]->IsFamily )
- {
- modifiers->Append( "protected " );
- }
- if ( mInfo[ i ]->IsAssembly )
- {
- modifiers->Append( "internal " );
- }
- if ( mInfo[ i ]->IsPrivate )
- {
- modifiers->Append( "private " );
- }
- myWriter->WriteLine( "{0} {1}", modifiers, mInfo[ i ] );
- }
-
- }
- }
-
- if ( !found )
- {
- myWriter->WriteLine( "(none)" );
- }
- }
-
-};
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.MemberType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.MemberType Example/CPP/source.cpp
deleted file mode 100644
index 5f55897e971..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.MemberType Example/CPP/source.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-
-public ref class Sample
-{
-public:
- void Method( Type^ t, MemberInfo^ mi )
- {
- //
- array^ others = t->GetMember( mi->Name, mi->MemberType,
- (BindingFlags)(BindingFlags::Public | BindingFlags::Static |
- BindingFlags::NonPublic | BindingFlags::Instance) );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.Missing Example/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.Missing Example/cpp/source.cpp
deleted file mode 100644
index be2838788b7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.Missing Example/cpp/source.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-//
-#using
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::CodeDom::Compiler;
-
-ref class Example
-{
-public:
- static void Main()
- {
- // VB source for example. Not all versions of CS and CPP compilers
- // support optional arguments.
- String^ codeLines =
- "Imports System\n\n" +
- "Public Class OptionalArg\n" +
- " Public Sub MyMethod(ByVal a As Integer, _\n" +
- " Optional ByVal b As Double = 1.2, _\n" +
- " Optional ByVal c As Integer = 1)\n\n" +
- " Console.WriteLine(\"a = \" & a & \" b = \" & b & \" c = \" & c)\n" +
- " End Sub\n" +
- "End Class\n";
-
- // Generate a OptionalArg instance from the source above.
- Object^ o = GenerateObjectFromSource("OptionalArg", codeLines, "VisualBasic");
- Type^ t;
-
- t = o->GetType();
- BindingFlags bf = BindingFlags::Public | BindingFlags::Instance |
- BindingFlags::InvokeMethod | BindingFlags::OptionalParamBinding;
-
- t->InvokeMember("MyMethod", bf, nullptr, o, gcnew array {10, 55.3, 12});
- t->InvokeMember("MyMethod", bf, nullptr, o, gcnew array {10, 1.3, Type::Missing});
- t->InvokeMember("MyMethod", bf, nullptr, o, gcnew array {10, Type::Missing, Type::Missing});
- }
-
-private:
- static Object^ GenerateObjectFromSource(String^ objectName,
- String^ sourceLines, String^ providerName)
- {
- Object^ genObject = nullptr;
- CodeDomProvider^ codeProvider = CodeDomProvider::CreateProvider(providerName);
- CompilerParameters^ cp = gcnew CompilerParameters();
-
- cp->GenerateExecutable = false;
- cp->GenerateInMemory = true;
-
- CompilerResults^ results =
- codeProvider->CompileAssemblyFromSource(cp, sourceLines);
- if (results->Errors->Count == 0)
- {
- genObject = results->CompiledAssembly->CreateInstance(objectName);
- }
-
- return genObject;
- }
-};
-
-int main()
-{
- Example::Main();
-}
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.ReflectedType Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.ReflectedType Example/CPP/source.cpp
deleted file mode 100644
index e40dfeced46..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.ReflectedType Example/CPP/source.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class MyClassA abstract
-{
-public:
- ref class MyClassB abstract
- {
-
- };
-
-};
-
-int main()
-{
- Console::WriteLine( "Reflected type of MyClassB is {0}", MyClassA::MyClassB::typeid->ReflectedType );
- //Outputs MyClassA, the enclosing type.
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/System.Reflection.MemberTypes/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/System.Reflection.MemberTypes/cpp/source.cpp
deleted file mode 100644
index d0cc8fad02a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/System.Reflection.MemberTypes/cpp/source.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-void main()
-{
- // Get the type of a chosen class.
- Type^ t = ReflectionTypeLoadException::typeid;
-
- // Get the MemberInfo array.
- array^ members = t->GetMembers();
-
- // Get and display the name and the MemberType for each member.
- Console::WriteLine("Members of {0}", t->Name);
- for each (MemberInfo^ member in members) {
- MemberTypes memberType = member->MemberType;
- Console::WriteLine(" {0}: {1}", member->Name, memberType);
- }
-}
-// The example displays the following output:
-// Members of ReflectionTypeLoadException
-// get_Types: Method
-// get_LoaderExceptions: Method
-// GetObjectData: Method
-// get_Message: Method
-// get_Data: Method
-// GetBaseException: Method
-// get_InnerException: Method
-// get_TargetSite: Method
-// get_StackTrace: Method
-// get_HelpLink: Method
-// set_HelpLink: Method
-// get_Source: Method
-// set_Source: Method
-// ToString: Method
-// get_HResult: Method
-// GetType: Method
-// Equals: Method
-// GetHashCode: Method
-// GetType: Method
-// .ctor: Constructor
-// .ctor: Constructor
-// Types: Property
-// LoaderExceptions: Property
-// Message: Property
-// Data: Property
-// InnerException: Property
-// TargetSite: Property
-// StackTrace: Property
-// HelpLink: Property
-// Source: Property
-// HResult: Property
-//
-
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals.cpp
deleted file mode 100644
index 3caae363b62..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-// Equals.cpp : Defines the entry point for the console application.
-//
-
-//#include "stdafx.h"
-
-//
-#using
-
-using namespace System;
-using namespace System::Numerics;
-
-void main()
-{
- BigInteger bigIntValue;
-
- Byte byteValue = 16;
- bigIntValue = BigInteger(byteValue);
- Console::WriteLine("{0} {1} = {2} {3} : {4}",
- bigIntValue.GetType()->Name, bigIntValue,
- byteValue.GetType()->Name, byteValue,
- bigIntValue.Equals((Int64)byteValue));
-
- SByte sbyteValue = -16;
- bigIntValue = BigInteger(sbyteValue);
- Console::WriteLine("{0} {1} = {2} {3} : {4}",
- bigIntValue.GetType()->Name, bigIntValue,
- sbyteValue.GetType()->Name, sbyteValue,
- bigIntValue.Equals((Int64)sbyteValue));
-
- Int16 shortValue = 1233;
- bigIntValue = BigInteger(shortValue);
- Console::WriteLine("{0} {1} = {2} {3} : {4}",
- bigIntValue.GetType()->Name, bigIntValue,
- shortValue.GetType()->Name, shortValue,
- bigIntValue.Equals((Int64)shortValue));
-
- UInt16 ushortValue = 64000;
- bigIntValue = BigInteger(ushortValue);
- Console::WriteLine("{0} {1} = {2} {3} : {4}",
- bigIntValue.GetType()->Name, bigIntValue,
- ushortValue.GetType()->Name, ushortValue,
- bigIntValue.Equals((Int64)ushortValue));
-
- int intValue = -1603854;
- bigIntValue = BigInteger(intValue);
- Console::WriteLine("{0} {1} = {2} {3} : {4}",
- bigIntValue.GetType()->Name, bigIntValue,
- intValue.GetType()->Name, intValue,
- bigIntValue.Equals((Int64)intValue));
-
- UInt32 uintValue = 1223300;
- bigIntValue = BigInteger(uintValue);
- Console::WriteLine("{0} {1} = {2} {3} : {4}",
- bigIntValue.GetType()->Name, bigIntValue,
- uintValue.GetType()->Name, uintValue,
- bigIntValue.Equals((Int64)uintValue));
-
- Int64 longValue = -123822229012;
- bigIntValue = BigInteger(longValue);
- Console::WriteLine("{0} {1} = {2} {3} : {4}",
- bigIntValue.GetType()->Name, bigIntValue,
- longValue.GetType()->Name, longValue,
- bigIntValue.Equals((Int64)longValue));
-}
-/*
-The example displays output like the following:
- BigInteger 16 = Byte 16 : True
- BigInteger -16 = SByte -16 : True
- BigInteger 1233 = Int16 1233 : True
- BigInteger 64000 = UInt16 64000 : True
- BigInteger -1603854 = Int32 -1603854 : True
- BigInteger 1223300 = UInt32 1223300 : True
- BigInteger -123822229012 = Int64 -123822229012 : True
-*/
-//
-
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals2.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals2.cpp
deleted file mode 100644
index c480f604daa..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Numerics.BigInteger.Equals/cpp/equals2.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// Equals2.cpp : Defines the entry point for the console application.
-//
-
-//
-#using
-
-using namespace System;
-using namespace System::Numerics;
-
-
-void main()
-{
- const Int64 LIGHT_YEAR = 5878625373183;
-
- BigInteger altairDistance = 17 * LIGHT_YEAR;
- BigInteger epsilonIndiDistance = 12 * LIGHT_YEAR;
- BigInteger ursaeMajoris47Distance = 46 * LIGHT_YEAR;
- Int64 tauCetiDistance = 12 * LIGHT_YEAR;
- UInt64 procyon2Distance = 12 * LIGHT_YEAR;
- Object^ wolf424ABDistance = 14 * LIGHT_YEAR;
-
- Console::WriteLine("Approx. equal distances from Epsilon Indi to:");
- Console::WriteLine(" Altair: {0}",
- epsilonIndiDistance.Equals(altairDistance));
- Console::WriteLine(" Ursae Majoris 47: {0}",
- epsilonIndiDistance.Equals(ursaeMajoris47Distance));
- Console::WriteLine(" TauCeti: {0}",
- epsilonIndiDistance.Equals(tauCetiDistance));
- Console::WriteLine(" Procyon 2: {0}",
- epsilonIndiDistance.Equals(procyon2Distance));
- Console::WriteLine(" Wolf 424 AB: {0}",
- epsilonIndiDistance.Equals(wolf424ABDistance));
-}
-/*
-The example displays output like the following:
- Approx. equal distances from Epsilon Indi to:
- Altair: False
- Ursae Majoris 47: False
- TauCeti: True
- Procyon 2: True
- Wolf 424 AB: False
-*/
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Refelction.Emit.MethodBuilder.CreateMethodBody Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Refelction.Emit.MethodBuilder.CreateMethodBody Example/CPP/source.cpp
deleted file mode 100644
index 44abeeae6c3..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Refelction.Emit.MethodBuilder.CreateMethodBody Example/CPP/source.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-class MethodBodyDemo
-{
-public:
-
- // This class will demonstrate how to create a method body using
- // the MethodBuilder::CreateMethodBody(Byte[], int) method.
- static Type^ BuildDynType()
- {
- Type^ addType = nullptr;
- AppDomain^ currentDom = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
- AssemblyBuilder^ myAsmBldr = currentDom->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
-
- // The dynamic assembly space has been created. Next, create a module
- // within it. The type Point will be reflected into this module.
- ModuleBuilder^ myModuleBldr = myAsmBldr->DefineDynamicModule( "MyModule" );
- TypeBuilder^ myTypeBldr = myModuleBldr->DefineType( "Adder" );
- array^temp0 = {int::typeid,int::typeid};
- MethodBuilder^ myMthdBldr = myTypeBldr->DefineMethod( "DoAdd", static_cast(MethodAttributes::Public | MethodAttributes::Static), int::typeid, temp0 );
-
- // Build the array of Bytes holding the MSIL instructions.
-
- /* 02h is the opcode for ldarg.0 */
- /* 03h is the opcode for ldarg.1 */
- /* 58h is the opcode for add */
- /* 2Ah is the opcode for ret */
- array^temp1 = {0x02,0x03,0x58,0x2A};
- array^ILcodes = temp1;
- myMthdBldr->CreateMethodBody( ILcodes, ILcodes->Length );
- addType = myTypeBldr->CreateType();
- return addType;
- }
-
-};
-
-int main()
-{
- Type^ myType = MethodBodyDemo::BuildDynType();
- Console::WriteLine( "---" );
- Console::Write( "Enter the first integer to add: " );
- int aVal = Convert::ToInt32( Console::ReadLine() );
- Console::Write( "Enter the second integer to add: " );
- int bVal = Convert::ToInt32( Console::ReadLine() );
- Object^ adderInst = Activator::CreateInstance( myType, gcnew array(0) );
- array^temp1 = {aVal,bVal};
- Console::WriteLine( "The value of adding {0} to {1} is: {2}.", aVal, bVal, myType->InvokeMember( "DoAdd", BindingFlags::InvokeMethod, nullptr, adderInst, temp1 ) );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/GetAssembly1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/GetAssembly1.cpp
deleted file mode 100644
index bd325cd3b40..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/GetAssembly1.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-void main()
-{
- // Get a Type object.
- Type^ t = int::typeid;
- // Instantiate an Assembly class to the assembly housing the Integer type.
- Assembly^ assem = Assembly::GetAssembly(t);
- // Display the name of the assembly.
- Console::WriteLine("Name: {0}", assem->FullName);
- // Get the location of the assembly using the file: protocol.
- Console::WriteLine("CodeBase: {0}", assem->CodeBase);
-}
-// The example displays output like the following:
-// Name: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-// CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/assembly.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/assembly.cpp
deleted file mode 100644
index 21eed0e53a5..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/assembly.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Collections;
-
-void Snippet1()
-{
- Assembly^ SampleAssembly;
- // Instantiate a target object.
- Int32 Integer1(0);
- Type^ Type1;
- // Set the Type instance to the target class type.
- Type1 = Integer1.GetType();
- // Instantiate an Assembly class to the assembly housing the Integer type.
- SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
- // Gets the location of the assembly using file: protocol.
- Console::WriteLine( "CodeBase= {0}", SampleAssembly->CodeBase );
-}
-void Snippet2()
-{
- //
- Assembly^ SampleAssembly;
- // Instantiate a target object.
- Int32 Integer1(0);
- Type^ Type1;
- // Set the Type instance to the target class type.
- Type1 = Integer1.GetType();
- // Instantiate an Assembly class to the assembly housing the Integer type.
- SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
- // Write the display name of assembly including base name and version.
- Console::WriteLine( "FullName= {0}", SampleAssembly->FullName );
- // The example displays the following output:
- // FullName=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- //
-}
-void Snippet3()
-{
- //
- Assembly^ SampleAssembly;
- // Instantiate a target object.
- Int32 Integer1(0);
- Type^ Type1;
- // Set the Type instance to the target class type.
- Type1 = Integer1.GetType();
- // Instantiate an Assembly class to the assembly housing the Integer type.
- SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
- // Display the physical location of the assembly containing the manifest.
- Console::WriteLine( "Location= {0}", SampleAssembly->Location );
- // The example displays the following output:
- // Location=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
- //
-}
-
-void Snippet5()
-{
- //
- Assembly^ SampleAssembly;
- // Instantiate a target object.
- Int32 Integer1(0);
- Type^ Type1;
- // Set the Type instance to the target class type.
- Type1 = Integer1.GetType();
- // Instantiate an Assembly class to the assembly housing the Integer type.
- SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
- // Display the name of the assembly currently executing
- Console::WriteLine( "GetExecutingAssembly= {0}", Assembly::GetExecutingAssembly()->FullName );
- // The example displays the following output:
- // GetExecutingAssembly=assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
- //
-}
-void Snippet6()
-{
- //
- Assembly^ SampleAssembly;
- // Load the assembly by providing the location of the assembly file.
- SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" );
- for each ( Type^ ExportedType in SampleAssembly->GetExportedTypes() )
- {
- Console::WriteLine( ExportedType );
- }
- //
-}
-void Snippet7()
-{
- //
- Assembly^ SampleAssembly;
- // Load the assembly by providing the type name.
- SampleAssembly = Assembly::Load( "MyAssembly" );
- for each ( String^ Resource in SampleAssembly->GetManifestResourceNames() )
- {
- Console::WriteLine( Resource );
- }
- //
-}
-void Snippet8()
-{
- //
- Assembly^ SampleAssembly;
- SampleAssembly = Assembly::Load( "System.Data" );
- array^ Types = SampleAssembly->GetTypes();
- for each ( Type^ oType in Types )
- {
- Console::WriteLine( oType->Name );
- }
- //
-}
-void Snippet9()
-{
- //
- Assembly^ SampleAssembly;
- SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" );
-
- // Obtain a reference to the first class contained in the assembly.
- Type^ oType = SampleAssembly->GetTypes()[ 0 ];
- // Obtain a reference to the public properties of the type.
- array^ Props = oType->GetProperties();
- // Display information about public properties of assembly type.
- // Prop = Prop1
- // DeclaringType = Sample::Assembly.Class1
- // Type = System::String
- // Readable = True
- // Writable = False
- for each ( PropertyInfo^ Prop in Props )
- {
- Console::WriteLine( "Prop= {0}", Prop->Name );
- Console::WriteLine( " DeclaringType= {0}", Prop->DeclaringType );
- Console::WriteLine( " Type= {0}", Prop->PropertyType );
- Console::WriteLine( " Readable= {0}", Prop->CanRead );
- Console::WriteLine( " Writable= {0}", Prop->CanWrite );
- }
- //
-}
-void Snippet10()
-{
- //
- Assembly^ SampleAssembly;
- SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" );
- array^ Methods = SampleAssembly->GetTypes()[ 0 ]->GetMethods();
- // Obtain a reference to the method members
- for each ( MethodInfo^ Method in Methods )
- {
- Console::WriteLine( "Method Name= {0}", Method->Name );
- }
- //
-}
-void Snippet11()
-{
- //
- Assembly^ SampleAssembly;
- SampleAssembly = Assembly::LoadFrom( "c:\\Sample.Assembly.dll" );
- // Obtain a reference to a method known to exist in assembly.
- MethodInfo^ Method = SampleAssembly->GetTypes()[ 0 ]->GetMethod( "Method1" );
- // Obtain a reference to the parameters collection of the MethodInfo instance.
- array^ Params = Method->GetParameters();
- // Display information about method parameters.
- // Param = sParam1
- // Type = System::String
- // Position = 0
- // Optional=False
- for each ( ParameterInfo^ Param in Params )
- {
- Console::WriteLine( "Param= {0}", Param->Name );
- Console::WriteLine( " Type= {0}", Param->ParameterType );
- Console::WriteLine( " Position= {0}", Param->Position );
- Console::WriteLine( " Optional= {0}", Param->IsOptional );
- }
- //
- Console::ReadLine();
-}
-
-void main()
-{
- Snippet1();
- Snippet2();
- Snippet3();
- Snippet5();
- Snippet6();
- Snippet7();
- Snippet8();
- Snippet9();
- Snippet10();
- Snippet11();
-}
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/codebase1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/codebase1.cpp
deleted file mode 100644
index 3c54fa6e1c5..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/codebase1.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-void main()
-{
- // Instantiate a target object.
- int integer1 = 1632;
- // Instantiate an Assembly class to the assembly housing the Integer type.
- Assembly^ systemAssembly = integer1.GetType()->Assembly;
- // Get the location of the assembly using the file: protocol.
- Console::WriteLine("CodeBase = {0}", systemAssembly->CodeBase);
-}
-// The example displays output like the following:
-// CodeBase = file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/getcallingassembly1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/getcallingassembly1.cpp
deleted file mode 100644
index a109f1df474..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Assembly/CPP/getcallingassembly1.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-void main()
-{
- // Instantiate a target object.
- Int32 integer1 = 0;
- // Set the Type instance to the target class type.
- Type^ type1 = integer1.GetType();
- // Instantiate an Assembly class to the assembly housing the Integer type.
- Assembly^ sampleAssembly = Assembly::GetAssembly(integer1.GetType());
- // Display the name of the assembly that is calling the method.
- Console::WriteLine("GetCallingAssembly = {0}", Assembly::GetCallingAssembly()->FullName);
-}
-// The example displays output like the following:
-// GetCallingAssembly = Example, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit ILGenerator Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit ILGenerator Example/CPP/source.cpp
deleted file mode 100644
index ba2e35bfbb6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit ILGenerator Example/CPP/source.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ DynamicDotProductGen()
-{
- Type^ ivType = nullptr;
- array^temp0 = {int::typeid,int::typeid,int::typeid};
- array^ctorParams = temp0;
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "IntVectorAsm";
- AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ IntVectorModule = myAsmBuilder->DefineDynamicModule( "IntVectorModule", "Vector.dll" );
- TypeBuilder^ ivTypeBld = IntVectorModule->DefineType( "IntVector", TypeAttributes::Public );
- FieldBuilder^ xField = ivTypeBld->DefineField( "x", int::typeid, FieldAttributes::Private );
- FieldBuilder^ yField = ivTypeBld->DefineField( "y", int::typeid, FieldAttributes::Private );
- FieldBuilder^ zField = ivTypeBld->DefineField( "z", int::typeid, FieldAttributes::Private );
- Type^ objType = Type::GetType( "System.Object" );
- ConstructorInfo^ objCtor = objType->GetConstructor( gcnew array(0) );
- ConstructorBuilder^ ivCtor = ivTypeBld->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, ctorParams );
- ILGenerator^ ctorIL = ivCtor->GetILGenerator();
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Call, objCtor );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_1 );
- ctorIL->Emit( OpCodes::Stfld, xField );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_2 );
- ctorIL->Emit( OpCodes::Stfld, yField );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_3 );
- ctorIL->Emit( OpCodes::Stfld, zField );
- ctorIL->Emit( OpCodes::Ret );
-
- // This method will find the dot product of the stored vector
- // with another.
- array^temp1 = {ivTypeBld};
- array^dpParams = temp1;
-
- // Here, you create a MethodBuilder containing the
- // name, the attributes (public, static, private, and so on),
- // the return type (int, in this case), and a array of Type
- // indicating the type of each parameter. Since the sole parameter
- // is a IntVector, the very class you're creating, you will
- // pass in the TypeBuilder (which is derived from Type) instead of
- // a Type object for IntVector, avoiding an exception.
- // -- This method would be declared in C# as:
- // public int DotProduct(IntVector aVector)
- MethodBuilder^ dotProductMthd = ivTypeBld->DefineMethod( "DotProduct", MethodAttributes::Public, int::typeid, dpParams );
-
- // A ILGenerator can now be spawned, attached to the MethodBuilder.
- ILGenerator^ mthdIL = dotProductMthd->GetILGenerator();
-
- // Here's the body of our function, in MSIL form. We're going to find the
- // "dot product" of the current vector instance with the passed vector
- // instance. For reference purposes, the equation is:
- // (x1 * x2) + (y1 * y2) + (z1 * z2) = the dot product
- // First, you'll load the reference to the current instance "this"
- // stored in argument 0 (ldarg.0) onto the stack. Ldfld, the subsequent
- // instruction, will pop the reference off the stack and look up the
- // field "x", specified by the FieldInfo token "xField".
- mthdIL->Emit( OpCodes::Ldarg_0 );
- mthdIL->Emit( OpCodes::Ldfld, xField );
-
- // That completed, the value stored at field "x" is now atop the stack.
- // Now, you'll do the same for the Object reference we passed as a
- // parameter, stored in argument 1 (ldarg.1). After Ldfld executed,
- // you'll have the value stored in field "x" for the passed instance
- // atop the stack.
- mthdIL->Emit( OpCodes::Ldarg_1 );
- mthdIL->Emit( OpCodes::Ldfld, xField );
-
- // There will now be two values atop the stack - the "x" value for the
- // current vector instance, and the "x" value for the passed instance.
- // You'll now multiply them, and push the result onto the evaluation stack.
- mthdIL->Emit( OpCodes::Mul_Ovf_Un );
-
- // Now, repeat this for the "y" fields of both vectors.
- mthdIL->Emit( OpCodes::Ldarg_0 );
- mthdIL->Emit( OpCodes::Ldfld, yField );
- mthdIL->Emit( OpCodes::Ldarg_1 );
- mthdIL->Emit( OpCodes::Ldfld, yField );
- mthdIL->Emit( OpCodes::Mul_Ovf_Un );
-
- // At this time, the results of both multiplications should be atop
- // the stack. You'll now add them and push the result onto the stack.
- mthdIL->Emit( OpCodes::Add_Ovf_Un );
-
- // Multiply both "z" field and push the result onto the stack.
- mthdIL->Emit( OpCodes::Ldarg_0 );
- mthdIL->Emit( OpCodes::Ldfld, zField );
- mthdIL->Emit( OpCodes::Ldarg_1 );
- mthdIL->Emit( OpCodes::Ldfld, zField );
- mthdIL->Emit( OpCodes::Mul_Ovf_Un );
-
- // Finally, add the result of multiplying the "z" fields with the
- // result of the earlier addition, and push the result - the dot product -
- // onto the stack.
- mthdIL->Emit( OpCodes::Add_Ovf_Un );
-
- // The "ret" opcode will pop the last value from the stack and return it
- // to the calling method. You're all done!
- mthdIL->Emit( OpCodes::Ret );
- ivType = ivTypeBld->CreateType();
- return ivType;
-}
-
-int main()
-{
- Type^ IVType = nullptr;
- Object^ aVector1 = nullptr;
- Object^ aVector2 = nullptr;
- array^temp2 = {int::typeid,int::typeid,int::typeid};
- array^aVtypes = temp2;
- array^temp3 = {10,10,10};
- array^aVargs1 = temp3;
- array^temp4 = {20,20,20};
- array^aVargs2 = temp4;
-
- // Call the method to build our dynamic class.
- IVType = DynamicDotProductGen();
- Console::WriteLine( "---" );
- ConstructorInfo^ myDTctor = IVType->GetConstructor( aVtypes );
- aVector1 = myDTctor->Invoke( aVargs1 );
- aVector2 = myDTctor->Invoke( aVargs2 );
- array^passMe = gcnew array(1);
- passMe[ 0 ] = dynamic_cast(aVector2);
- Console::WriteLine( "(10, 10, 10) . (20, 20, 20) = {0}", IVType->InvokeMember( "DotProduct", BindingFlags::InvokeMethod, nullptr, aVector1, passMe ) );
-}
-
-// +++ OUTPUT +++
-// ---
-// (10, 10, 10) . (20, 20, 20) = 600
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.AddResourceFile Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.AddResourceFile Example/CPP/source.cpp
deleted file mode 100644
index 210c6ee6489..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.AddResourceFile Example/CPP/source.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-
-//
-using namespace System;
-using namespace System::IO;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-ref class AsmBuilderGetFileDemo
-{
-public:
- static String^ myResourceFileName = "MyResource.txt";
- static FileInfo^ CreateResourceFile()
- {
- FileInfo^ f = gcnew FileInfo( myResourceFileName );
- StreamWriter^ sw = f->CreateText();
- sw->WriteLine( "Hello, world!" );
- sw->Close();
- return f;
- }
-
- static AssemblyBuilder^ BuildDynAssembly()
- {
- String^ myAsmFileName = "MyAsm.dll";
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
- AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
- myAsmBuilder->AddResourceFile( "MyResource", myResourceFileName );
-
- // To confirm that the resource file has been added to the manifest,
- // we will save the assembly as MyAsm.dll. You can view the manifest
- // and confirm the presence of the resource file by running
- // "ildasm MyAsm.dll" from the prompt in the directory where you executed
- // the compiled code.
- myAsmBuilder->Save( myAsmFileName );
- return myAsmBuilder;
- }
-
-};
-
-int main()
-{
- FileStream^ myResourceFS = nullptr;
- AsmBuilderGetFileDemo::CreateResourceFile();
- Console::WriteLine( "The contents of MyResource.txt, via GetFile:" );
- AssemblyBuilder^ myAsm = AsmBuilderGetFileDemo::BuildDynAssembly();
- try
- {
- myResourceFS = myAsm->GetFile( AsmBuilderGetFileDemo::myResourceFileName );
- }
- catch ( NotSupportedException^ )
- {
- Console::WriteLine( "---" );
- Console::WriteLine( "System::Reflection::Emit::AssemblyBuilder::GetFile\nis not supported in this SDK build." );
- Console::WriteLine( "The file data will now be retrieved directly, via a new FileStream." );
- Console::WriteLine( "---" );
- myResourceFS = gcnew FileStream( AsmBuilderGetFileDemo::myResourceFileName,FileMode::Open );
- }
-
- StreamReader^ sr = gcnew StreamReader( myResourceFS,System::Text::Encoding::ASCII );
- Console::WriteLine( sr->ReadToEnd() );
- sr->Close();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.DefineDynamicModule Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.DefineDynamicModule Example/CPP/source.cpp
deleted file mode 100644
index 90c18c11fa1..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.DefineDynamicModule Example/CPP/source.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-class TypeBuilderMemberDemo
-{
-public:
- static void DefineDynamicModuleDemo1()
- {
- //
- AppDomain^ myAppDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyAssembly";
- AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
- myAsmName, AssemblyBuilderAccess::Run );
-
- // Create a transient dynamic module. Since no DLL name is specified with
- // this constructor, it cannot be saved.
- ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule( "MyModule1" );
- //
- }
-
- static void DefineDynamicModuleDemo2()
- {
- //
- AppDomain^ myAppDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyAssembly";
- AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
- myAsmName, AssemblyBuilderAccess::Run );
-
- // Create a transient dynamic module. Since no DLL name is specified with
- // this constructor, it can not be saved. By specifying the second parameter
- // of the constructor as false, we can suppress the emission of symbol info.
- ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule(
- "MyModule2", false );
- //
- }
-
- static void DefineDynamicModuleDemo3()
- {
- //
- AppDomain^ myAppDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyAssembly";
- AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
- myAsmName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module that can be saved as the specified DLL name.
- ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule(
- "MyModule3", "MyModule3.dll" );
- //
- }
-
- static void DefineDynamicModuleDemo4()
- {
- //
- AppDomain^ myAppDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyAssembly";
- AssemblyBuilder^ myAsmBuilder = myAppDomain->DefineDynamicAssembly(
- myAsmName, AssemblyBuilderAccess::Run );
-
- // Create a dynamic module that can be saved as the specified DLL name. By
- // specifying the third parameter as true, we can allow the emission of symbol info.
- ModuleBuilder^ myModuleBuilder = myAsmBuilder->DefineDynamicModule(
- "MyModule4", "MyModule4.dll", true );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.Save Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.Save Example/CPP/source.cpp
deleted file mode 100644
index 7ecadcfc345..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.AssemblyBuilder.Save Example/CPP/source.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Text;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-// The Point class is the class we will reflect on and copy into our
-// dynamic assembly. The public static function PointMain() will be used
-// as our entry point.
-//
-// We are constructing the type seen here dynamically, and will write it
-// out into a .exe file for later execution from the command-line.
-// ---
-// __gc class Point {
-//
-// private:
-// int x;
-// int y;
-//
-// public:
-// Point(int ix, int iy) {
-//
-// this->x = ix;
-// this->y = iy;
-//
-// }
-//
-// int DotProduct (Point* p) {
-//
-// return ((this->x * p->x) + (this->y * p->y));
-//
-// }
-//
-// static void PointMain() {
-//
-// Console::Write(S"Enter the 'x' value for point 1: ");
-// int x1 = Convert::ToInt32(Console::ReadLine());
-//
-// Console::Write(S"Enter the 'y' value for point 1: ");
-// int y1 = Convert::ToInt32(Console::ReadLine());
-//
-// Console::Write(S"Enter the 'x' value for point 2: ");
-// int x2 = Convert::ToInt32(Console::ReadLine());
-//
-// Console::Write(S"Enter the 'y' value for point 2: ");
-// int y2 = Convert::ToInt32(Console::ReadLine());
-//
-// Point* p1 = new Point(x1, y1);
-// Point* p2 = new Point(x2, y2);
-//
-// Console::WriteLine(S"( {0}, {1}) . ( {2}, {3}) = {4}.",
-// __box(x1), __box(y1), __box(x2), __box(y2), p1->DotProduct(p2));
-//
-// }
-//
-// };
-// ---
-Type^ BuildDynAssembly()
-{
- Type^ pointType = nullptr;
- AppDomain^ currentDom = Thread::GetDomain();
- Console::Write( "Please enter a name for your new assembly: " );
- StringBuilder^ asmFileNameBldr = gcnew StringBuilder;
- asmFileNameBldr->Append( Console::ReadLine() );
- asmFileNameBldr->Append( ".exe" );
- String^ asmFileName = asmFileNameBldr->ToString();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
- AssemblyBuilder^ myAsmBldr = currentDom->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
-
- // We've created a dynamic assembly space - now, we need to create a module
- // within it to reflect the type Point into.
- ModuleBuilder^ myModuleBldr = myAsmBldr->DefineDynamicModule( asmFileName, asmFileName );
- TypeBuilder^ myTypeBldr = myModuleBldr->DefineType( "Point" );
- FieldBuilder^ xField = myTypeBldr->DefineField( "x", int::typeid, FieldAttributes::Private );
- FieldBuilder^ yField = myTypeBldr->DefineField( "y", int::typeid, FieldAttributes::Private );
-
- // Build the constructor.
- Type^ objType = Type::GetType( "System.Object" );
- ConstructorInfo^ objCtor = objType->GetConstructor( gcnew array(0) );
- array^temp4 = {int::typeid,int::typeid};
- array^ctorParams = temp4;
- ConstructorBuilder^ pointCtor = myTypeBldr->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, ctorParams );
- ILGenerator^ ctorIL = pointCtor->GetILGenerator();
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Call, objCtor );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_1 );
- ctorIL->Emit( OpCodes::Stfld, xField );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_2 );
- ctorIL->Emit( OpCodes::Stfld, yField );
- ctorIL->Emit( OpCodes::Ret );
-
- // Build the DotProduct method.
- Console::WriteLine( "Constructor built." );
- array^temp0 = {myTypeBldr};
- MethodBuilder^ pointDPBldr = myTypeBldr->DefineMethod( "DotProduct", MethodAttributes::Public, int::typeid, temp0 );
- ILGenerator^ dpIL = pointDPBldr->GetILGenerator();
- dpIL->Emit( OpCodes::Ldarg_0 );
- dpIL->Emit( OpCodes::Ldfld, xField );
- dpIL->Emit( OpCodes::Ldarg_1 );
- dpIL->Emit( OpCodes::Ldfld, xField );
- dpIL->Emit( OpCodes::Mul_Ovf_Un );
- dpIL->Emit( OpCodes::Ldarg_0 );
- dpIL->Emit( OpCodes::Ldfld, yField );
- dpIL->Emit( OpCodes::Ldarg_1 );
- dpIL->Emit( OpCodes::Ldfld, yField );
- dpIL->Emit( OpCodes::Mul_Ovf_Un );
- dpIL->Emit( OpCodes::Add_Ovf_Un );
- dpIL->Emit( OpCodes::Ret );
-
- // Build the PointMain method.
- Console::WriteLine( "DotProduct built." );
- MethodBuilder^ pointMainBldr = myTypeBldr->DefineMethod( "PointMain", static_cast(MethodAttributes::Public | MethodAttributes::Static), void::typeid, nullptr );
- pointMainBldr->InitLocals = true;
- ILGenerator^ pmIL = pointMainBldr->GetILGenerator();
-
- // We have four methods that we wish to call, and must represent as
- // MethodInfo tokens:
- // - void Console::WriteLine(String*)
- // - String* Console::ReadLine()
- // - int Convert::Int32(String*)
- // - void Console::WriteLine(String*, Object*[])
- array^temp1 = {String::typeid};
- MethodInfo^ writeMI = Console::typeid->GetMethod( "Write", temp1 );
- MethodInfo^ readLineMI = Console::typeid->GetMethod( "ReadLine", gcnew array(0) );
- array^temp2 = {String::typeid};
- MethodInfo^ convertInt32MI = Convert::typeid->GetMethod( "ToInt32", temp2 );
- array^temp5 = {String::typeid,array::typeid};
- array^wlParams = temp5;
- MethodInfo^ writeLineMI = Console::typeid->GetMethod( "WriteLine", wlParams );
-
- // Although we could just refer to the local variables by
- // index (short ints for Ldloc/Stloc, bytes for LdLoc_S/Stloc_S),
- // this time, we'll use LocalBuilders for clarity and to
- // demonstrate their usage and syntax.
- LocalBuilder^ x1LB = pmIL->DeclareLocal( int::typeid );
- LocalBuilder^ y1LB = pmIL->DeclareLocal( int::typeid );
- LocalBuilder^ x2LB = pmIL->DeclareLocal( int::typeid );
- LocalBuilder^ y2LB = pmIL->DeclareLocal( int::typeid );
- LocalBuilder^ point1LB = pmIL->DeclareLocal( myTypeBldr );
- LocalBuilder^ point2LB = pmIL->DeclareLocal( myTypeBldr );
- LocalBuilder^ tempObjArrLB = pmIL->DeclareLocal( array::typeid );
- pmIL->Emit( OpCodes::Ldstr, "Enter the 'x' value for point 1: " );
- pmIL->EmitCall( OpCodes::Call, writeMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, readLineMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, convertInt32MI, nullptr );
- pmIL->Emit( OpCodes::Stloc, x1LB );
- pmIL->Emit( OpCodes::Ldstr, "Enter the 'y' value for point 1: " );
- pmIL->EmitCall( OpCodes::Call, writeMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, readLineMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, convertInt32MI, nullptr );
- pmIL->Emit( OpCodes::Stloc, y1LB );
- pmIL->Emit( OpCodes::Ldstr, "Enter the 'x' value for point 2: " );
- pmIL->EmitCall( OpCodes::Call, writeMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, readLineMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, convertInt32MI, nullptr );
- pmIL->Emit( OpCodes::Stloc, x2LB );
- pmIL->Emit( OpCodes::Ldstr, "Enter the 'y' value for point 2: " );
- pmIL->EmitCall( OpCodes::Call, writeMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, readLineMI, nullptr );
- pmIL->EmitCall( OpCodes::Call, convertInt32MI, nullptr );
- pmIL->Emit( OpCodes::Stloc, y2LB );
- pmIL->Emit( OpCodes::Ldloc, x1LB );
- pmIL->Emit( OpCodes::Ldloc, y1LB );
- pmIL->Emit( OpCodes::Newobj, pointCtor );
- pmIL->Emit( OpCodes::Stloc, point1LB );
- pmIL->Emit( OpCodes::Ldloc, x2LB );
- pmIL->Emit( OpCodes::Ldloc, y2LB );
- pmIL->Emit( OpCodes::Newobj, pointCtor );
- pmIL->Emit( OpCodes::Stloc, point2LB );
- pmIL->Emit( OpCodes::Ldstr, "( {0}, {1}) . ( {2}, {3}) = {4}." );
- pmIL->Emit( OpCodes::Ldc_I4_5 );
- pmIL->Emit( OpCodes::Newarr, Object::typeid );
- pmIL->Emit( OpCodes::Stloc, tempObjArrLB );
- pmIL->Emit( OpCodes::Ldloc, tempObjArrLB );
- pmIL->Emit( OpCodes::Ldc_I4_0 );
- pmIL->Emit( OpCodes::Ldloc, x1LB );
- pmIL->Emit( OpCodes::Box, int::typeid );
- pmIL->Emit( OpCodes::Stelem_Ref );
- pmIL->Emit( OpCodes::Ldloc, tempObjArrLB );
- pmIL->Emit( OpCodes::Ldc_I4_1 );
- pmIL->Emit( OpCodes::Ldloc, y1LB );
- pmIL->Emit( OpCodes::Box, int::typeid );
- pmIL->Emit( OpCodes::Stelem_Ref );
- pmIL->Emit( OpCodes::Ldloc, tempObjArrLB );
- pmIL->Emit( OpCodes::Ldc_I4_2 );
- pmIL->Emit( OpCodes::Ldloc, x2LB );
- pmIL->Emit( OpCodes::Box, int::typeid );
- pmIL->Emit( OpCodes::Stelem_Ref );
- pmIL->Emit( OpCodes::Ldloc, tempObjArrLB );
- pmIL->Emit( OpCodes::Ldc_I4_3 );
- pmIL->Emit( OpCodes::Ldloc, y2LB );
- pmIL->Emit( OpCodes::Box, int::typeid );
- pmIL->Emit( OpCodes::Stelem_Ref );
- pmIL->Emit( OpCodes::Ldloc, tempObjArrLB );
- pmIL->Emit( OpCodes::Ldc_I4_4 );
- pmIL->Emit( OpCodes::Ldloc, point1LB );
- pmIL->Emit( OpCodes::Ldloc, point2LB );
- pmIL->EmitCall( OpCodes::Callvirt, pointDPBldr, nullptr );
- pmIL->Emit( OpCodes::Box, int::typeid );
- pmIL->Emit( OpCodes::Stelem_Ref );
- pmIL->Emit( OpCodes::Ldloc, tempObjArrLB );
- pmIL->EmitCall( OpCodes::Call, writeLineMI, nullptr );
- pmIL->Emit( OpCodes::Ret );
- Console::WriteLine( "PointMain (entry point) built." );
- pointType = myTypeBldr->CreateType();
- Console::WriteLine( "Type completed." );
- myAsmBldr->SetEntryPoint( pointMainBldr );
- myAsmBldr->Save( asmFileName );
- Console::WriteLine( "Assembly saved as ' {0}'.", asmFileName );
- Console::WriteLine( "Type ' {0}' at the prompt to run your new dynamically generated dot product calculator.", asmFileName );
-
- // After execution, this program will have generated and written to disk,
- // in the directory you executed it from, a program named
- // .exe. You can run it by typing
- // the name you gave it during execution, in the same directory where
- // you executed this program.
- return pointType;
-}
-
-int main()
-{
- Type^ myType = BuildDynAssembly();
- Console::WriteLine( "---" );
-
- // Let's invoke the type 'Point' created in our dynamic assembly.
- array^temp3 = {nullptr,nullptr};
- Object^ ptInstance = Activator::CreateInstance( myType, temp3 );
- myType->InvokeMember( "PointMain", BindingFlags::InvokeMethod, nullptr, ptInstance, gcnew array(0) );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ConstructorBuilder Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ConstructorBuilder Example/CPP/source.cpp
deleted file mode 100644
index 5fc4617dce5..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ConstructorBuilder Example/CPP/source.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ DynamicPointTypeGen()
-{
- Type^ pointType = nullptr;
- array^temp0 = {int::typeid,int::typeid,int::typeid};
- array^ctorParams = temp0;
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
- AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ pointModule = myAsmBuilder->DefineDynamicModule( "PointModule", "Point.dll" );
- TypeBuilder^ pointTypeBld = pointModule->DefineType( "Point", TypeAttributes::Public );
- FieldBuilder^ xField = pointTypeBld->DefineField( "x", int::typeid, FieldAttributes::Public );
- FieldBuilder^ yField = pointTypeBld->DefineField( "y", int::typeid, FieldAttributes::Public );
- FieldBuilder^ zField = pointTypeBld->DefineField( "z", int::typeid, FieldAttributes::Public );
- Type^ objType = Type::GetType( "System.Object" );
- ConstructorInfo^ objCtor = objType->GetConstructor( gcnew array(0) );
- ConstructorBuilder^ pointCtor = pointTypeBld->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, ctorParams );
- ILGenerator^ ctorIL = pointCtor->GetILGenerator();
-
- // NOTE: ldarg.0 holds the "this" reference - ldarg.1, ldarg.2, and ldarg.3
- // hold the actual passed parameters. ldarg.0 is used by instance methods
- // to hold a reference to the current calling bject instance. Static methods
- // do not use arg.0, since they are not instantiated and hence no reference
- // is needed to distinguish them.
- ctorIL->Emit( OpCodes::Ldarg_0 );
-
- // Here, we wish to create an instance of System::Object by invoking its
- // constructor, as specified above.
- ctorIL->Emit( OpCodes::Call, objCtor );
-
- // Now, we'll load the current instance in arg 0, along
- // with the value of parameter "x" stored in arg 1, into stfld.
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_1 );
- ctorIL->Emit( OpCodes::Stfld, xField );
-
- // Now, we store arg 2 "y" in the current instance with stfld.
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_2 );
- ctorIL->Emit( OpCodes::Stfld, yField );
-
- // Last of all, arg 3 "z" gets stored in the current instance.
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_3 );
- ctorIL->Emit( OpCodes::Stfld, zField );
-
- // Our work complete, we return.
- ctorIL->Emit( OpCodes::Ret );
-
- // Now, let's create three very simple methods so we can see our fields.
- array^temp1 = {"GetX","GetY","GetZ"};
- array^mthdNames = temp1;
- System::Collections::IEnumerator^ myEnum = mthdNames->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- String^ mthdName = safe_cast(myEnum->Current);
- MethodBuilder^ getFieldMthd = pointTypeBld->DefineMethod( mthdName, MethodAttributes::Public, int::typeid, nullptr );
- ILGenerator^ mthdIL = getFieldMthd->GetILGenerator();
- mthdIL->Emit( OpCodes::Ldarg_0 );
- if ( mthdName->Equals( "GetX" ) )
- mthdIL->Emit( OpCodes::Ldfld, xField );
- else
- if ( mthdName->Equals( "GetY" ) )
- mthdIL->Emit( OpCodes::Ldfld, yField );
- else
- if ( mthdName->Equals( "GetZ" ) )
- mthdIL->Emit( OpCodes::Ldfld, zField );
-
-
-
- mthdIL->Emit( OpCodes::Ret );
- }
-
- pointType = pointTypeBld->CreateType();
-
- // Let's save it, just for posterity.
- myAsmBuilder->Save( "Point.dll" );
- return pointType;
-}
-
-int main()
-{
- Type^ myDynamicType = nullptr;
- Object^ aPoint = nullptr;
- array^temp2 = {int::typeid,int::typeid,int::typeid};
- array^aPtypes = temp2;
- array^temp3 = {4,5,6};
- array^aPargs = temp3;
-
- // Call the method to build our dynamic class.
- myDynamicType = DynamicPointTypeGen();
- Console::WriteLine( "Some information about my new Type '{0}':", myDynamicType->FullName );
- Console::WriteLine( "Assembly: '{0}'", myDynamicType->Assembly );
- Console::WriteLine( "Attributes: '{0}'", myDynamicType->Attributes );
- Console::WriteLine( "Module: '{0}'", myDynamicType->Module );
- Console::WriteLine( "Members: " );
- System::Collections::IEnumerator^ myEnum = myDynamicType->GetMembers()->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- MemberInfo^ member = safe_cast(myEnum->Current);
- Console::WriteLine( "-- {0} {1};", member->MemberType, member->Name );
- }
-
- Console::WriteLine( "---" );
-
- // Let's take a look at the constructor we created.
- ConstructorInfo^ myDTctor = myDynamicType->GetConstructor( aPtypes );
- Console::WriteLine( "Constructor: {0};", myDTctor );
- Console::WriteLine( "---" );
-
- // Now, we get to use our dynamically-created class by invoking the constructor.
- aPoint = myDTctor->Invoke( aPargs );
- Console::WriteLine( "aPoint is type {0}.", aPoint->GetType() );
-
- // Finally, let's reflect on the instance of our new type - aPoint - and
- // make sure everything proceeded according to plan.
- Console::WriteLine( "aPoint.x = {0}", myDynamicType->InvokeMember( "GetX", BindingFlags::InvokeMethod, nullptr, aPoint, gcnew array(0) ) );
- Console::WriteLine( "aPoint.y = {0}", myDynamicType->InvokeMember( "GetY", BindingFlags::InvokeMethod, nullptr, aPoint, gcnew array(0) ) );
- Console::WriteLine( "aPoint.z = {0}", myDynamicType->InvokeMember( "GetZ", BindingFlags::InvokeMethod, nullptr, aPoint, gcnew array(0) ) );
-
- // +++ OUTPUT +++
- // Some information about my new Type 'Point':
- // Assembly: 'MyDynamicAssembly, Version=0.0.0.0'
- // Attributes: 'AutoLayout, AnsiClass, NotPublic, Public'
- // Module: 'PointModule'
- // Members:
- // -- Field x;
- // -- Field y;
- // -- Field z;
- // -- Method GetHashCode;
- // -- Method Equals;
- // -- Method ToString;
- // -- Method GetType;
- // -- Constructor .ctor;
- // ---
- // Constructor: Void .ctor(Int32, Int32, Int32);
- // ---
- // aPoint is type Point.
- // aPoint.x = 4
- // aPoint.y = 5
- // aPoint.z = 6
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.CustomAttributeBuilder Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.CustomAttributeBuilder Example/CPP/source.cpp
deleted file mode 100644
index 0529bd4ec8c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.CustomAttributeBuilder Example/CPP/source.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-// We will apply this custom attribute to our dynamic type.
-public ref class ClassCreator: public Attribute
-{
-private:
- String^ creator;
-
-public:
-
- property String^ Creator
- {
- String^ get()
- {
- return creator;
- }
-
- }
- ClassCreator( String^ name )
- {
- this->creator = name;
- }
-
-};
-
-
-// We will apply this dynamic attribute to our dynamic method.
-public ref class DateLastUpdated: public Attribute
-{
-private:
- String^ dateUpdated;
-
-public:
-
- property String^ DateUpdated
- {
- String^ get()
- {
- return dateUpdated;
- }
-
- }
- DateLastUpdated( String^ theDate )
- {
- this->dateUpdated = theDate;
- }
-
-};
-
-Type^ BuildTypeWithCustomAttributesOnMethod()
-{
- AppDomain^ currentDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyAssembly";
- AssemblyBuilder^ myAsmBuilder = currentDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::Run );
- ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MyModule" );
-
- // First, we'll build a type with a custom attribute attached.
- TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "MyType", TypeAttributes::Public );
- array^temp6 = {String::typeid};
- array^ctorParams = temp6;
- ConstructorInfo^ classCtorInfo = ClassCreator::typeid->GetConstructor( ctorParams );
- array^temp0 = {"Joe Programmer"};
- CustomAttributeBuilder^ myCABuilder = gcnew CustomAttributeBuilder( classCtorInfo,temp0 );
- myTypeBuilder->SetCustomAttribute( myCABuilder );
-
- // Now, let's build a method and add a custom attribute to it.
- array^temp1 = gcnew array(0);
- MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "HelloWorld", MethodAttributes::Public, nullptr, temp1 );
- array^temp7 = {String::typeid};
- ctorParams = temp7;
- classCtorInfo = DateLastUpdated::typeid->GetConstructor( ctorParams );
- array^temp2 = {DateTime::Now.ToString()};
- CustomAttributeBuilder^ myCABuilder2 = gcnew CustomAttributeBuilder( classCtorInfo,temp2 );
- myMethodBuilder->SetCustomAttribute( myCABuilder2 );
- ILGenerator^ myIL = myMethodBuilder->GetILGenerator();
- myIL->EmitWriteLine( "Hello, world!" );
- myIL->Emit( OpCodes::Ret );
- return myTypeBuilder->CreateType();
-}
-
-int main()
-{
- Type^ myType = BuildTypeWithCustomAttributesOnMethod();
- Object^ myInstance = Activator::CreateInstance( myType );
- array^customAttrs = myType->GetCustomAttributes( true );
- Console::WriteLine( "Custom Attributes for Type 'MyType':" );
- Object^ attrVal = nullptr;
- System::Collections::IEnumerator^ myEnum = customAttrs->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Object^ customAttr = safe_cast(myEnum->Current);
- array^temp3 = gcnew array(0);
- attrVal = ClassCreator::typeid->InvokeMember( "Creator", BindingFlags::GetProperty, nullptr, customAttr, temp3 );
- Console::WriteLine( "-- Attribute: [{0} = \"{1}\"]", customAttr, attrVal );
- }
-
- Console::WriteLine( "Custom Attributes for Method 'HelloWorld()' in 'MyType':" );
- customAttrs = myType->GetMember( "HelloWorld" )[ 0 ]->GetCustomAttributes( true );
- System::Collections::IEnumerator^ myEnum2 = customAttrs->GetEnumerator();
- while ( myEnum2->MoveNext() )
- {
- Object^ customAttr = safe_cast(myEnum2->Current);
- array^temp4 = gcnew array(0);
- attrVal = DateLastUpdated::typeid->InvokeMember( "DateUpdated", BindingFlags::GetProperty, nullptr, customAttr, temp4 );
- Console::WriteLine( "-- Attribute: [{0} = \"{1}\"]", customAttr, attrVal );
- }
-
- Console::WriteLine( "---" );
- array^temp5 = gcnew array(0);
- Console::WriteLine( myType->InvokeMember( "HelloWorld", BindingFlags::InvokeMethod, nullptr, myInstance, temp5 ) );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.Emit Example 2/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.Emit Example 2/CPP/source.cpp
deleted file mode 100644
index 2c62a49f16a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.Emit Example 2/CPP/source.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ BuildMyType()
-{
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
- AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::Run );
- ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MyJumpTableDemo" );
- TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "JumpTableDemo", TypeAttributes::Public );
- array^temp0 = {int::typeid};
- MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "SwitchMe", static_cast(MethodAttributes::Public | MethodAttributes::Static), String::typeid, temp0 );
- ILGenerator^ myIL = myMthdBuilder->GetILGenerator();
- Label defaultCase = myIL->DefineLabel();
- Label endOfMethod = myIL->DefineLabel();
-
- // We are initializing our jump table. Note that the labels
- // will be placed later using the MarkLabel method.
- array
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.EmitCalli Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.EmitCalli Example/CPP/source.cpp
deleted file mode 100644
index 06f186f7b7b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.EmitCalli Example/CPP/source.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-class MyDynamicAssembly
-{
-public:
- static void BuildDynamicMethod( TypeBuilder^ myTypeBuilder,
- array^ mthdParamTypes,
- Type^ returnType,
- int addrOfLegacyNumberObject )
- {
- //
- MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "MyMethod",
- MethodAttributes::Public,
- returnType, mthdParamTypes );
-
- // We will assume that an external unmanaged type "LegacyNumber" has been loaded, and
- // that it has a method "ToString" which returns a String.
-
- MethodInfo^ unmanagedMthdMI = Type::GetType( "LegacyNumber" )->GetMethod( "ToString" );
- ILGenerator^ myMthdIL = myMthdBuilder->GetILGenerator();
-
- // Code to emit various IL opcodes here ...
-
- // Load a reference to the specific Object instance onto the stack.
-
- myMthdIL->Emit( OpCodes::Ldc_I4, addrOfLegacyNumberObject );
- myMthdIL->Emit( OpCodes::Ldobj, Type::GetType( "LegacyNumber" ) );
-
- // Make the call to the unmanaged type method, telling it that the method is
- // the member of a specific instance, to expect a String
- // as a return value, and that there are no explicit parameters.
- myMthdIL->EmitCalli( OpCodes::Calli,
- System::Runtime::InteropServices::CallingConvention::ThisCall,
- String::typeid,
- gcnew array( 0 ) );
-
- // More IL code emission here ...
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.OpCodes Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.OpCodes Example/CPP/source.cpp
deleted file mode 100644
index cc26ae7bb54..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.OpCodes Example/CPP/source.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ CreateDynamicType()
-{
- array^ctorParams = {int::typeid,int::typeid};
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
- AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::Run );
- ModuleBuilder^ pointModule = myAsmBuilder->DefineDynamicModule( "PointModule", "Point.dll" );
- TypeBuilder^ pointTypeBld = pointModule->DefineType( "Point", TypeAttributes::Public );
- FieldBuilder^ xField = pointTypeBld->DefineField( "x", int::typeid, FieldAttributes::Public );
- FieldBuilder^ yField = pointTypeBld->DefineField( "y", int::typeid, FieldAttributes::Public );
- Type^ objType = Type::GetType( "System.Object" );
- ConstructorInfo^ objCtor = objType->GetConstructor( gcnew array(0) );
- ConstructorBuilder^ pointCtor = pointTypeBld->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, ctorParams );
- ILGenerator^ ctorIL = pointCtor->GetILGenerator();
-
- // First, you build the constructor.
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Call, objCtor );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_1 );
- ctorIL->Emit( OpCodes::Stfld, xField );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_2 );
- ctorIL->Emit( OpCodes::Stfld, yField );
- ctorIL->Emit( OpCodes::Ret );
-
- // Now, you'll build a method to output some information on the
- // inside your dynamic class. This method will have the following
- // definition in C#:
- // public void WritePoint()
- MethodBuilder^ writeStrMthd = pointTypeBld->DefineMethod( "WritePoint", MethodAttributes::Public, void::typeid, nullptr );
- ILGenerator^ writeStrIL = writeStrMthd->GetILGenerator();
-
- // The below ILGenerator created demonstrates a few ways to create
- // String* output through STDIN.
- // ILGenerator::EmitWriteLine(String*) will generate a ldstr and a
- // call to WriteLine for you.
- writeStrIL->EmitWriteLine( "The value of this current instance is:" );
-
- // Here, you will do the hard work yourself. First, you need to create
- // the String* we will be passing and obtain the correct WriteLine overload
- // for said String*. In the below case, you are substituting in two values,
- // so the chosen overload is Console::WriteLine(String*, Object*, Object*).
- String^ inStr = "( {0}, {1})";
- array^wlParams = {String::typeid,Object::typeid,Object::typeid};
-
- // We need the MethodInfo to pass into EmitCall later.
- MethodInfo^ writeLineMI = Console::typeid->GetMethod( "WriteLine", wlParams );
-
- // Push the String* with the substitutions onto the stack.
- // This is the first argument for WriteLine - the String* one.
- writeStrIL->Emit( OpCodes::Ldstr, inStr );
-
- // Since the second argument is an Object*, and it corresponds to
- // to the substitution for the value of our integer field, you
- // need to box that field to an Object*. First, push a reference
- // to the current instance, and then push the value stored in
- // field 'x'. We need the reference to the current instance (stored
- // in local argument index 0) so Ldfld can load from the correct
- // instance (this one).
- writeStrIL->Emit( OpCodes::Ldarg_0 );
- writeStrIL->Emit( OpCodes::Ldfld, xField );
-
- // Now, we execute the box opcode, which pops the value of field 'x',
- // returning a reference to the integer value boxed as an Object*.
- writeStrIL->Emit( OpCodes::Box, int::typeid );
-
- // Atop the stack, you'll find our String* inStr, followed by a reference
- // to the boxed value of 'x'. Now, you need to likewise box field 'y'.
- writeStrIL->Emit( OpCodes::Ldarg_0 );
- writeStrIL->Emit( OpCodes::Ldfld, yField );
- writeStrIL->Emit( OpCodes::Box, int::typeid );
-
- // Now, you have all of the arguments for your call to
- // Console::WriteLine(String*, Object*, Object*) atop the stack:
- // the String* InStr, a reference to the boxed value of 'x', and
- // a reference to the boxed value of 'y'.
- // Call Console::WriteLine(String*, Object*, Object*) with EmitCall.
- writeStrIL->EmitCall( OpCodes::Call, writeLineMI, nullptr );
-
- // Lastly, EmitWriteLine can also output the value of a field
- // using the overload EmitWriteLine(FieldInfo).
- writeStrIL->EmitWriteLine( "The value of 'x' is:" );
- writeStrIL->EmitWriteLine( xField );
- writeStrIL->EmitWriteLine( "The value of 'y' is:" );
- writeStrIL->EmitWriteLine( yField );
-
- // Since we return no value (void), the ret opcode will not
- // return the top stack value.
- writeStrIL->Emit( OpCodes::Ret );
- return pointTypeBld->CreateType();
-}
-
-int main()
-{
- array^ctorParams = gcnew array(2);
- Console::Write( "Enter a integer value for X: " );
- String^ myX = Console::ReadLine();
- Console::Write( "Enter a integer value for Y: " );
- String^ myY = Console::ReadLine();
- Console::WriteLine( "---" );
- ctorParams[ 0 ] = Convert::ToInt32( myX );
- ctorParams[ 1 ] = Convert::ToInt32( myY );
- Type^ ptType = CreateDynamicType();
- Object^ ptInstance = Activator::CreateInstance( ptType, ctorParams );
- ptType->InvokeMember( "WritePoint", BindingFlags::InvokeMethod, nullptr, ptInstance, gcnew array(0) );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.ThrowException Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.ThrowException Example/CPP/source.cpp
deleted file mode 100644
index a8bc130aeb6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ILGenerator.ThrowException Example/CPP/source.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-int main()
-{
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "AdderExceptionAsm";
- AssemblyBuilder^ myAsmBldr = myDomain->DefineDynamicAssembly( myAsmName,
- AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ myModBldr = myAsmBldr->DefineDynamicModule( myAsmName->Name,
- myAsmName->Name + ".dll" );
- TypeBuilder^ myTypeBldr = myModBldr->DefineType( "Adder" );
- array^adderParams = {int::typeid,int::typeid};
-
- // This method will add two numbers which are 100 or less. If either of the
- // passed integer vales are greater than 100, it will throw an exception.
- MethodBuilder^ adderBldr = myTypeBldr->DefineMethod( "DoAdd",
- static_cast(MethodAttributes::Public | MethodAttributes::Static),
- int::typeid, adderParams );
- ILGenerator^ adderIL = adderBldr->GetILGenerator();
-
- // Types and methods used in the code to throw, catch, and
- // display OverflowException. Note that if the catch block were
- // for a more general type, such as Exception, we would need
- // a MethodInfo for that type's ToString method.
- //
- Type^ overflow = OverflowException::typeid;
- ConstructorInfo^ exCtorInfo = overflow->GetConstructor(
- gcnew array { String::typeid });
- MethodInfo^ exToStrMI = overflow->GetMethod( "ToString" );
- MethodInfo^ writeLineMI = Console::typeid->GetMethod( "WriteLine",
- gcnew array { String::typeid, Object::typeid } );
-
- LocalBuilder^ tmp1 = adderIL->DeclareLocal( int::typeid );
- LocalBuilder^ tmp2 = adderIL->DeclareLocal( overflow );
-
- // In order to successfully branch, we need to create labels
- // representing the offset IL instruction block to branch to.
- // These labels, when the MarkLabel(Label) method is invoked,
- // will specify the IL instruction to branch to.
- //
- Label failed = adderIL->DefineLabel();
- Label endOfMthd = adderIL->DefineLabel();
-
- // Begin the try block.
- Label exBlock = adderIL->BeginExceptionBlock();
-
- // First, load argument 0 and the integer value of S"100" onto the
- // stack. If arg0 > 100, branch to the label S"failed", which is marked
- // as the address of the block that throws an exception.
- adderIL->Emit( OpCodes::Ldarg_0 );
- adderIL->Emit( OpCodes::Ldc_I4_S, 100 );
- adderIL->Emit( OpCodes::Bgt_S, failed );
-
- // Now, check to see if argument 1 was greater than 100. If it was,
- // branch to S"failed." Otherwise, fall through and perform the addition,
- // branching unconditionally to the instruction at the label S"endOfMthd".
- adderIL->Emit( OpCodes::Ldarg_1 );
- adderIL->Emit( OpCodes::Ldc_I4_S, 100 );
- adderIL->Emit( OpCodes::Bgt_S, failed );
-
- adderIL->Emit( OpCodes::Ldarg_0 );
- adderIL->Emit( OpCodes::Ldarg_1 );
- adderIL->Emit( OpCodes::Add_Ovf_Un );
- // Store the result of the addition.
- adderIL->Emit( OpCodes::Stloc_S, tmp1 );
- adderIL->Emit( OpCodes::Br_S, endOfMthd );
-
- // If one of the arguments was greater than 100, we need to throw an
- // exception. We'll use "OverflowException" with a customized message.
- // First, we load our message onto the stack, and then create a new
- // exception Object using the constructor overload that accepts a
- // String* message.
- adderIL->MarkLabel( failed );
- adderIL->Emit( OpCodes::Ldstr, "Cannot accept values over 100 for add." );
- adderIL->Emit( OpCodes::Newobj, exCtorInfo );
-
- // We're going to need to refer to that exception Object later, so let's
- // store it in a temporary variable. Since the store function pops the
- // the value/reference off the stack, and we'll need it to throw the
- // exception, we will subsequently load it back onto the stack as well.
- adderIL->Emit( OpCodes::Stloc_S, tmp2 );
- adderIL->Emit( OpCodes::Ldloc_S, tmp2 );
-
- // Throw the exception now on the stack.
- adderIL->ThrowException( overflow );
-
- // Start the catch block for OverflowException.
- //
- adderIL->BeginCatchBlock( overflow );
-
- // When we enter the catch block, the thrown exception
- // is on the stack. Store it, then load the format string
- // for WriteLine.
- //
- adderIL->Emit(OpCodes::Stloc_S, tmp2);
- adderIL->Emit(OpCodes::Ldstr, "Caught {0}");
-
- // Push the thrown exception back on the stack, then
- // call its ToString() method. Note that if this catch block
- // were for a more general exception type, like Exception,
- // it would be necessary to use the ToString for that type.
- //
- adderIL->Emit(OpCodes::Ldloc_S, tmp2);
- adderIL->EmitCall(OpCodes::Callvirt, exToStrMI, nullptr);
-
- // The format string and the return value from ToString() are
- // now on the stack. Call WriteLine(string, object).
- //
- adderIL->EmitCall( OpCodes::Call, writeLineMI, nullptr );
-
- // Since our function has to return an integer value, we'll load -1 onto
- // the stack to indicate an error, and store it in local variable tmp1.
- adderIL->Emit( OpCodes::Ldc_I4_M1 );
- adderIL->Emit( OpCodes::Stloc_S, tmp1 );
-
- // End the exception handling block.
- adderIL->EndExceptionBlock();
-
- // The end of the method. If no exception was thrown, the correct value
- // will be saved in tmp1. If an exception was thrown, tmp1 will be equal
- // to -1. Either way, we'll load the value of tmp1 onto the stack and return.
- adderIL->MarkLabel( endOfMthd );
- adderIL->Emit( OpCodes::Ldloc_S, tmp1 );
- adderIL->Emit( OpCodes::Ret );
-
- Type^ adderType = myTypeBldr->CreateType();
-
- Object^ addIns = Activator::CreateInstance( adderType );
-
- array^addParams = gcnew array(2);
-
- Console::Write( "Enter an integer value: " );
- addParams[ 0 ] = Convert::ToInt32( Console::ReadLine() );
-
- Console::Write( "Enter another integer value: " );
- addParams[ 1 ] = Convert::ToInt32( Console::ReadLine() );
-
- Console::WriteLine( "If either integer was > 100, an exception will be thrown." );
-
- Console::WriteLine( "---" );
- Console::WriteLine( " {0} + {1} = {2}", addParams[ 0 ], addParams[ 1 ], adderType->InvokeMember( "DoAdd", BindingFlags::InvokeMethod, nullptr, addIns, addParams ) );
-}
-
-/* This code produces output similar to the following:
-
-Enter an integer value: 24
-Enter another integer value: 101
-If either integer was > 100, an exception will be thrown.
----
-Caught System.OverflowException: Arithmetic operation resulted in an overflow.
- at Adder.DoAdd(Int32 , Int32 )
- 24 + 101 = -1
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.Label Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.Label Example/CPP/source.cpp
deleted file mode 100644
index 8b29b655e66..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.Label Example/CPP/source.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ BuildAdderType()
-{
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "AdderExceptionAsm";
- AssemblyBuilder^ myAsmBldr = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::Run );
- ModuleBuilder^ myModBldr = myAsmBldr->DefineDynamicModule( "AdderExceptionMod" );
- TypeBuilder^ myTypeBldr = myModBldr->DefineType( "Adder" );
- array^adderParams = {int::typeid,int::typeid};
-
- // This method will add two numbers which are 100 or less. If either of the
- // passed integer vales are greater than 100, it will return the value of -1.
- MethodBuilder^ adderBldr = myTypeBldr->DefineMethod( "DoAdd", static_cast(MethodAttributes::Public | MethodAttributes::Static), int::typeid, adderParams );
- ILGenerator^ adderIL = adderBldr->GetILGenerator();
-
- // In order to successfully branch, we need to create labels
- // representing the offset IL instruction block to branch to.
- // These labels, when the MarkLabel(Label) method is invoked,
- // will specify the IL instruction to branch to.
- Label failed = adderIL->DefineLabel();
- Label endOfMthd = adderIL->DefineLabel();
-
- // First, load argument 0 and the integer value of "100" onto the
- // stack. If arg0 > 100, branch to the label "failed", which is marked
- // as the address of the block that loads -1 onto the stack, bypassing
- // the addition.
- adderIL->Emit( OpCodes::Ldarg_0 );
- adderIL->Emit( OpCodes::Ldc_I4_S, 100 );
- adderIL->Emit( OpCodes::Bgt_S, failed );
-
- // Now, check to see if argument 1 was greater than 100. If it was,
- // branch to "failed." Otherwise, fall through and perform the addition,
- // branching unconditionally to the instruction at the label "endOfMthd".
- adderIL->Emit( OpCodes::Ldarg_1 );
- adderIL->Emit( OpCodes::Ldc_I4_S, 100 );
- adderIL->Emit( OpCodes::Bgt_S, failed );
- adderIL->Emit( OpCodes::Ldarg_0 );
- adderIL->Emit( OpCodes::Ldarg_1 );
- adderIL->Emit( OpCodes::Add_Ovf_Un );
- adderIL->Emit( OpCodes::Br_S, endOfMthd );
-
- // If this label is branched to (the failure case), load -1 onto the stack
- // and fall through to the return opcode.
- adderIL->MarkLabel( failed );
- adderIL->Emit( OpCodes::Ldc_I4_M1 );
-
- // The end of the method. If both values were less than 100, the
- // correct result will return. If one of the arguments was greater
- // than 100, the result will be -1.
- adderIL->MarkLabel( endOfMthd );
- adderIL->Emit( OpCodes::Ret );
- return myTypeBldr->CreateType();
-}
-
-int main()
-{
- Type^ adderType = BuildAdderType();
- Object^ addIns = Activator::CreateInstance( adderType );
- array^addParams = gcnew array(2);
- Console::Write( "Enter an integer value: " );
- addParams[ 0 ] = Convert::ToInt32( Console::ReadLine() );
- Console::Write( "Enter another integer value: " );
- addParams[ 1 ] = Convert::ToInt32( Console::ReadLine() );
- Console::WriteLine( "---" );
- int adderResult = safe_cast(adderType->InvokeMember( "DoAdd", BindingFlags::InvokeMethod, nullptr, addIns, addParams ));
- if ( adderResult != -1 )
- {
- Console::WriteLine( " {0} + {1} = {2}", addParams[ 0 ], addParams[ 1 ], adderResult );
- }
- else
- {
- Console::WriteLine( "One of the integers to add was greater than 100!" );
- }
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder Example/CPP/source.cpp
deleted file mode 100644
index 13c415b9f79..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder Example/CPP/source.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-void AddMethodDynamically( TypeBuilder^ myTypeBld,
- String^ mthdName,
- array^ mthdParams,
- Type^ returnType,
- String^ mthdAction )
-{
- MethodBuilder^ myMthdBld = myTypeBld->DefineMethod( mthdName, static_cast(MethodAttributes::Public | MethodAttributes::Static), returnType, mthdParams );
- ILGenerator^ ILOut = myMthdBld->GetILGenerator();
- int numParams = mthdParams->Length;
- for ( Byte x = 0; x < numParams; x++ )
- {
- ILOut->Emit( OpCodes::Ldarg_S, x );
-
- }
- if ( numParams > 1 )
- {
- for ( int y = 0; y < (numParams - 1); y++ )
- {
- if ( mthdAction->Equals( "A" ) )
- ILOut->Emit( OpCodes::Add );
- else
- if ( mthdAction->Equals( "M" ) )
- ILOut->Emit( OpCodes::Mul );
- else
- ILOut->Emit( OpCodes::Add );
-
- }
- }
-
- ILOut->Emit( OpCodes::Ret );
-};
-
-void main()
-{
- AppDomain^ myDomain = AppDomain::CurrentDomain;
- AssemblyName^ asmName = gcnew AssemblyName;
- asmName->Name = "MyDynamicAsm";
- AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( asmName,
- AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ myModule = myAsmBuilder->DefineDynamicModule( "MyDynamicAsm",
- "MyDynamicAsm.dll" );
- TypeBuilder^ myTypeBld = myModule->DefineType( "MyDynamicType",
- TypeAttributes::Public );
-
- // Get info from the user to build the method dynamically.
- Console::WriteLine( "Let's build a simple method dynamically!" );
- Console::WriteLine( "Please enter a few numbers, separated by spaces." );
- String^ inputNums = Console::ReadLine();
- Console::Write( "Do you want to [A]dd (default) or [M]ultiply these numbers? " );
- String^ myMthdAction = Console::ReadLine()->ToUpper();
- Console::Write( "Lastly, what do you want to name your new dynamic method? " );
- String^ myMthdName = Console::ReadLine();
-
- // Process inputNums into an array and create a corresponding Type array
- int index = 0;
- array^inputNumsList = inputNums->Split();
- array^myMthdParams = gcnew array(inputNumsList->Length);
- array^inputValsList = gcnew array(inputNumsList->Length);
- for each (String^ inputNum in inputNumsList)
- {
- inputValsList[ index ] = Convert::ToInt32( inputNum );
- myMthdParams[ index ] = int::typeid;
- index++;
- }
-
-
- // Now, call the method building method with the parameters, passing the
- // TypeBuilder by reference.
- AddMethodDynamically( myTypeBld,
- myMthdName,
- myMthdParams,
- int::typeid,
- myMthdAction );
- Type^ myType = myTypeBld->CreateType();
-
- Console::WriteLine( "---" );
- Console::WriteLine( "The result of {0} the inputted values is: {1}",
- ((myMthdAction->Equals( "M" )) ? "multiplying" : "adding"),
- myType->InvokeMember( myMthdName,
- BindingFlags::InvokeMethod | BindingFlags::Public | BindingFlags::Static,
- nullptr,
- nullptr,
- inputValsList ) );
- Console::WriteLine( "---" );
-
- // Let's take a look at the method we created.
- // If you are interested in seeing the MSIL generated dynamically for the method
- // your program generated, change to the directory where you ran the compiled
- // code sample and type "ildasm MyDynamicAsm.dll" at the prompt. When the list
- // of manifest contents appears, click on "MyDynamicType" and then on the name of
- // of the method you provided during execution.
-
- myAsmBuilder->Save( "MyDynamicAsm.dll" );
-
- MethodInfo^ myMthdInfo = myType->GetMethod( myMthdName );
- Console::WriteLine( "Your Dynamic Method: {0};", myMthdInfo );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.AddDeclarativeSecurity Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.AddDeclarativeSecurity Example/CPP/source.cpp
deleted file mode 100644
index e11b9039eea..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.AddDeclarativeSecurity Example/CPP/source.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-using namespace System;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-class MyMethodBuilderDemo
-{
-public:
- static void BuildDynMethod( ModuleBuilder^ myModBuilder )
- {
- //
- // myModBuilder is an instance of ModuleBuilder.
- // Note that for the use of PermissionSet and SecurityAction,
- // the namespaces System::Security and System::Security::Permissions
- // should be included.
-
- TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "MyType",
- TypeAttributes::Public );
-
- array^ temp0 = {int::typeid, int::typeid};
- MethodBuilder^ myMethod1 = myTypeBuilder->DefineMethod( "MyMethod",
- MethodAttributes::Public,
- int::typeid, temp0 );
-
- PermissionSet^ myMethodPermissions = gcnew PermissionSet(
- PermissionState::Unrestricted );
-
- myMethod1->AddDeclarativeSecurity( SecurityAction::Demand,
- myMethodPermissions );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.GetModule/CPP/source3.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.GetModule/CPP/source3.cpp
deleted file mode 100644
index b0197f9c238..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.GetModule/CPP/source3.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-class MoreMethodBuilderSnippets
-{
-public:
- static void ContainerMethod( AssemblyBuilder^ myAsmBuilder )
- {
-
- //
- ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MathFunctions" );
- TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "MyMathFunctions", TypeAttributes::Public );
- array^temp0 = {int::typeid,int::typeid};
- MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "Adder", MethodAttributes::Public, int::typeid, temp0 );
-
- // Create body via ILGenerator here ...
- Type^ myNewType = myTypeBuilder->CreateType();
- Module^ myModule = myMthdBuilder->GetModule();
- array^myModTypes = myModule->GetTypes();
- Console::WriteLine( "Module: {0}", myModule->Name );
- Console::WriteLine( "------- with path {0}", myModule->FullyQualifiedName );
- Console::WriteLine( "------- in assembly {0}", myModule->Assembly->FullName );
- System::Collections::IEnumerator^ myEnum = myModTypes->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Type^ myModType = safe_cast(myEnum->Current);
- Console::WriteLine( "------- has type {0}", myModType->FullName );
- }
- }
-
-};
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.GetParameters Example/CPP/source4.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.GetParameters Example/CPP/source4.cpp
deleted file mode 100644
index 8588434c8e6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.GetParameters Example/CPP/source4.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-class MoreMethodBuilderSnippets
-{
-public:
- static void ContainerMethod( ModuleBuilder^ myModBuilder )
- {
- //
- TypeBuilder^ myType1 = myModBuilder->DefineType( "MyMathFunctions", TypeAttributes::Public );
- array^temp0 = {Type::GetType( "System.Int32&" ),int::typeid};
- MethodBuilder^ myMthdBuilder = myType1->DefineMethod( "AddToRefValue", MethodAttributes::Public, void::typeid, temp0 );
- ParameterBuilder^ myParam1 = myMthdBuilder->DefineParameter( 1, ParameterAttributes::Out, "thePool" );
- ParameterBuilder^ myParam2 = myMthdBuilder->DefineParameter( 2, ParameterAttributes::In, "addMeToPool" );
-
- // Create body via ILGenerator here, and complete the type.
- array^myParams = myMthdBuilder->GetParameters();
- Console::WriteLine( "Method: {0}", myMthdBuilder->Name );
-
- for each (ParameterInfo^ myParam in myParams)
- {
- Console::WriteLine("------- Parameter: {0} {1} at pos {2}, with attribute {3}",
- myParam->ParameterType, myParam->Name, myParam->Position,
- myParam->Attributes.ToString());
- }
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetImplementationFlags Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetImplementationFlags Example/CPP/source.cpp
deleted file mode 100644
index 3f7e32af646..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetImplementationFlags Example/CPP/source.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-class MethodBuilderAssortedMembersDemo
-{
-public:
- static void MemberSnippets( TypeBuilder^ myTypeBuilder )
- {
- //
- array^ temp0 = { int::typeid, int::typeid };
- MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "MyMethod",
- MethodAttributes::Public,
- CallingConventions::HasThis,
- int::typeid,
- temp0 );
-
- // Specifies that the dynamic method declared above has a an MSIL implementation,
- // is managed, synchronized (single-threaded) through the body, and that it
- // cannot be inlined.
-
- myMthdBuilder->SetImplementationFlags( (MethodImplAttributes)(
- MethodImplAttributes::IL |
- MethodImplAttributes::Managed |
- MethodImplAttributes::Synchronized |
- MethodImplAttributes::NoInlining) );
-
- // Create an ILGenerator for the MethodBuilder and emit MSIL here ...
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetMarshal Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetMarshal Example/CPP/source.cpp
deleted file mode 100644
index 43dd7762fff..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetMarshal Example/CPP/source.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-class VariousMethodBuilderSnippets
-{
-public:
- static void ContainerMethod( TypeBuilder^ myDynamicType )
- {
- //
- array^ temp0 = { String::typeid };
- MethodBuilder^ myMethod = myDynamicType->DefineMethod( "MyMethodReturnsMarshal",
- MethodAttributes::Public,
- UInt32::typeid,
- temp0 );
-
- // We want the return value of our dynamic method to be marshalled as
- // an 64-bit (8-Byte) signed integer, instead of the default 32-bit
- // unsigned int as specified above. The UnmanagedMarshal class can perform
- // the type conversion.
-
- UnmanagedMarshal^ marshalMeAsI8 = UnmanagedMarshal::DefineUnmanagedMarshal(
- System::Runtime::InteropServices::UnmanagedType::I8 );
-
- myMethod->SetMarshal( marshalMeAsI8 );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetSymCustomAttribute Example/CPP/source2.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetSymCustomAttribute Example/CPP/source2.cpp
deleted file mode 100644
index f2b05b30c44..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.MethodBuilder.SetSymCustomAttribute Example/CPP/source2.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-class VariousMethodBuilderSnippets
-{
-public:
- static void ContainerMethod( TypeBuilder^ myDynamicType )
- {
- //
- array^ temp0 = { String::typeid };
- MethodBuilder^ myMethod = myDynamicType->DefineMethod( "MyMethod",
- MethodAttributes::Public,
- int::typeid,
- temp0 );
-
- // A 128-bit key in hex form, represented as a Byte array.
- array^ keyVal = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xFF, 0xFF};
-
- System::Text::ASCIIEncoding^ encoder = gcnew System::Text::ASCIIEncoding;
- array^ symFullName = encoder->GetBytes( "My Dynamic Method" );
-
- myMethod->SetSymCustomAttribute( "SymID", keyVal );
- myMethod->SetSymCustomAttribute( "SymFullName", symFullName );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.OpCodes.TakesSingleByteArgument Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.OpCodes.TakesSingleByteArgument Example/CPP/source.cpp
deleted file mode 100644
index 2f0d3457db5..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.OpCodes.TakesSingleByteArgument Example/CPP/source.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-//
-int main()
-{
-
- // We need a blank OpCode Object for reference when calling FieldInfo::GetValue().
- OpCode blankOpCode;
- Type^ myOpCodesType = Type::GetType( "System.Reflection.Emit.OpCodes" );
- array^listOfOpCodes = myOpCodesType->GetFields();
- Console::WriteLine( "Which OpCodes take single-Byte arguments?" );
- Console::WriteLine( "-----------------------------------------" );
-
- // Now, let's reflect on each FieldInfo and create an instance of the OpCode it represents.
- System::Collections::IEnumerator^ myEnum = listOfOpCodes->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- FieldInfo^ opCodeFI = safe_cast(myEnum->Current);
- Object^ theOpCode = opCodeFI->GetValue( blankOpCode );
- Console::WriteLine( " {0}: {1}", opCodeFI->Name, OpCodes::TakesSingleByteArgument( *dynamic_cast(theOpCode) ) );
- }
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ParameterBuilder Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ParameterBuilder Example/CPP/source.cpp
deleted file mode 100644
index 7039d6968a8..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.ParameterBuilder Example/CPP/source.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ BuildCustomerDataType()
-{
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
- AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::Run );
- ModuleBuilder^ myModBuilder = myAsmBuilder->DefineDynamicModule( "MyMod" );
- TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "CustomerData", TypeAttributes::Public );
- FieldBuilder^ customerNameBldr = myTypeBuilder->DefineField( "customerName", String::typeid, FieldAttributes::Private );
- FieldBuilder^ acctIDBldr = myTypeBuilder->DefineField( "acctID", String::typeid, FieldAttributes::Private );
- FieldBuilder^ balanceAmtBldr = myTypeBuilder->DefineField( "balanceAmt", double::typeid, FieldAttributes::Private );
- array^temp0 = {String::typeid,String::typeid,double::typeid};
- ConstructorBuilder^ myCtorBuilder = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::HasThis, temp0 );
- ILGenerator^ ctorIL = myCtorBuilder->GetILGenerator();
- Type^ objType = Type::GetType( "System.Object" );
- ConstructorInfo^ objCtor = objType->GetConstructor( gcnew array(0) );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Call, objCtor );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_1 );
- ctorIL->Emit( OpCodes::Stfld, customerNameBldr );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_2 );
- ctorIL->Emit( OpCodes::Stfld, acctIDBldr );
- ctorIL->Emit( OpCodes::Ldarg_0 );
- ctorIL->Emit( OpCodes::Ldarg_3 );
- ctorIL->Emit( OpCodes::Stfld, balanceAmtBldr );
- ctorIL->Emit( OpCodes::Ret );
-
- // This method will take an amount from a static pool and add it to the balance.
- // Note that we are passing the first parameter, fundsPool, by reference. Therefore,
- // we need to inform the MethodBuilder to expect a ref, by declaring the first
- // parameter's type to be System::Double& (a reference to a double).
- array^temp4 = {Type::GetType( "System.Double&" ),double::typeid};
- MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "AddFundsFromPool", MethodAttributes::Public, double::typeid, temp4 );
- ParameterBuilder^ poolRefBuilder = myMthdBuilder->DefineParameter( 1, ParameterAttributes::Out, "fundsPool" );
- ParameterBuilder^ amountFromPoolBuilder = myMthdBuilder->DefineParameter( 2, ParameterAttributes::In, "amountFromPool" );
- ILGenerator^ mthdIL = myMthdBuilder->GetILGenerator();
- mthdIL->Emit( OpCodes::Ldarg_1 );
- mthdIL->Emit( OpCodes::Ldarg_1 );
- mthdIL->Emit( OpCodes::Ldind_R8 );
- mthdIL->Emit( OpCodes::Ldarg_2 );
- mthdIL->Emit( OpCodes::Sub );
- mthdIL->Emit( OpCodes::Stind_R8 );
- mthdIL->Emit( OpCodes::Ldarg_0 );
- mthdIL->Emit( OpCodes::Ldarg_0 );
- mthdIL->Emit( OpCodes::Ldfld, balanceAmtBldr );
- mthdIL->Emit( OpCodes::Ldarg_2 );
- mthdIL->Emit( OpCodes::Add );
- mthdIL->Emit( OpCodes::Stfld, balanceAmtBldr );
- mthdIL->Emit( OpCodes::Ldarg_0 );
- mthdIL->Emit( OpCodes::Ldfld, balanceAmtBldr );
- mthdIL->Emit( OpCodes::Ret );
- return myTypeBuilder->CreateType();
-}
-
-int main()
-{
- Type^ custType = nullptr;
- Object^ custObj = nullptr;
- array^custArgTypes = {String::typeid,String::typeid,double::typeid};
-
- // Call the method to build our dynamic class.
- custType = BuildCustomerDataType();
- Console::WriteLine( "---" );
- ConstructorInfo^ myCustCtor = custType->GetConstructor( custArgTypes );
- double initialBalance = 100.00;
- array^temp5 = {"Joe Consumer","5678-XYZ",initialBalance};
- custObj = myCustCtor->Invoke( temp5 );
- array^myMemberInfo = custType->GetMember( "AddFundsFromPool" );
- double thePool = 1000.00;
- Console::WriteLine( "The pool is currently ${0}", thePool );
- Console::WriteLine( "The original balance of the account instance is ${0}", initialBalance );
- double amountFromPool = 50.00;
- Console::WriteLine( "The amount to be subtracted from the pool and added to the account is ${0}", amountFromPool );
- Console::WriteLine( "---" );
- Console::WriteLine( "Calling {0} ...", myMemberInfo[ 0 ] );
- Console::WriteLine( "---" );
- array^passMe = {thePool,amountFromPool};
- Console::WriteLine( "The new balance in the account instance is ${0}", custType->InvokeMember( "AddFundsFromPool", BindingFlags::InvokeMethod, nullptr, custObj, passMe ) );
- thePool = safe_cast(passMe[ 0 ]);
- Console::WriteLine( "The new amount in the pool is ${0}", thePool );
-}
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.PropertyBuilder Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.PropertyBuilder Example/CPP/source.cpp
deleted file mode 100644
index 8f782758f2a..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.PropertyBuilder Example/CPP/source.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Threading;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-Type^ BuildDynamicTypeWithProperties()
-{
- AppDomain^ myDomain = Thread::GetDomain();
- AssemblyName^ myAsmName = gcnew AssemblyName;
- myAsmName->Name = "MyDynamicAssembly";
-
- // To generate a persistable assembly, specify AssemblyBuilderAccess::RunAndSave.
- AssemblyBuilder^ myAsmBuilder =
- myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
-
- // Generate a persistable single-module assembly.
- ModuleBuilder^ myModBuilder =
- myAsmBuilder->DefineDynamicModule( myAsmName->Name, myAsmName->Name + ".dll" );
- TypeBuilder^ myTypeBuilder = myModBuilder->DefineType( "CustomerData", TypeAttributes::Public );
-
- // Define a private field to hold the property value.
- FieldBuilder^ customerNameBldr = myTypeBuilder->DefineField( "customerName", String::typeid, FieldAttributes::Private );
-
- // The last argument of DefineProperty is an empty array of Type
- // objects, because the property has no parameters. (Alternatively,
- // you can specify a null value.)
- PropertyBuilder^ custNamePropBldr =
- myTypeBuilder->DefineProperty( "CustomerName", PropertyAttributes::HasDefault, String::typeid, gcnew array(0) );
-
- // The property set and property get methods require a special
- // set of attributes.
- MethodAttributes getSetAttr =
- MethodAttributes::Public | MethodAttributes::SpecialName |
- MethodAttributes::HideBySig;
-
- // Define the "get" accessor method for CustomerName.
- MethodBuilder^ custNameGetPropMthdBldr =
- myTypeBuilder->DefineMethod( "get_CustomerName",
- getSetAttr,
- String::typeid,
- Type::EmptyTypes );
-
- ILGenerator^ custNameGetIL = custNameGetPropMthdBldr->GetILGenerator();
- custNameGetIL->Emit( OpCodes::Ldarg_0 );
- custNameGetIL->Emit( OpCodes::Ldfld, customerNameBldr );
- custNameGetIL->Emit( OpCodes::Ret );
-
- // Define the "set" accessor method for CustomerName.
- array^temp2 = {String::typeid};
- MethodBuilder^ custNameSetPropMthdBldr =
- myTypeBuilder->DefineMethod( "set_CustomerName",
- getSetAttr,
- nullptr,
- temp2 );
-
- ILGenerator^ custNameSetIL = custNameSetPropMthdBldr->GetILGenerator();
- custNameSetIL->Emit( OpCodes::Ldarg_0 );
- custNameSetIL->Emit( OpCodes::Ldarg_1 );
- custNameSetIL->Emit( OpCodes::Stfld, customerNameBldr );
- custNameSetIL->Emit( OpCodes::Ret );
-
- // Last, we must map the two methods created above to our PropertyBuilder to
- // their corresponding behaviors, "get" and "set" respectively.
- custNamePropBldr->SetGetMethod( custNameGetPropMthdBldr );
- custNamePropBldr->SetSetMethod( custNameSetPropMthdBldr );
-
- Type^ retval = myTypeBuilder->CreateType();
-
- // Save the assembly so it can be examined with Ildasm.exe,
- // or referenced by a test program.
- myAsmBuilder->Save(myAsmName->Name + ".dll");
- return retval;
-}
-
-int main()
-{
- Type^ custDataType = BuildDynamicTypeWithProperties();
- array^custDataPropInfo = custDataType->GetProperties();
- System::Collections::IEnumerator^ myEnum = custDataPropInfo->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- PropertyInfo^ pInfo = safe_cast(myEnum->Current);
- Console::WriteLine( "Property '{0}' created!", pInfo );
- }
-
- Console::WriteLine( "---" );
-
- // Note that when invoking a property, you need to use the proper BindingFlags -
- // BindingFlags::SetProperty when you invoke the "set" behavior, and
- // BindingFlags::GetProperty when you invoke the "get" behavior. Also note that
- // we invoke them based on the name we gave the property, as expected, and not
- // the name of the methods we bound to the specific property behaviors.
- Object^ custData = Activator::CreateInstance( custDataType );
- array^temp3 = {"Joe User"};
- custDataType->InvokeMember( "CustomerName", BindingFlags::SetProperty, nullptr, custData, temp3 );
- Console::WriteLine( "The customerName field of instance custData has been set to '{0}'.", custDataType->InvokeMember( "CustomerName", BindingFlags::GetProperty, nullptr, custData, gcnew array(0) ) );
-}
-
-// --- O U T P U T ---
-// The output should be as follows:
-// -------------------
-// Property 'System.String CustomerName' created!
-// ---
-// The customerName field of instance custData has been set to 'Joe User'.
-// -------------------
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.TypeBuilder.CreateType Example/CPP/nestedenum.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.TypeBuilder.CreateType Example/CPP/nestedenum.cpp
deleted file mode 100644
index bfeecb340d6..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Emit.TypeBuilder.CreateType Example/CPP/nestedenum.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-using namespace System::Threading;
-using namespace System::Text;
-using namespace System::Resources;
-using namespace System::Collections;
-using namespace System::IO;
-
-// Helper class called when a resolve type event is raised.
-ref class TypeResolveHandler
-{
-private:
- Module^ m_Module;
-
-public:
- TypeResolveHandler( Module^ mod )
- {
- m_Module = mod;
- }
-
- Assembly^ ResolveEvent( Object^ sender, ResolveEventArgs^ args );
-};
-
-ref class NestedEnum
-{
-internal:
- static TypeBuilder^ enumType = nullptr;
- static Type^ tNested = nullptr;
- static Type^ tNesting = nullptr;
-
-public:
- static void Main()
- {
- AssemblyName^ asmName = gcnew AssemblyName;
- asmName->Name = "NestedEnum";
- AssemblyBuilder^ asmBuild = Thread::GetDomain()->DefineDynamicAssembly( asmName, AssemblyBuilderAccess::RunAndSave );
- ModuleBuilder^ modBuild = asmBuild->DefineDynamicModule( "ModuleOne", "NestedEnum.dll" );
-
- // Hook up the event listening.
- TypeResolveHandler^ typeResolveHandler = gcnew TypeResolveHandler( modBuild );
-
- // Add a listener for the type resolve events.
- AppDomain^ currentDomain = Thread::GetDomain();
- ResolveEventHandler^ resolveHandler = gcnew ResolveEventHandler( typeResolveHandler, &TypeResolveHandler::ResolveEvent );
- currentDomain->TypeResolve += resolveHandler;
- TypeBuilder^ tb = modBuild->DefineType( "AType", TypeAttributes::Public );
- TypeBuilder^ eb = tb->DefineNestedType( "AnEnum", static_cast(TypeAttributes::NestedPublic | TypeAttributes::Sealed), Enum::typeid, 0 );
- eb->DefineField( "value__", int::typeid, static_cast(FieldAttributes::Private | FieldAttributes::SpecialName) );
- FieldBuilder^ fb = eb->DefineField( "Field1", eb, static_cast(FieldAttributes::Public | FieldAttributes::Literal | FieldAttributes::Static) );
- fb->SetConstant( 1 );
- enumType = eb;
-
- // Comment out this field.
- // When this field is defined, the loader cannot determine the size
- // of the type. Therefore, a TypeResolve event is generated when the
- // nested type is completed.
- tb->DefineField( "Field2", eb, FieldAttributes::Public );
- tNesting = tb->CreateType();
- if ( tNesting == nullptr )
- Console::WriteLine( "NestingType CreateType failed but didn't throw!" );
-
- try
- {
- tNested = eb->CreateType();
- if ( tNested == nullptr )
- Console::WriteLine( "NestedType CreateType failed but didn't throw!" );
- }
- catch ( Exception^ )
- {
-
- // This is needed because you might have already completed the type in the TypeResolve event.
- }
-
- if ( tNested != nullptr )
- {
- Type^ x = tNested->DeclaringType;
- if ( x == nullptr )
- Console::WriteLine( "Declaring type is null." );
- else
- Console::WriteLine( x->Name );
- }
-
- asmBuild->Save( "NestedEnum.dll" );
-
- // Remove the listener for the type resolve events.
- currentDomain->TypeResolve -= resolveHandler;
- }
-
-};
-
-Assembly^ TypeResolveHandler::ResolveEvent( Object^ sender, ResolveEventArgs^ args )
-{
- Console::WriteLine( args->Name );
-
- // Use args.Name to look up the type name. In this case, you are getting AnEnum.
- try
- {
- NestedEnum::tNested = NestedEnum::enumType->CreateType();
- }
- catch ( Exception^ )
- {
-
- // This is needed to throw away InvalidOperationException.
- // Loader might send the TypeResolve event more than once
- // and the type might be complete already.
- }
-
-
- // Complete the type.
- return m_Module->Assembly;
-}
-
-int main()
-{
- NestedEnum::Main();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.MemberInfo.Module/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.MemberInfo.Module/cpp/source.cpp
deleted file mode 100644
index 8f8a66f0c27..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.MemberInfo.Module/cpp/source.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-public ref class Test
-{
-public:
- virtual String^ ToString() override
- {
- return "An instance of class Test!";
- }
-};
-
-int main()
-{
- Test^ target = gcnew Test();
- MethodInfo^ toStringInfo = target->GetType()->GetMethod("ToString");
- Console::WriteLine("{0} is defined in {1}", toStringInfo->Name,
- toStringInfo->Module->Name);
-
- MethodInfo^ getHashCodeInfo = target->GetType()->GetMethod("GetHashCode");
- Console::WriteLine("{0} is defined in {1}", getHashCodeInfo->Name,
- getHashCodeInfo->Module->Name);
-}
-
-/*
-* This example produces the following console output:
-*
-* ToString is defined in source.exe
-* GetHashCode is defined in mscorlib.dll
-*/
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.MethodBase.IsHideBySig/cpp/hide.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.MethodBase.IsHideBySig/cpp/hide.cpp
deleted file mode 100644
index 2ba285b7284..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.MethodBase.IsHideBySig/cpp/hide.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-// The base class Parent contains an overloaded method PrintCall.
-//
-public ref class Parent
-{
-public:
- virtual void PrintCall()
- {
- Console::WriteLine("Parent's PrintCall()");
- }
-public:
- virtual void PrintCall(int x)
- {
- Console::WriteLine("Parent's PrintCall({0})", x);
- }
-};
-
-// The derived class Child hides one overload of the inherited
-// method PrintCall.
-//
-public ref class Child : public Parent
-{
-public:
- void PrintCall(int i) new
- {
- Console::WriteLine("Child's PrintCall({0})", i);
- }
-};
-
-int main()
-{
- Child^ childInstance = gcnew Child();
-
- // In C#, the method in the derived class hides by name and by
- // signature, so the overload in the derived class hides only one
- // of the overloads in the base class.
- //
- Console::WriteLine("------ List the overloads of PrintCall in the " +
- "derived class Child ------");
- Type^ t = childInstance->GetType();
- for each(MethodInfo^ minfo in t->GetMethods())
- {
- if (minfo->Name == "PrintCall")
- {
- Console::WriteLine("Overload of PrintCall: {0}" +
- " IsHideBySig = {1}, DeclaringType = {2}",
- minfo, minfo->IsHideBySig, minfo->DeclaringType);
- }
- }
-
- // The method PrintCall in the derived class hides one overload of the
- // method in Parent. Contrast this with Visual Basic, which hides by
- // name instead of by name and signature. In Visual Basic, the
- // parameterless overload of PrintCall would be unavailable from Child.
- //
- Console::WriteLine(
- "------ Call the overloads of PrintCall available in Child ------");
- childInstance->PrintCall();
- childInstance->PrintCall(42);
-
- // If Child is cast to the base type Parent, both overloads of the
- // shadowed method can be called.
- //
- Console::WriteLine(
- "------ Call the shadowed overloads of PrintCall ------");
- Parent^ parentInstance = childInstance;
- parentInstance->PrintCall();
- parentInstance->PrintCall(42);
-}
-
-/* This code example produces the following output:
-
------- List the overloads of PrintCall in the derived class Child ------
-Overload of PrintCall: Void PrintCall(Int32) IsHideBySig = True, DeclaringType = Child
-Overload of PrintCall: Void PrintCall() IsHideBySig = True, DeclaringType = Parent
-Overload of PrintCall: Void PrintCall(Int32) IsHideBySig = True, DeclaringType = Parent
------- Call the overloads of PrintCall available in Child ------
-Parent's PrintCall()
-Child's PrintCall(42)
------- Call the shadowed overloads of PrintCall ------
-Parent's PrintCall()
-Parent's PrintCall(42)
-
-*/
-
-//
-
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.Assembly Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.Assembly Example/CPP/class1.cpp
deleted file mode 100644
index 2fca1e3a971..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.Assembly Example/CPP/class1.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- array^moduleArray;
- moduleArray = Assembly::GetExecutingAssembly()->GetModules( false );
-
- // In a simple project with only one module, the module at index
- // 0 will be the module containing this class.
- Module^ myModule = moduleArray[ 0 ];
- Assembly^ myAssembly = myModule->Assembly;
- Console::WriteLine( "myModule.Assembly = {0}.", myAssembly->FullName );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FilterTypeName Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FilterTypeName Example/CPP/class1.cpp
deleted file mode 100644
index 82159ee05f7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FilterTypeName Example/CPP/class1.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Collections;
-public ref class MySecondClass{};
-
-
-// This class does not fit the filter criterion My*.
-public ref class YourClass{};
-
-int main()
-{
- array^moduleArray;
- moduleArray = Assembly::GetExecutingAssembly()->GetModules( false );
-
- // In a simple project with only one module, the module at index
- // 0 will be the module containing these classes.
- Module^ myModule = moduleArray[ 0 ];
- array^tArray;
- tArray = myModule->FindTypes( Module::FilterTypeName, "My*" );
- IEnumerator^ myEnum = tArray->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Type^ t = safe_cast(myEnum->Current);
- Console::WriteLine( "Found a module beginning with My*: {0}.", t->Name );
- }
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FilterTypeNameIgnoreCase Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FilterTypeNameIgnoreCase Example/CPP/class1.cpp
deleted file mode 100644
index 3aa584f6d2c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FilterTypeNameIgnoreCase Example/CPP/class1.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Collections;
-public ref class MyMainClass{};
-
-public ref class MySecondClass{};
-
-
-// This class does not fit the filter criteria my*.
-public ref class YourClass{};
-
-int main()
-{
- array^moduleArray;
- moduleArray = Assembly::GetExecutingAssembly()->GetModules( false );
-
- // In a simple project with only one module, the module at index
- // 0 will be the module containing these classes.
- Module^ myModule = moduleArray[ 0 ];
- array^tArray;
- tArray = myModule->FindTypes( Module::FilterTypeNameIgnoreCase, "my*" );
- IEnumerator^ myEnum = tArray->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Type^ t = safe_cast(myEnum->Current);
- Console::WriteLine( "Found a module beginning with my*: {0}", t->Name );
- }
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FullyQualifiedName/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FullyQualifiedName/CPP/class1.cpp
deleted file mode 100644
index 68633196a7c..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.FullyQualifiedName/CPP/class1.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- array^moduleArray;
- moduleArray = Assembly::GetExecutingAssembly()->GetModules( false );
-
- // In a simple project with only one module, the module at index
- // 0 will be the module containing this class.
- Module^ myModule = moduleArray[ 0 ];
- Console::WriteLine( "myModule.FullyQualifiedName = {0}", myModule->FullyQualifiedName );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetCustomAttributes 1Arg Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetCustomAttributes 1Arg Example/CPP/class1.cpp
deleted file mode 100644
index 38137adc219..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetCustomAttributes 1Arg Example/CPP/class1.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Collections;
-
-namespace ReflectionModule_Examples
-{
-
- //Define a module-level attribute.
- //A very simple custom attribute.
-
- [AttributeUsage(AttributeTargets::Class|AttributeTargets::Module)]
- public ref class MySimpleAttribute: public Attribute
- {
- private:
- String^ name;
-
- public:
- MySimpleAttribute( String^ newName )
- {
- name = newName;
- }
-
- };
-
-
- [module:MySimpleAttribute("module-level")];
- ref class MyMainClass{};
-
-}
-
-int main()
-{
- array^moduleArray;
- moduleArray = ReflectionModule_Examples::MySimpleAttribute::typeid->Assembly->GetModules( false );
-
- // In a simple project with only one module, the module at index
- // 0 will be the module containing these classes.
- System::Reflection::Module^ myModule = moduleArray[ 0 ];
- array^attributes;
- attributes = myModule->GetCustomAttributes( true );
- IEnumerator^ myEnum = attributes->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Object^ o = safe_cast(myEnum->Current);
- Console::WriteLine( "Found this attribute on myModule: {0}.", o );
- }
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetCustomAttributes 2Arg Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetCustomAttributes 2Arg Example/CPP/class1.cpp
deleted file mode 100644
index 3cf8509d34b..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetCustomAttributes 2Arg Example/CPP/class1.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Collections;
-
-namespace ReflectionModule_Examples
-{
-
- // Define a very simple custom attribute
-
- [AttributeUsage(AttributeTargets::Class|AttributeTargets::Module)]
- public ref class MySimpleAttribute: public Attribute
- {
- private:
- String^ name;
-
- public:
- MySimpleAttribute( String^ newName )
- {
- name = newName;
- }
-
- };
-
-}
-
-
-//Define a module-level attribute.
-
-[module:ReflectionModule_Examples::MySimpleAttribute("module-level")];
-int main()
-{
- array^moduleArray;
- moduleArray = ReflectionModule_Examples::MySimpleAttribute::typeid->Assembly->GetModules( false );
-
- // In a simple project with only one module, the module at index
- // 0 will be the module containing these classes.
- System::Reflection::Module^ myModule = moduleArray[ 0 ];
- array^attributes;
-
- //Get only MySimpleAttribute attributes for this module.
- attributes = myModule->GetCustomAttributes( myModule->GetType( "ReflectionModule_Examples.MySimpleAttribute", false, false ), true );
- IEnumerator^ myEnum = attributes->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- Object^ o = safe_cast(myEnum->Current);
- Console::WriteLine( "Found this attribute on myModule: {0}", o );
- }
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 1Arg Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 1Arg Example/CPP/class1.cpp
deleted file mode 100644
index e7972909d1e..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 1Arg Example/CPP/class1.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-namespace ReflectionModule_Examples
-{
- public ref class MyMainClass{};
-
-}
-
-int main()
-{
- array^moduleArray;
- moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->GetModules( false );
-
- //In a simple project with only one module, the module at index
- // 0 will be the module containing these classes.
- Module^ myModule = moduleArray[ 0 ];
- Type^ myType;
- myType = myModule->GetType( "ReflectionModule_Examples.MyMainClass" );
- Console::WriteLine( "Got type: {0}", myType );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 2Arg Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 2Arg Example/CPP/class1.cpp
deleted file mode 100644
index 7c898abb0c9..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 2Arg Example/CPP/class1.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-namespace ReflectionModule_Examples
-{
- public ref class MyMainClass{};
-
-}
-
-int main()
-{
- array^moduleArray;
- moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->GetModules( false );
-
- //In a simple project with only one module, the module at index
- // 0 will be the module containing these classes.
- Module^ myModule = moduleArray[ 0 ];
- Type^ myType;
- myType = myModule->GetType( "ReflectionModule_Examples.MyMainClass", false );
- Console::WriteLine( "Got type: {0}", myType );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 3Arg Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 3Arg Example/CPP/class1.cpp
deleted file mode 100644
index 3759068bbe0..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.GetType 3Arg Example/CPP/class1.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-namespace ReflectionModule_Examples
-{
- public ref class MyMainClass{};
-
-}
-
-int main()
-{
- array^moduleArray;
- moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->GetModules( false );
-
- //In a simple project with only one module, the module at index
- // 0 will be the module containing this class.
- Module^ myModule = moduleArray[ 0 ];
- Type^ myType;
- myType = myModule->GetType( "ReflectionModule_Examples.MyMainClass", false, false );
- Console::WriteLine( "Got type: {0}", myType );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.IsDefined Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.IsDefined Example/CPP/class1.cpp
deleted file mode 100644
index 651c5025f0d..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.IsDefined Example/CPP/class1.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-
-namespace ReflectionModule_Examples
-{
-
- //A very simple custom attribute.
-
- [AttributeUsage(AttributeTargets::Class|AttributeTargets::Module)]
- public ref class MySimpleAttribute: public Attribute
- {
- private:
- String^ name;
-
- public:
- MySimpleAttribute( String^ newName )
- {
- name = newName;
- }
-
- };
-
-}
-
-
-//Define a module-level attribute.
-
-[module:ReflectionModule_Examples::MySimpleAttribute("module-level")];
-int main()
-{
- array^moduleArray;
- moduleArray = ReflectionModule_Examples::MySimpleAttribute::typeid->Assembly->GetModules( false );
-
- //In a simple project with only one module, the module at index
- // 0 will be the module containing these classes.
- System::Reflection::Module^ myModule = moduleArray[ 0 ];
- Type^ myType;
- myType = myModule->GetType( "ReflectionModule_Examples.MySimpleAttribute" );
- Console::WriteLine( "IsDefined(MySimpleAttribute) = {0}", myModule->IsDefined( myType, false ) );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.IsResource Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.IsResource Example/CPP/class1.cpp
deleted file mode 100644
index 41922a945e4..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.IsResource Example/CPP/class1.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- array^moduleArray;
- moduleArray = Assembly::GetExecutingAssembly()->GetModules( false );
-
- //In a simple project with only one module, the module at index
- // 0 will be the module containing this class.
- Module^ myModule = moduleArray[ 0 ];
- Console::WriteLine( "myModule->IsResource() = {0}", myModule->IsResource() );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.ToString Example/CPP/class1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.ToString Example/CPP/class1.cpp
deleted file mode 100644
index bd17af9afb2..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Reflection.Module.ToString Example/CPP/class1.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-
-//
-using namespace System;
-using namespace System::Reflection;
-int main()
-{
- array^moduleArray;
- moduleArray = Assembly::GetExecutingAssembly()->GetModules( false );
-
- //In a simple project with only one module, the module at index
- // 0 will be the module containing this class.
- Module^ myModule = moduleArray[ 0 ];
- Console::WriteLine( "myModule->ToString returns: {0}", myModule );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.Type.GetGenericParameterConstraints/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.Type.GetGenericParameterConstraints/CPP/source.cpp
deleted file mode 100644
index 8720dbc53fd..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.Type.GetGenericParameterConstraints/CPP/source.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-//
-using namespace System;
-using namespace System::Collections;
-using namespace System::Reflection;
-
-// Define a sample interface to use as an interface constraint.
-interface class ITest{};
-
-// Define a base type to use as a class constraint.
-public ref class Base{};
-
-// Define the generic type to examine. The first generic type parameter,
-// T, derives from the class Base and implements ITest. This demonstrates
-// a base class constraint and an interface constraint. In the .NET
-// Framework version 2.0, C++ has no way of expressing special constraints.
-// See the C# example code.
-//
-generic
- where T : Base, ITest
-ref class Test {};
-
-// Define a type that derives from Base and implements interface
-// ITest. This type satisfies the constraint on T in class Test.
-public ref class Derived: public Base, public ITest {};
-
-public ref class Example
-{
-public:
- static void Main()
- {
- // Create a constructed type from Test, and from it
- // get the generic type definition.
- //
- Type^ def = Test::typeid;
- Console::WriteLine( L"\r\nExamining generic type {0}", def );
-
- // Get the type parameters of the generic type definition,
- // and display them.
- //
- for each (Type^ tp in def->GetGenericArguments())
- {
- Console::WriteLine( L"\r\nType parameter: {0}", tp);
- Console::WriteLine( L"\t{0}",
- ListGenericParameterAttributes( tp ) );
-
- // List the base class and interface constraints. The
- // constraints do not appear in any particular order. If
- // there are no class or interface constraints, an empty
- // array is returned.
- //
- for each (Type^ constraint in tp->GetGenericParameterConstraints())
- {
- Console::WriteLine( L"\t{0}", constraint );
- }
- }
- }
-
-private:
-
- // List the variance and special constraint flags.
- //
- static String^ ListGenericParameterAttributes( Type^ t )
- {
- String^ retval;
- GenericParameterAttributes gpa = t->GenericParameterAttributes;
-
- // Select the variance flag.
- GenericParameterAttributes variance =
- static_cast(
- gpa & GenericParameterAttributes::VarianceMask );
-
- if ( variance == GenericParameterAttributes::None )
- retval = L"No variance flag;";
- else
- {
- if ( (variance & GenericParameterAttributes::Covariant) !=
- GenericParameterAttributes::None )
- retval = L"Covariant;";
- else
- retval = L"Contravariant;";
- }
-
- // Select the special constraint flags.
- GenericParameterAttributes constraints =
- static_cast(
- gpa & GenericParameterAttributes::SpecialConstraintMask);
-
- if ( constraints == GenericParameterAttributes::None )
- retval = String::Concat( retval, L" No special constraints" );
- else
- {
- if ( (constraints & GenericParameterAttributes::ReferenceTypeConstraint) !=
- GenericParameterAttributes::None )
- retval = String::Concat( retval, L" ReferenceTypeConstraint" );
-
- if ( (constraints & GenericParameterAttributes::NotNullableValueTypeConstraint) !=
- GenericParameterAttributes::None )
- retval = String::Concat( retval, L" NotNullableValueTypeConstraint" );
-
- if ( (constraints & GenericParameterAttributes::DefaultConstructorConstraint) !=
- GenericParameterAttributes::None )
- retval = String::Concat( retval, L" DefaultConstructorConstraint" );
- }
-
- return retval;
- }
-};
-
-int main()
-{
- Example::Main();
-}
-
-/* This example produces the following output:
-
-Examining generic type Test`2[T,U]
-
-Type parameter: T
- No variance flag; No special constraints
- Base
- ITest
-
-Type parameter: U
- No variance flag; No special constraints
- */
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codeattributeargument/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codeattributeargument/cpp/source.cpp
deleted file mode 100644
index 2b795397fac..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codeattributeargument/cpp/source.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-#using
-#using
-
-using namespace System;
-using namespace System::CodeDom;
-using namespace System::CodeDom::Compiler;
-
-int main()
-{
- // Declare a new type called Class1.
- CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration("Class1");
-
- // Use attributes to mark the class as serializable and obsolete.
- CodeAttributeDeclaration^ codeAttrDecl =
- gcnew CodeAttributeDeclaration("System.Serializable");
- class1->CustomAttributes->Add(codeAttrDecl);
-
- CodeAttributeArgument^ codeAttr =
- gcnew CodeAttributeArgument( gcnew CodePrimitiveExpression("This class is obsolete."));
- codeAttrDecl = gcnew CodeAttributeDeclaration("System.Obsolete", codeAttr);
- class1->CustomAttributes->Add(codeAttrDecl);
-
- // Create a C# code provider
- CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp");
-
- // Generate code and send the output to the console
- provider->GenerateCodeFromType(class1, Console::Out, gcnew CodeGeneratorOptions());
-}
-
-// The CPP code generator produces the following source code for the preceeding example code:
-//
-//[System.Serializable()]
-//[System.Obsolete("This class is obsolete.")]
-//public class Class1 {
-//}
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codeattributedeclaration/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codeattributedeclaration/cpp/source.cpp
deleted file mode 100644
index 5523f2c37c7..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codeattributedeclaration/cpp/source.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//
-#using
-#using
-
-using namespace System;
-using namespace System::CodeDom;
-using namespace System::CodeDom::Compiler;
-
-int main()
-{
- // Declare a new type called Class1.
- CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration("Class1");
-
- // Declare a new code attribute
- CodeAttributeDeclaration^ codeAttrDecl = gcnew CodeAttributeDeclaration(
- "System.CLSCompliantAttribute",
- gcnew CodeAttributeArgument(gcnew CodePrimitiveExpression(false)));
- class1->CustomAttributes->Add(codeAttrDecl);
-
- // Create a C# code provider
- CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp");
-
- // Generate code and send the output to the console
- provider->GenerateCodeFromType(class1, Console::Out, gcnew CodeGeneratorOptions());
-}
-
-// The CPP code generator produces the following source code for the preceeding example code:
-//
-//[System.CLSCompliantAttribute(false)]
-//public class Class1 {
-//}
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codemethodreferenceexpression/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codemethodreferenceexpression/cpp/source.cpp
deleted file mode 100644
index 4db196685db..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.codemethodreferenceexpression/cpp/source.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-#using
-#using
-
-using namespace System;
-using namespace System::CodeDom;
-using namespace System::CodeDom::Compiler;
-
-int main()
-{
- // Declare a new type called Class1.
- CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration("Class1");
-
- // Declares a type constructor that calls a method.
- CodeConstructor^ constructor1 = gcnew CodeConstructor();
- constructor1->Attributes = MemberAttributes::Public;
- class1->Members->Add(constructor1);
-
- // Creates a method reference for dict.Init.
- CodeMethodReferenceExpression^ methodRef1 =
- gcnew CodeMethodReferenceExpression(
- gcnew CodeVariableReferenceExpression("dict"),
- "Init",
- gcnew array {
- gcnew CodeTypeReference("System.Decimal"),
- gcnew CodeTypeReference("System.Int32")});
-
- // Invokes the dict.Init method from the constructor.
- CodeMethodInvokeExpression^ invoke1 =
- gcnew CodeMethodInvokeExpression(methodRef1, gcnew array {});
- constructor1->Statements->Add(invoke1);
-
- // Create a C# code provider
- CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp");
-
- // Generate code and send the output to the console
- provider->GenerateCodeFromType(class1, Console::Out, gcnew CodeGeneratorOptions());
-}
-
-// The CPP code generator produces the following source code for the preceeding example code:
-//
-//public class Class1 {
-//
-// public Class1() {
-// dict.Init();
-// }
-// }
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.compiler.generatedcodeattribute/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.codedom.compiler.generatedcodeattribute/cpp/source.cpp
deleted file mode 100644
index dcd7661e4aa..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.codedom.compiler.generatedcodeattribute/cpp/source.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-#using
-#using
-
-using namespace System;
-using namespace System::CodeDom;
-using namespace System::CodeDom::Compiler;
-
-int main()
-{
- // Declare a new type called Class1.
- CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration("Class1");
-
- // Declare a new generated code attribute
- GeneratedCodeAttribute^ generatedCodeAttribute =
- gcnew GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0");
-
- // Use the generated code attribute members in the attribute declaration
- CodeAttributeDeclaration^ codeAttrDecl =
- gcnew CodeAttributeDeclaration(generatedCodeAttribute->GetType()->Name,
- gcnew CodeAttributeArgument(
- gcnew CodePrimitiveExpression(generatedCodeAttribute->Tool)),
- gcnew CodeAttributeArgument(
- gcnew CodePrimitiveExpression(generatedCodeAttribute->Version)));
- class1->CustomAttributes->Add(codeAttrDecl);
-
- // Create a C# code provider
- CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp");
-
- // Generate code and send the output to the console
- provider->GenerateCodeFromType(class1, Console::Out, gcnew CodeGeneratorOptions());
-}
-
-// The CPP code generator produces the following source code for the preceeding example code:
-//
-// [GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0")]
-// public class Class1 {
-// }
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.assembly.getexecutingassembly/cpp/getexecutingassembly1.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.reflection.assembly.getexecutingassembly/cpp/getexecutingassembly1.cpp
deleted file mode 100644
index f2ad3ec6d43..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.assembly.getexecutingassembly/cpp/getexecutingassembly1.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//
-using namespace System;
-using namespace System::Reflection;
-
-ref class Example
-{};
-
-void main()
-{
- // Get the assembly from a known type in that assembly.
- Type^ t = Example::typeid;
- Assembly^ assemFromType = t->Assembly;
- Console::WriteLine("Assembly that contains Example:");
- Console::WriteLine(" {0}\n", assemFromType->FullName);
-
- // Get the currently executing assembly.
- Assembly^ currentAssem = Assembly::GetExecutingAssembly();
- Console::WriteLine("Currently executing assembly:");
- Console::WriteLine(" {0}\n", currentAssem->FullName);
-
- Console::WriteLine("The two Assembly objects are equal: {0}",
- assemFromType->Equals(currentAssem));
-}
-// The example displays the following output:
-// Assembly that contains Example:
-// GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
-//
-// Currently executing assembly:
-// GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
-//
-// The two Assembly objects are equal: True
-//
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.emit.typebuilder.makegenerictype/cpp/remarks.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.reflection.emit.typebuilder.makegenerictype/cpp/remarks.cpp
deleted file mode 100644
index 31f5e221cac..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.emit.typebuilder.makegenerictype/cpp/remarks.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-
-using namespace System;
-using namespace System::Reflection;
-using namespace System::Reflection::Emit;
-
-public ref class CompareGenericTypes
-{
-public:
- static void Main()
- {
- try
- {
- AppDomain^ currentDomain = AppDomain::CurrentDomain;
-
- AssemblyName^ aName = gcnew AssemblyName("TempAssembly");
- AssemblyBuilder^ ab = currentDomain->DefineDynamicAssembly(aName, AssemblyBuilderAccess::Run);
-
- ModuleBuilder^ mb = ab->DefineDynamicModule(aName->Name);
-
- TypeBuilder^ tbldr = mb->DefineType("MyNewType", TypeAttributes::Public);
- tbldr->DefineGenericParameters("T");
- //
- Type^ t1 = tbldr->MakeGenericType(String::typeid);
- Type^ t2 = tbldr->MakeGenericType(String::typeid);
- bool result = t1->Equals(t2);
- //
- Console::WriteLine("Types t1 and t2 match: {0:s}", result ? "Yes" : "No");
- }
- catch (Exception^ ex)
- {
- Console::WriteLine(ex->Message);
- Console::WriteLine(ex->StackTrace);
- }
- }
-};
-
-int main()
-{
- CompareGenericTypes::Main();
-}
-
-
-
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.fieldattributes/cpp/remarks.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.reflection.fieldattributes/cpp/remarks.cpp
deleted file mode 100644
index 7f81c1fa446..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.fieldattributes/cpp/remarks.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-
-using namespace System;
-using namespace System::Reflection;
-
-public ref class FieldAttribTest
-{
-public:
- static int field1 = 99;
-
- static void Main()
- {
- Object^ obj = gcnew FieldAttribTest();
-
- //
- FieldInfo^ fi = obj->GetType()->GetField("field1");
-
- if ((fi->Attributes & FieldAttributes::FieldAccessMask) ==
- FieldAttributes::Public)
- {
- Console::WriteLine("{0:s} is public. Value: {1:d}", fi->Name, fi->GetValue(obj));
- }
- //
- }
-};
-
-int main()
-{
- FieldAttribTest::Main();
-}
-
-
-
diff --git a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.parametermodifier/cpp/source.cpp b/snippets/cpp/VS_Snippets_CLR_System/system.reflection.parametermodifier/cpp/source.cpp
deleted file mode 100644
index 588767ccad5..00000000000
--- a/snippets/cpp/VS_Snippets_CLR_System/system.reflection.parametermodifier/cpp/source.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-
-using namespace System;
-using namespace System::Reflection;
-
-public ref class ParmInfoTest
-{
-public:
- static void Main()
- {
- Object^ obj = gcnew ParmInfoTest;
-
- //
- // Create an array containing the arguments.
- array^ args = {"Argument 1", "Argument 2", "Argument 3" };
-
- // Initialize a ParameterModifier with the number of parameters.
- ParameterModifier p = ParameterModifier(3);
-
- // Pass the first and third parameters by reference.
- p[0] = true;
- p[2] = true;
-
- // The ParameterModifier must be passed as the single element
- // of an array.
-
- array^ mods = { p };
-
- // Invoke the method late bound.
- obj->GetType()->InvokeMember("MethodName", BindingFlags::InvokeMethod,
- nullptr, obj, args, mods, nullptr, nullptr);
- //
- }
-
- void MethodName(String^% str1, String^ str2, String^% str3)
- {
- Console::WriteLine("Called 'MethodName'");
- }
-};
-
-int main()
-{
- ParmInfoTest::Main();
-}
-
-
-
diff --git a/snippets/cpp/VS_Snippets_Data/XPathValidation/CPP/XPathValidation.cpp b/snippets/cpp/VS_Snippets_Data/XPathValidation/CPP/XPathValidation.cpp
deleted file mode 100644
index 75adbf6a471..00000000000
--- a/snippets/cpp/VS_Snippets_Data/XPathValidation/CPP/XPathValidation.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-#using
-
-using namespace System;
-using namespace System::Xml;
-using namespace System::Xml::Schema;
-using namespace System::Xml::XPath;
-
-class XPathValidation
-{
-public:
-
- static void Main()
- {
- try
- {
- XmlReaderSettings^ settings = gcnew XmlReaderSettings();
- settings->Schemas->Add("http://www.contoso.com/books", "contosoBooks.xsd");
- settings->ValidationType = ValidationType::Schema;
-
- XmlReader^ reader = XmlReader::Create("contosoBooks.xml", settings);
- XmlDocument^ document = gcnew XmlDocument();
- document->Load(reader);
-
- ValidationEventHandler^ eventHandler = gcnew ValidationEventHandler(ValidationEventHandlerOne);
-
- // the following call to Validate succeeds.
- document->Validate(eventHandler);
-
- // add a node so that the document is no longer valid
- XPathNavigator^ navigator = document->CreateNavigator();
- navigator->MoveToFollowing("price", "http://www.contoso.com/books");
- XmlWriter^ writer = navigator->InsertAfter();
- writer->WriteStartElement("anotherNode", "http://www.contoso.com/books");
- writer->WriteEndElement();
- writer->Close();
-
- // the document will now fail to successfully validate
- document->Validate(eventHandler);
- }
- catch(Exception^ ex)
- {
- Console::WriteLine(ex->Message);
- }
- }
-
- static void ValidationEventHandlerOne(Object^ sender, ValidationEventArgs^ e)
- {
- switch (e->Severity)
- {
- case XmlSeverityType::Error:
- Console::WriteLine("Error: {0}", e->Message);
- break;
- case XmlSeverityType::Warning:
- Console::WriteLine("Warning {0}", e->Message);
- break;
- }
-
- }
-};
-
-int main()
-{
- XPathValidation::Main();
- Console::ReadLine();
- return 0;
-};
-//
\ No newline at end of file
diff --git a/snippets/cpp/VS_Snippets_Data/XmlDocument.XmlResolver/CPP/docresolver.cpp b/snippets/cpp/VS_Snippets_Data/XmlDocument.XmlResolver/CPP/docresolver.cpp
deleted file mode 100644
index 2b1b5ca9f4d..00000000000
--- a/snippets/cpp/VS_Snippets_Data/XmlDocument.XmlResolver/CPP/docresolver.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-//
-#using
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Xml;
-using namespace System::Net;
-int main()
-{
-
- // Supply the credentials necessary to access the DTD file stored on the network.
- XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
- resolver->Credentials = CredentialCache::DefaultCredentials;
-
- // Create and load the XmlDocument.
- XmlDocument^ doc = gcnew XmlDocument;
- doc->XmlResolver = resolver; // Set the resolver.
- doc->Load( "book5.xml" );
-
- // Display the entity replacement text which is pulled from the DTD file.
- Console::WriteLine( doc->DocumentElement->LastChild->InnerText );
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.Cctor/CPP/valid_xsd2.cpp b/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.Cctor/CPP/valid_xsd2.cpp
deleted file mode 100644
index 1b175cb5e4e..00000000000
--- a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.Cctor/CPP/valid_xsd2.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-//
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Xml;
-using namespace System::Xml::Schema;
-public ref class Sample
-{
-private:
- static Boolean m_success = true;
-
-public:
- Sample()
- {
-
- // Validate the document using an external XSD schema. Validation should fail.
- Validate( "notValidXSD.xml" );
-
- // Validate the document using an inline XSD. Validation should succeed.
- Validate( "inlineXSD.xml" );
- }
-
-
-private:
-
- // Display the validation error.
- void ValidationCallBack( Object^ /*sender*/, ValidationEventArgs^ args )
- {
- m_success = false;
- Console::WriteLine( "\r\n\tValidation error: {0}", args->Message );
- }
-
- void Validate( String^ filename )
- {
- m_success = true;
- Console::WriteLine( "\r\n******" );
- Console::WriteLine( "Validating XML file {0}", filename );
- XmlTextReader^ txtreader = gcnew XmlTextReader( filename );
- XmlValidatingReader^ reader = gcnew XmlValidatingReader( txtreader );
-
- // Set the validation event handler
- reader->ValidationEventHandler += gcnew ValidationEventHandler( this, &Sample::ValidationCallBack );
-
- // Read XML data
- while ( reader->Read() )
- {}
-
- Console::WriteLine( "Validation finished. Validation {0}", (m_success == true ? (String^)"successful!" : "failed.") );
-
- // Close the reader.
- reader->Close();
- }
-
-};
-
-int main()
-{
- Sample^ validation = gcnew Sample;
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.IsDefault/CPP/readdefattr.cpp b/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.IsDefault/CPP/readdefattr.cpp
deleted file mode 100644
index d4ffcecd285..00000000000
--- a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.IsDefault/CPP/readdefattr.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-//
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Xml;
-int main()
-{
-
- // Create the reader.
- XmlTextReader^ txtreader = gcnew XmlTextReader( "book4.xml" );
- XmlValidatingReader^ reader = gcnew XmlValidatingReader( txtreader );
- reader->MoveToContent();
-
- // Display each of the attribute nodes, including default attributes.
- while ( reader->MoveToNextAttribute() )
- {
- if ( reader->IsDefault )
- Console::Write( "(default attribute) " );
-
- Console::WriteLine( " {0} = {1}", reader->Name, reader->Value );
- }
-
-
- // Close the reader.
- reader->Close();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.SchemaType/CPP/schematype.cpp b/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.SchemaType/CPP/schematype.cpp
deleted file mode 100644
index 8704a0b66bd..00000000000
--- a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.SchemaType/CPP/schematype.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-#using
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Xml;
-using namespace System::Xml::Schema;
-
-public ref class Sample
-{
-private:
- static void ValidationCallBack( Object^ sender, ValidationEventArgs^ args )
- {
- Console::WriteLine( "***Validation error" );
- Console::WriteLine( "\tSeverity: {0}", args->Severity );
- Console::WriteLine( "\tMessage : {0}", args->Message );
- }
-
-public:
- static void main()
- {
- XmlTextReader^ tr = gcnew XmlTextReader( "booksSchema.xml" );
- XmlValidatingReader^ vr = gcnew XmlValidatingReader( tr );
- vr->Schemas->Add( nullptr, "books.xsd" );
- vr->ValidationType = ValidationType::Schema;
- vr->ValidationEventHandler += gcnew ValidationEventHandler( Sample::ValidationCallBack );
- while ( vr->Read() )
- {
- if ( vr->NodeType == XmlNodeType::Element )
- {
- if ( dynamic_cast(vr->SchemaType) != nullptr )
- {
- XmlSchemaComplexType^ sct = dynamic_cast(vr->SchemaType);
- Console::WriteLine( " {0}( {1})", vr->Name, sct->Name );
- }
- else
- {
- Object^ value = vr->ReadTypedValue();
- Console::WriteLine( " {0}( {1}): {2}", vr->Name, value->GetType()->Name, value );
- }
- }
- }
- }
-};
-
-int main()
-{
- Sample::main();
-}
-//
diff --git a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.XmlResolver/CPP/vrdr_resolver.cpp b/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.XmlResolver/CPP/vrdr_resolver.cpp
deleted file mode 100644
index c8b97c43ecc..00000000000
--- a/snippets/cpp/VS_Snippets_Data/XmlValidatingReader.XmlResolver/CPP/vrdr_resolver.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-#using
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Xml;
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- String^ UserName = args[ 1 ];
- String^ SecurelyStoredPassword = args[ 2 ];
- String^ Domain = args[ 3 ];
-
- //
- // Create the reader. ->
- XmlTextReader^ txtreader = gcnew XmlTextReader( "book5.xml" );
- XmlValidatingReader^ reader = gcnew XmlValidatingReader( txtreader );
- txtreader->WhitespaceHandling = WhitespaceHandling::None;
-
- // Set the credentials necessary to access the DTD file stored on the network.
- XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
- resolver->Credentials = System::Net::CredentialCache::DefaultCredentials;
- reader->XmlResolver = resolver;
-
- // Display each of the element nodes.
- while ( reader->Read() )
- {
- switch ( reader->NodeType )
- {
- case XmlNodeType::Element:
- Console::Write( "< {0}>", reader->Name );
- break;
-
- case XmlNodeType::Text:
- Console::Write( reader->Value );
- break;
-
- case XmlNodeType::DocumentType:
- Console::Write( "Name, reader->Value );
- break;
-
- case XmlNodeType::EntityReference:
- Console::Write( reader->Name );
- break;
-
- case XmlNodeType::EndElement:
- Console::Write( " {0}>", reader->Name );
- break;
- }
- }
-
-
- // Close the reader.
- reader->Close();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/AuthenticationManager_UnRegister2/CPP/authenticationmanager_unregister2.cpp b/snippets/cpp/VS_Snippets_Remoting/AuthenticationManager_UnRegister2/CPP/authenticationmanager_unregister2.cpp
deleted file mode 100644
index eaec1a8cfc9..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/AuthenticationManager_UnRegister2/CPP/authenticationmanager_unregister2.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-// System.Net.AuthenticationManager.UnRegister(String).
-// System.Net.AuthenticationManager.Register.
-// Grouping Clause : 1,3 AND 2,3.
-
-/*This program demonstrates the 'UnRegister(String)' and 'Register' methods of
-'AuthenticationManager' class. It gets all the authentication modules registered with the system into an
-IEnumerator instance ,unregisters the first authentication module and displays to show that it was
-unregistered. Then registers the same module back again and displays all the modules again.*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Collections;
-
-//
-void DisplayAllModules()
-{
- IEnumerator^ registeredModules = AuthenticationManager::RegisteredModules;
- Console::WriteLine( "\n\tThe following modules are now registered with the system:" );
- while ( registeredModules->MoveNext() )
- {
- Console::WriteLine( "\n\t\tModule : {0}", registeredModules->Current );
- IAuthenticationModule^ currentAuthenticationModule = dynamic_cast(registeredModules->Current);
- Console::WriteLine( "\t\t\t CanPreAuthenticate : {0}", currentAuthenticationModule->CanPreAuthenticate );
- }
-}
-//
-
-int main()
-{
- try
- {
-//
-//
- IEnumerator^ registeredModules = AuthenticationManager::RegisteredModules;
- // Display all the modules that are already registered with the system.
- DisplayAllModules();
- registeredModules->Reset();
- registeredModules->MoveNext();
- // Get the first Authentication module registered with the system.
- IAuthenticationModule^ authenticationModule1 = dynamic_cast(registeredModules->Current);
- // Call the UnRegister() method to unregister the first authentication module from the system.
- String^ authenticationScheme = authenticationModule1->AuthenticationType;
- AuthenticationManager::Unregister( authenticationScheme );
- Console::WriteLine( "\nSuccessfully unregistered '{0}'.", authenticationModule1 );
- // Display all modules to see that the module was unregistered.
- DisplayAllModules();
-//
- // Calling 'Register()' method to register 'authenticationModule1' module back again.
- AuthenticationManager::Register( authenticationModule1 );
- Console::WriteLine( "\nSuccessfully re-registered '{0}'.", authenticationModule1 );
- // Display the modules to verify that 'authenticationModule1' has been registered back again.
- DisplayAllModules();
-//
- Console::WriteLine( "Press any key to continue" );
- Console::ReadLine();
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\n The following Exception was raised : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Authorization_Constructor3/CPP/authorization_constructor3.cpp b/snippets/cpp/VS_Snippets_Remoting/Authorization_Constructor3/CPP/authorization_constructor3.cpp
deleted file mode 100644
index 9d25d5c5604..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Authorization_Constructor3/CPP/authorization_constructor3.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-
-
-// System::Net::Authorization::Authorization(String*, bool, String*)
-/* This program demonstrates the contructor 'Authorization(String*, bool, String*)' of the authorization
-* class.
-*
-* We implement the interface S"IAuthenticationModule*" to make CloneBasic which is a custom authentication module.
-* The custom authentication module encodes username and password as base64 strings and then returns
-* back an authorization instance. This authorization is internally used by the HttpWebRequest for
-* authentication.
-* *
-* Please Note : This program has to be compiled as a dll.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Text;
-
-namespace CloneBasicAuthentication
-{
- public ref class CloneBasic: public IAuthenticationModule
- {
- private:
- String^ m_authenticationType;
- bool m_canPreAuthenticate;
-
- public:
- CloneBasic()
- {
- m_authenticationType = "CloneBasic";
- m_canPreAuthenticate = false;
- }
-
- property String^ AuthenticationType
- {
- virtual String^ get()
- {
- return m_authenticationType;
- }
- }
-
- property bool CanPreAuthenticate
- {
- virtual bool get()
- {
- return m_canPreAuthenticate;
- }
- }
-
- //
- virtual Authorization^ Authenticate( String^ challenge, WebRequest^ request, ICredentials^ credentials )
- {
- try
- {
- String^ message;
-
- // Check if Challenge String* was raised by a site which requires CloneBasic authentication.
- if ( (challenge == nullptr) || ( !challenge->StartsWith( "CloneBasic" )) )
- return nullptr;
- NetworkCredential^ myCredentials;
- if ( dynamic_cast(credentials) == nullptr )
- {
- myCredentials = credentials->GetCredential( request->RequestUri, "CloneBasic" );
- if ( myCredentials == nullptr )
- return nullptr;
- }
- else
- myCredentials = dynamic_cast(credentials);
-
- // Message encryption scheme :
- // a)Concatenate username and password seperated by space;
- // b)Apply ASCII encoding to obtain a stream of bytes;
- // c)Apply Base64 Encoding to this array of bytes to obtain our encoded authorization message.
- message = String::Concat( myCredentials->UserName, " ", myCredentials->Password );
-
- // Apply AsciiEncoding to our user name and password to obtain it as an array of bytes.
- Encoding^ asciiEncoding = Encoding::ASCII;
- array^byteArray = gcnew array(asciiEncoding->GetByteCount( message ));
- byteArray = asciiEncoding->GetBytes( message );
-
- // Perform Base64 transform.
- message = Convert::ToBase64String( byteArray );
-
- // The following overloaded contructor sets the 'Message' property of authorization to the base64 String*;
- // that we just formed and it also sets the 'Complete' property to true and the connection group id;
- // to the domain of the NetworkCredential Object*.
- Authorization^ myAuthorization = gcnew Authorization( String::Concat( "CloneBasic ", message, true, request->ConnectionGroupName ) );
- return myAuthorization;
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception Raised ...: {0}", e->Message );
- return nullptr;
- }
- }
- //
-
- virtual Authorization^ PreAuthenticate( WebRequest^ request, ICredentials^ credentials )
- {
- return nullptr;
- }
- };
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Authorization_ProtectionRealm/CPP/authorization_protectionrealm.cpp b/snippets/cpp/VS_Snippets_Remoting/Authorization_ProtectionRealm/CPP/authorization_protectionrealm.cpp
deleted file mode 100644
index 6f0a633e81e..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Authorization_ProtectionRealm/CPP/authorization_protectionrealm.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-
-
-// System::Net::Authorization::Authorization(String*, bool);System::Net::Authorization::ProtectionRealm
-/* This program demonstrates the 'ProtectionRealm' property and 'Authorization(String*, bool)' constructor of
-the S"Authorization" class. The S"IAuthenticationModule*" interface is implemented in 'CloneBasic' to make
-it a custom authentication module. The custom authentication module encodes username and password as
-base64 strings and then returns back an 'Authorization' instance. The 'Authorization' instance encapsulates
-a list of Uri's for which it is applicable using the S"ProtectionRealm" property.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Text;
-void GetPage( String^ url, String^ username, String^ passwd )
-{
- try
- {
- String^ challenge = nullptr;
- HttpWebRequest^ myHttpWebRequest = nullptr;
- try
- {
- // Create a 'HttpWebRequest' Object* for the above 'url'.
- myHttpWebRequest = dynamic_cast(WebRequest::Create( url ));
-
- // The following method call throws the 'WebException'.
- HttpWebResponse^ myHttpWebResponse = dynamic_cast(myHttpWebRequest->GetResponse());
-
- // Release resources of response Object*.
- myHttpWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- for ( int i = 0; i < e->Response->Headers->Count; ++i )
-
- // Retrieve the challenge String* from the header S"WWW-Authenticate".
- if ( (String::Compare( e->Response->Headers->Keys[ i ], "WWW-Authenticate", true ) == 0) )
- challenge = e->Response->Headers[ i ];
- }
-
- if ( challenge != nullptr )
- {
- // Challenge was raised by the client.Declare your credentials.
- NetworkCredential^ myCredentials = gcnew NetworkCredential( username,passwd );
-
- // Pass the challenge , 'NetworkCredential' Object* and the 'HttpWebRequest' Object* to the
- // 'Authenticate' method of the S"AuthenticationManager" to retrieve an S"Authorization" ;
- // instance.
- Authorization^ urlAuthorization = AuthenticationManager::Authenticate( challenge, myHttpWebRequest, myCredentials );
- if ( urlAuthorization != nullptr )
- {
- Console::WriteLine( "\nSuccessfully Created 'Authorization' object with authorization Message:\n \" {0}\"", urlAuthorization->Message );
- Console::WriteLine( "\n\nThis authorization is valid for the following Uri's:" );
- int count = 0;
- System::Collections::IEnumerator^ myEnum = urlAuthorization->ProtectionRealm->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- String^ uri = safe_cast(myEnum->Current);
- ++count;
- Console::WriteLine( "\nUri->Item[ {0}]: {1}", count, uri );
- }
- }
- else
- Console::WriteLine( "\nAuthorization Object* was returned as 0. Please check if site accepts 'CloneBasic' authentication" );
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\n The following exception was raised : {0}", e->Message );
- }
-}
-
-void PrintUsage()
-{
- Console::WriteLine( "\r\nUsage: Try a site which requires CloneBasic(custom made) authentication as below" );
- Console::WriteLine( " Authorization_ProtectionRealm URLname username password" );
- Console::WriteLine( "\nExample:" );
- Console::WriteLine( "\n Authorization_ProtectionRealm http://www.microsoft.com/net/ george george123" );
-}
-
-// The 'CloneBasic' authentication module class implements 'IAuthenticationModule*'.
-public ref class CloneBasic: public IAuthenticationModule
-{
-private:
- String^ m_authenticationType;
- bool m_canPreAuthenticate;
-
-public:
- CloneBasic()
- {
- m_authenticationType = "CloneBasic";
- m_canPreAuthenticate = false;
- }
-
- property String^ AuthenticationType
- {
- virtual String^ get()
- {
- return m_authenticationType;
- }
- }
-
- property bool CanPreAuthenticate
- {
- virtual bool get()
- {
- return m_canPreAuthenticate;
- }
- }
-
- //
- //
- virtual Authorization^ Authenticate( String^ challenge, WebRequest^ request, ICredentials^ credentials )
- {
- try
- {
- String^ message;
-
- // Check if Challenge String* was raised by a site which requires 'CloneBasic' authentication.
- if ( (challenge == nullptr) || ( !challenge->StartsWith( "CloneBasic" )) )
- return nullptr;
- NetworkCredential^ myCredentials;
- if ( dynamic_cast(credentials) == nullptr )
- {
- myCredentials = credentials->GetCredential( request->RequestUri, "CloneBasic" );
- if ( myCredentials == nullptr )
- return nullptr;
- }
- else
- myCredentials = dynamic_cast(credentials);
-
- // Message encryption scheme :
- // a)Concatenate username and password seperated by space;
- // b)Apply ASCII encoding to obtain a stream of bytes;
- // c)Apply Base64 Encoding to this array of bytes to obtain our encoded authorization message.
- message = String::Concat( myCredentials->UserName, " ", myCredentials->Password );
-
- // Apply AsciiEncoding to 'message' String* to obtain it as an array of bytes.
- Encoding^ ascii = Encoding::ASCII;
- array^byteArray = gcnew array(ascii->GetByteCount( message ));
- byteArray = ascii->GetBytes( message );
-
- // Performing Base64 transformation.
- message = Convert::ToBase64String( byteArray );
- Authorization^ myAuthorization = gcnew Authorization( String::Concat( "CloneBasic ", message, true ) );
- array^protectionRealm = gcnew array(1);
- protectionRealm[ 0 ] = request->RequestUri->AbsolutePath;
- myAuthorization->ProtectionRealm = protectionRealm;
- return myAuthorization;
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "The following exception was raised in Authenticate method: {0}", e->Message );
- return nullptr;
- }
- }
- //
- //
-
- virtual Authorization^ PreAuthenticate( WebRequest^ request, ICredentials^ credentials )
- {
- return nullptr;
- }
-};
-
-// The 'Client' class is defined here to test the above custom authentication module.
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- String^ url;
- String^ userName;
- String^ passwd;
- if ( args->Length < 3 )
- {
- PrintUsage();
- return 0;
- }
- else
- {
- url = args[ 0 ];
- userName = args[ 1 ];
- passwd = args[ 2 ];
- }
-
- Console::WriteLine();
- CloneBasic^ authenticationModule = gcnew CloneBasic;
- AuthenticationManager::Register( authenticationModule );
- AuthenticationManager::Unregister( "Basic" );
-
- // Get response from Uri.
- GetPage( url, userName, passwd );
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic CredentialCache.Add Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic CredentialCache.Add Example/CPP/source.cpp
deleted file mode 100644
index eb8a5c280ac..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic CredentialCache.Add Example/CPP/source.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::Net;
-public ref class Class
-{
-private:
- void Method1()
- {
- String^ UserName = Console::ReadLine();
- String^ SecurelyStoredPassword = Console::ReadLine();
- String^ Domain = Console::ReadLine();
-
- WebRequest^ wReq = WebRequest::Create( "http://www.contoso.com" );
-
- //
- CredentialCache^ myCache = gcnew CredentialCache;
-
- myCache->Add( gcnew Uri( "http://www.contoso.com/" ), "Basic", gcnew NetworkCredential( UserName,SecurelyStoredPassword ) );
- myCache->Add( gcnew Uri( "http://www.contoso.com/" ), "Digest", gcnew NetworkCredential( UserName,SecurelyStoredPassword,Domain ) );
-
- wReq->Credentials = myCache;
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Dns Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Dns Example/CPP/source.cpp
deleted file mode 100644
index 1902e81255b..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Dns Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Net;
-using namespace System::Windows::Forms;
-public ref class Form1: public Form
-
-{
-protected:
- void Method()
- {
- //
- IPHostEntry^ hostInfo = Dns::GetHostEntry( "www.contoso.com" );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic GlobalProxySelection Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic GlobalProxySelection Example/CPP/source.cpp
deleted file mode 100644
index e4aa5aedcd2..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic GlobalProxySelection Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Windows::Forms;
-
-public ref class Form1: public Form
-{
-public:
- void Method()
- {
- //
- Uri^ proxyURI = gcnew Uri( "http://webproxy:80" );
- GlobalProxySelection::Select = gcnew WebProxy( proxyURI );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest Example/CPP/source.cpp
deleted file mode 100644
index 16cbdf361c8..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest Example/CPP/source.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-#using
-
-using namespace System;
-using namespace System::Net;
-public ref class Sample
-{
-public:
- void Method()
- {
- //
- HttpWebRequest^ myReq = dynamic_cast(WebRequest::Create( "http://www.contoso.com/" ));
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest.RequestUri Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest.RequestUri Example/CPP/source.cpp
deleted file mode 100644
index 352469e1bea..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest.RequestUri Example/CPP/source.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Web;
-using namespace System::Web::UI;
-
-public ref class Page1: public Page
-{
-private:
- void Page_Load( Object^, EventArgs^ )
- {
- HttpWebRequest^ req = dynamic_cast(WebRequest::Create( "http://www.contoso.com/" ));
-
- //
- bool hasChanged = req->RequestUri->Equals( req->Address );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebResponse Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebResponse Example/CPP/source.cpp
deleted file mode 100644
index 945bd743eee..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebResponse Example/CPP/source.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Web;
-using namespace System::Web::UI;
-
-public ref class Page1: public Page
-{
-private:
- void Page_Load( Object^, EventArgs^ )
- {
- //
- HttpWebRequest^ HttpWReq = dynamic_cast(WebRequest::Create( "http://www.contoso.com" ));
- HttpWebResponse^ HttpWResp = dynamic_cast(HttpWReq->GetResponse());
-
- // Insert code that uses the response object.
- HttpWResp->Close();
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic LingerOption Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic LingerOption Example/CPP/source.cpp
deleted file mode 100644
index ef840b46dcf..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic LingerOption Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-public ref class Sample
-{
-protected:
- void Method( Socket^ mySocket )
- {
- //
- LingerOption^ myOpts = gcnew LingerOption( true,1 );
- mySocket->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::Linger, myOpts );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic NetworkCredential Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic NetworkCredential Example/CPP/source.cpp
deleted file mode 100644
index c92542655c2..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic NetworkCredential Example/CPP/source.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Net::Http;
-using namespace System::IO;
-using namespace System::Windows::Forms;
-
-public ref class Form1: public Form
-{
-public:
- void Method()
- {
- String^ SecurelyStoredUserName = "";
- String^ SecurelyStoredPassword = "";
- String^ SecurelyStoredDomain = "";
-
- //
- NetworkCredential^ myCred = gcnew NetworkCredential(
- SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain );
-
- CredentialCache^ myCache = gcnew CredentialCache;
-
- myCache->Add( gcnew Uri( "http://www.contoso.com" ), "Basic", myCred );
- myCache->Add( gcnew Uri( "http://app.contoso.com" ), "Basic", myCred );
-
- // HttpClient lifecycle management best practices:
- // https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
- HttpClientHandler^ handler = gcnew HttpClientHandler();
- handler->Credentials = myCache;
- HttpClient^ client = gcnew HttpClient(handler);
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic ServicePoint Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic ServicePoint Example/CPP/source.cpp
deleted file mode 100644
index 1a04a196a24..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic ServicePoint Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Windows::Forms;
-
-public ref class Form1: public Form
-{
-public:
- void Method()
- {
- //
- Uri^ myUri = gcnew Uri( "http://www.contoso.com/" );
- ServicePoint^ mySP = ServicePointManager::FindServicePoint( myUri );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic ServicePointManager.CertificatePolicy Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic ServicePointManager.CertificatePolicy Example/CPP/source.cpp
deleted file mode 100644
index 7a9fdb44639..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic ServicePointManager.CertificatePolicy Example/CPP/source.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Windows::Forms;
-using namespace System::Web;
-using namespace System::Web::Services;
-
-// Class added so sample will compile
-public ref class MyCertificatePolicy: public ICertificatePolicy
-{
-public:
- virtual bool CheckValidationResult( System::Net::ServicePoint^, System::Security::Cryptography::X509Certificates::X509Certificate^, System::Net::WebRequest^, int )
- {
- return true;
- }
-};
-
-public ref class Form1: public Form
-{
-public:
- void Method( Uri^ myUri )
- {
- //
- ServicePointManager::CertificatePolicy = gcnew MyCertificatePolicy;
-
- // Create the request and receive the response
- try
- {
- WebRequest^ myRequest = WebRequest::Create( myUri );
- WebResponse^ myResponse = myRequest->GetResponse();
- ProcessResponse( myResponse );
- myResponse->Close();
- }
- // Catch any exceptions
- catch ( WebException^ e )
- {
- if ( e->Status == WebExceptionStatus::TrustFailure )
- {
- // Code for handling security certificate problems goes here.
- }
- // Other exception handling goes here
- }
- //
- }
-
- // Method added so sample will compile
- void ProcessResponse( WebResponse^ ){}
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Accept Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Accept Example/CPP/source.cpp
deleted file mode 100644
index e1e657e660b..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Accept Example/CPP/source.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-public ref class Sample
-{
- //
-protected:
- void AcceptMethod( Socket^ listeningSocket )
- {
- Socket^ mySocket = listeningSocket->Accept();
- }
- //
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Bind Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Bind Example/CPP/source.cpp
deleted file mode 100644
index 6c46b3b92d7..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Bind Example/CPP/source.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-public ref class Sample
-{
-protected:
- void Method( Socket^ aSocket, EndPoint^ anEndPoint )
- {
- //
- try
- {
- aSocket->Bind( anEndPoint );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Winsock error: {0}", e );
- }
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Close Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Close Example/CPP/source.cpp
deleted file mode 100644
index 2e51128de63..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Close Example/CPP/source.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-using namespace System::Security::Permissions;
-
-public ref class Sample
-{
-protected:
- [SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
- void Method( Socket^ aSocket )
- {
- //
- try
- {
- aSocket->Shutdown(SocketShutdown::Both);
- aSocket->Close();
- }
- catch (...)
- {
- aSocket->Close();
- throw;
- }
-
- if ( aSocket->Connected )
- {
- Console::WriteLine( "Winsock error: {0}", Convert::ToString(
- System::Runtime::InteropServices::Marshal::GetLastWin32Error() ) );
- }
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Connect Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Connect Example/CPP/source.cpp
deleted file mode 100644
index 6693a8bdfcc..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Connect Example/CPP/source.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-static void ConnectAndCheck( Socket^ client, EndPoint^ anEndPoint )
-{
- //
- client->Connect( anEndPoint );
- if ( !client->Connected )
- {
- Console::WriteLine( "Winsock error: {0}", Convert::ToString(
- System::Runtime::InteropServices::Marshal::GetLastWin32Error() ) );
- }
-
- // This is how you can determine whether a socket is still connected.
- bool blockingState = client->Blocking;
- try
- {
- array^tmp = gcnew array(1);
- client->Blocking = false;
- client->Send( tmp, 0, static_cast(0) );
- Console::WriteLine( L"Connected!" );
- }
- catch ( SocketException^ e )
- {
- // 10035 == WSAEWOULDBLOCK
- if ( e->NativeErrorCode.Equals( 10035 ) )
- {
- Console::WriteLine( "Connected from an exception!" );
- }
- else
- {
- Console::WriteLine( "Disconnected: {0}!", e->NativeErrorCode );
- }
- }
- finally
- {
- client->Blocking = blockingState;
- }
-
- Console::WriteLine( "Connected: {0}", client->Connected );
- //
-}
-
-[STAThread]
-int main()
-{
- Socket^ s = gcnew Socket( AddressFamily::InterNetwork,
- SocketType::Stream,
- ProtocolType::Tcp );
-
- String^ host = "localhost";
- int port = 80;
-
- IPHostEntry^ hostEntry = Dns::Resolve( host );
- IPEndPoint^ EPHost = gcnew IPEndPoint( hostEntry->AddressList[ 0 ],port );
-
- ConnectAndCheck( s, EPHost );
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Listen Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Listen Example/CPP/source.cpp
deleted file mode 100644
index 66f68944d86..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Socket.Listen Example/CPP/source.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-void CreateAndListen( int port, int backlog )
-{
- //
- // create the socket
- Socket^ listenSocket = gcnew Socket( AddressFamily::InterNetwork,
- SocketType::Stream,
- ProtocolType::Tcp );
-
- // bind the listening socket to the port
- IPAddress^ hostIP = ( Dns::Resolve( IPAddress::Any->ToString() ) )->AddressList[ 0 ];
- IPEndPoint^ ep = gcnew IPEndPoint( hostIP,port );
- listenSocket->Bind( ep );
-
- // start listening
- listenSocket->Listen( backlog );
- //
-}
-
-[STAThread]
-int main()
-{
- CreateAndListen( 10042, 10 );
- Console::WriteLine( "enter to exit" );
- Console::Read();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic SocketAddressExample/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic SocketAddressExample/CPP/source.cpp
deleted file mode 100644
index 27d0003bd8b..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic SocketAddressExample/CPP/source.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::Text;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-void MySerializeIPEndPointClassMethod()
-{
- //
- //Creates an IpEndPoint.
- IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
- IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );
-
- //Serializes the IPEndPoint.
- SocketAddress^ socketAddress = ipLocalEndPoint->Serialize();
-
- //Verifies that ipLocalEndPoint is now serialized by printing its contents.
- Console::WriteLine( "Contents of the socketAddress are: {0}", socketAddress );
- //Checks the Family property.
- Console::WriteLine( "The address family of the socketAddress is: {0}", socketAddress->Family );
- //Checks the underlying buffer size.
- Console::WriteLine( "The size of the underlying buffer is: {0}", socketAddress->Size );
- //
-}
-
-int main()
-{
- MySerializeIPEndPointClassMethod();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic TcpListener.PublicMethodsAndPropertiesExample/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic TcpListener.PublicMethodsAndPropertiesExample/CPP/source.cpp
deleted file mode 100644
index 719fbbc6521..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic TcpListener.PublicMethodsAndPropertiesExample/CPP/source.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-using namespace System::Text;
-using namespace System::Threading;
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- if ( args->Length == 1 )
- {
- Console::WriteLine( "Enter a selection" );
- return 0;
- }
-
- if ( args[ 1 ] == "endpointExample" )
- {
- //
- //Creates an instance of the TcpListener class by providing a local endpoint.
-
- IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ];
- IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );
-
- try
- {
- TcpListener^ tcpListener = gcnew TcpListener( ipLocalEndPoint );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else
- if ( args[ 1 ] == "ipAddressExample" )
- {
- //
- //Creates an instance of the TcpListener class by providing a local IP address and port number.
-
- IPAddress^ ipAddress = Dns::Resolve( "localhost" )->AddressList[ 0 ];
-
- try
- {
- TcpListener^ tcpListener = gcnew TcpListener( ipAddress,13 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else
- if ( args[ 1 ] == "portNumberExample" )
- {
- //
- //Creates an instance of the TcpListener class by providing a local port number.
-
- IPAddress^ ipAddress = Dns::Resolve( "localhost" )->AddressList[ 0 ];
-
- try
- {
- TcpListener^ tcpListener = gcnew TcpListener( ipAddress,13 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else
- {
- IPAddress^ ipAddress = Dns::Resolve( "localhost" )->AddressList[ 0 ];
- TcpListener^ tcpListener = gcnew TcpListener( ipAddress,13 );
- tcpListener->Start();
- Console::WriteLine( "Waiting for a connection...." );
-
- try
- {
- //
- // Accepts the pending client connection and returns a socket for communciation.
- Socket^ socket = tcpListener->AcceptSocket();
- Console::WriteLine( "Connection accepted." );
-
- String^ responseString = "You have successfully connected to me";
-
- //Forms and sends a response string to the connected client.
- array^sendBytes = Encoding::ASCII->GetBytes( responseString );
- int i = socket->Send( sendBytes );
- Console::WriteLine( "Message Sent /> : {0}", responseString );
- //
-
- //Any communication with the remote client using the socket can go here.
-
- //Closes the tcpListener and the socket.
- socket->Shutdown( SocketShutdown::Both );
- socket->Close();
- tcpListener->Stop();
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic TcpListenerExample/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic TcpListenerExample/CPP/source.cpp
deleted file mode 100644
index c216c7fe3f7..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic TcpListenerExample/CPP/source.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-//
-/**
-* This program shows how to use the TcpListener class.
-* It creates a TcpListener that listens on the specified port (13000).
-* To run this program at the command line you enter:
-* cs_tcpserver
-* Any TcpClient that wants to use this server
-* has to explicitly connect to an address obtained by the combination of
-* the server on which this TcpServer is running and the port 13000.
-* This TcpServer simply echoes back the message sent by the TcpClient, after
-* translating it into uppercase.
-**/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-using namespace System::Text;
-
-int main()
-{
- try
- {
-
- // Set the TcpListener on port 13000.
- Int32 port = 13000;
- TcpListener^ server = gcnew TcpListener(IPAddress::Any, port);
-
- // Start listening for client requests.
- server->Start();
-
- // Buffer for reading data
- array^bytes = gcnew array(256);
- String^ data = nullptr;
-
- // Enter the listening loop.
- while ( true )
- {
- Console::Write( "Waiting for a connection... " );
-
- // Perform a blocking call to accept requests.
- // You could also use server.AcceptSocket() here.
- TcpClient^ client = server->AcceptTcpClient();
- Console::WriteLine( "Connected!" );
- data = nullptr;
-
- // Get a stream object for reading and writing
- NetworkStream^ stream = client->GetStream();
- Int32 i;
-
- // Loop to receive all the data sent by the client.
- while ( (i = stream->Read( bytes, 0, bytes->Length )) != 0 )
- {
-
- // Translate data bytes to a ASCII string.
- data = System::Text::Encoding::ASCII->GetString( bytes, 0, i );
- Console::WriteLine( String::Format( "Received: {0}", data ) );
-
- // Process the data sent by the client.
- data = data->ToUpper();
- array^msg = System::Text::Encoding::ASCII->GetBytes( data );
-
- // Send back a response.
- stream->Write( msg, 0, msg->Length );
- Console::WriteLine( String::Format( "Sent: {0}", data ) );
- }
-
- // Shutdown and end connection
- client->Close();
- }
- }
- catch ( SocketException^ e )
- {
- Console::WriteLine( "SocketException: {0}", e );
- }
-
- Console::WriteLine( "\nHit enter to continue..." );
- Console::Read();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UdpClient.ProtectedMethodsAndPropertiesExample/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UdpClient.ProtectedMethodsAndPropertiesExample/CPP/source.cpp
deleted file mode 100644
index 8c3fe289538..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UdpClient.ProtectedMethodsAndPropertiesExample/CPP/source.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-#using
-
-using namespace System;
-using namespace System::Text;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-//
-// This derived class demonstrate the use of three protected methods belonging to the UdpClient class.
-public ref class MyUdpClientDerivedClass: public UdpClient
-{
-public:
- MyUdpClientDerivedClass()
- : UdpClient()
- {}
-
- void UsingProtectedMethods()
- {
- //Uses the protected Active property belonging to the UdpClient base class to determine if a connection is established.
- if ( this->Active )
- {
- //Calls the protected Client property belonging to the UdpClient base class.
- Socket^ s = this->Client;
-
- //Uses the Socket returned by Client to set an option that is not available using UdpClient.
- s->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::Broadcast, 1 );
- }
- }
-};
-//
-
-int main()
-{
- MyUdpClientDerivedClass^ myUdpClientDerivedClass = gcnew MyUdpClientDerivedClass;
- myUdpClientDerivedClass->UsingProtectedMethods();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UdpClient.PublicMethodsAndPropertiesExample/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UdpClient.PublicMethodsAndPropertiesExample/CPP/source.cpp
deleted file mode 100644
index 9ac0d6b76e3..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UdpClient.PublicMethodsAndPropertiesExample/CPP/source.cpp
+++ /dev/null
@@ -1,280 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::Text;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-public ref class MyUdpClientExample
-{
-public:
- // MyUdpClientConstructor is just used to illustrate the different constructors available in in the UdpClient class.
- static void MyUdpClientConstructor( String^ myConstructorType )
- {
- if ( myConstructorType->Equals( "PortNumberExample" ) )
- {
- //
- //Creates an instance of the UdpClient class to listen on
- // the default interface using a particular port.
- try
- {
- UdpClient^ udpClient = gcnew UdpClient( 11000 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( myConstructorType->Equals( "LocalEndPointExample" ) )
- {
- //
- //Creates an instance of the UdpClient class using a local endpoint.
- IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ];
- IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );
-
- try
- {
- UdpClient^ udpClient = gcnew UdpClient( ipLocalEndPoint );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( myConstructorType->Equals( "HostNameAndPortNumExample" ) )
- {
- //
- //Creates an instance of the UdpClient class with a remote host name and a port number.
- try
- {
- UdpClient^ udpClient = gcnew UdpClient( "www.contoso.com",11000 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( myConstructorType->Equals( "DefaultExample" ) )
- {
- //
- //Creates an instance of the UdpClient class using the default constructor.
- UdpClient^ udpClient = gcnew UdpClient;
- //
- }
- else
- {
- // Do nothing.
- }
- }
-
- // MyUdpClientConnection method is just used to illustrate the different connection methods of UdpClient class.
- static void MyUdpClientConnection( String^ myConnectionType )
- {
- if ( myConnectionType->Equals( "HostnameAndPortNumExample" ) )
- {
- //
- //Uses a host name and port number to establish a socket connection.
- UdpClient^ udpClient = gcnew UdpClient;
- try
- {
- udpClient->Connect( "www.contoso.com", 11002 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( myConnectionType == "IPAddressAndPortNumExample" )
- {
- //
- //Uses the IP address and port number to establish a socket connection.
- UdpClient^ udpClient = gcnew UdpClient;
- IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
- try
- {
- udpClient->Connect( ipAddress, 11003 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( myConnectionType == "RemoteEndPointExample" )
- {
- //
- //Uses a remote endpoint to establish a socket connection.
- UdpClient^ udpClient = gcnew UdpClient;
- IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
- IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddress,11004 );
- try
- {
- udpClient->Connect( ipEndPoint );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else
- {
- // Do nothing.
- }
- }
-
- // This class demonstrates sending and receiving using a Udp socket.
- static void MyUdpClientCommunicator( String^ mySendType )
- {
- if ( mySendType == "EndPointExample" )
- {
- //
- UdpClient^ udpClient = gcnew UdpClient;
- IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
- IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddress,11004 );
-
- array^ sendBytes = Encoding::ASCII->GetBytes( "Is anybody there?" );
- try
- {
- udpClient->Send( sendBytes, sendBytes->Length, ipEndPoint );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( mySendType == "HostNameAndPortNumberExample" )
- {
- //
- UdpClient^ udpClient = gcnew UdpClient;
-
- array^ sendBytes = Encoding::ASCII->GetBytes( "Is anybody there" );
- try
- {
- udpClient->Send( sendBytes, sendBytes->Length, "www.contoso.com", 11000 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( mySendType == "StraightSendExample" )
- {
- //
- UdpClient^ udpClient = gcnew UdpClient( "www.contoso.com",11000 );
- array^ sendBytes = Encoding::ASCII->GetBytes( "Is anybody there" );
- try
- {
- udpClient->Send( sendBytes, sendBytes->Length );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else
- {
- // Do nothing.
- }
-
- //
- //Creates a UdpClient for reading incoming data.
- UdpClient^ receivingUdpClient = gcnew UdpClient( 11000 );
-
- //Creates an IPEndPoint to record the IP Address and port number of the sender.
- // The IPEndPoint will allow you to read datagrams sent from any source.
- IPEndPoint^ RemoteIpEndPoint = gcnew IPEndPoint( IPAddress::Any,0 );
- try
- {
- // Blocks until a message returns on this socket from a remote host.
- array^receiveBytes = receivingUdpClient->Receive( RemoteIpEndPoint );
-
- String^ returnData = Encoding::ASCII->GetString( receiveBytes );
-
- Console::WriteLine( "This is the message you received {0}", returnData );
- Console::WriteLine( "This message was sent from {0} on their port number {1}",
- RemoteIpEndPoint->Address, RemoteIpEndPoint->Port );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
-
- // This example class demonstrates methods used to join and drop multicast groups.
- static void MyUdpClientMulticastConfiguration( String^ myAction )
- {
- if ( myAction == "JoinMultiCastExample" )
- {
- //
- UdpClient^ udpClient = gcnew UdpClient;
- IPAddress^ multicastIpAddress = Dns::Resolve( "MulticastGroupName" )->AddressList[ 0 ];
- try
- {
- udpClient->JoinMulticastGroup( multicastIpAddress );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
- }
- else if ( myAction == "JoinMultiCastWithTimeToLiveExample" )
- {
- //
- UdpClient^ udpClient = gcnew UdpClient;
- // Creates an IPAddress to use to join and drop the multicast group.
- IPAddress^ multicastIpAddress = IPAddress::Parse( "239.255.255.255" );
-
- try
- {
- // The packet dies after 50 router hops.
- udpClient->JoinMulticastGroup( multicastIpAddress, 50 );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
-
- //
- // Informs the server that you want to remove yourself from the multicast client list.
- try
- {
- udpClient->DropMulticastGroup( multicastIpAddress );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
-
- //
- // Closes the UDP client by calling the public method Close().
- udpClient->Close();
- //
- }
- else
- {
- // Do nothing.
- }
- }
-};
-//end class
-
-int main()
-{
- // For our example, we will use the default constructor.
- MyUdpClientExample::MyUdpClientConstructor( "defaultExample" );
- MyUdpClientExample::MyUdpClientConnection( "HostNameAndPortNumExample" );
- MyUdpClientExample::MyUdpClientCommunicator( "EndPointExample" );
- MyUdpClientExample::MyUdpClientMulticastConfiguration( "JoinMultiCastExample" );
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UdpClientExample/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UdpClientExample/CPP/source.cpp
deleted file mode 100644
index 12a033e105e..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UdpClientExample/CPP/source.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-#using
-
-using namespace System;
-using namespace System::Text;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-int main()
-{
- //
- // With this constructor the local port number is arbitrarily assigned.
- UdpClient^ udpClient = gcnew UdpClient;
- try
- {
- udpClient->Connect( "host.contoso.com", 11000 );
-
- // Send message to the host to which you have connected.
- array^sendBytes = Encoding::ASCII->GetBytes( "Is anybody there?" );
- udpClient->Send( sendBytes, sendBytes->Length );
-
- // Send message to a different host using optional hostname and port parameters.
- UdpClient^ udpClientB = gcnew UdpClient;
- udpClientB->Send( sendBytes, sendBytes->Length, "AlternateHostMachineName", 11000 );
-
- //IPEndPoint object will allow us to read datagrams sent from any source.
- IPEndPoint^ RemoteIpEndPoint = gcnew IPEndPoint( IPAddress::Any,0 );
-
- // Block until a message returns on this socket from a remote host.
- array^receiveBytes = udpClient->Receive( RemoteIpEndPoint );
- String^ returnData = Encoding::ASCII->GetString( receiveBytes );
-
- // Use the IPEndPoint object to determine which of these two hosts responded.
- Console::WriteLine( String::Concat( "This is the message you received ", returnData->ToString() ) );
- Console::WriteLine( String::Concat( "This message was sent from ", RemoteIpEndPoint->Address->ToString(), " on their port number ", RemoteIpEndPoint->Port.ToString() ) );
- udpClient->Close();
- udpClientB->Close();
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( e->ToString() );
- }
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri Example/CPP/source.cpp
deleted file mode 100644
index 072abfddaab..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri Example/CPP/source.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Net;
-using namespace System::Net::Http;
-using namespace System::Windows::Forms;
-
-public ref class Form1: public Form
-{
-protected:
- void Method()
- {
- //
- Uri^ siteUri = gcnew Uri("http://www.contoso.com/");
-
- // HttpClient lifecycle management best practices:
- // https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
- HttpClient^ client = gcnew HttpClient;
- HttpRequestMessage^ request = gcnew HttpRequestMessage(HttpMethod::Get, siteUri);
- HttpResponseMessage^ response = client->Send(request);
- //
- }
-};
-
-void main()
-{
- Form1^ f = gcnew Form1;
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.AbsolutePath Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.AbsolutePath Example/CPP/source.cpp
deleted file mode 100644
index 1d511f22f6b..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.AbsolutePath Example/CPP/source.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-public ref class Form1: public Form
-{
-protected:
- void Method()
- {
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
- Uri^ myUri = gcnew Uri( baseUri,"catalog/shownew.htm?date=today" );
- Console::WriteLine( myUri->AbsolutePath );
- //
- }
-};
-
-void main()
-{
- Form1^ f = gcnew Form1;
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.AbsoluteUri Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.AbsoluteUri Example/CPP/source.cpp
deleted file mode 100644
index f5adb1e6dc0..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.AbsoluteUri Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com" );
- Uri^ myUri = gcnew Uri( baseUri,"catalog/shownew.htm?date=today" );
- Console::WriteLine( myUri->AbsoluteUri );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Authority Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Authority Example/CPP/source.cpp
deleted file mode 100644
index 2cb8990b9d0..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Authority Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com:8080/" );
- Uri^ myUri = gcnew Uri( baseUri,"shownew.htm?date=today" );
- Console::WriteLine( myUri->Authority );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.CheckHostName Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.CheckHostName Example/CPP/source.cpp
deleted file mode 100644
index 0d5b9b87897..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.CheckHostName Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Console::WriteLine( Uri::CheckHostName( "www.contoso.com" ) );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Host Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Host Example/CPP/source.cpp
deleted file mode 100644
index db24745352e..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Host Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com:8080/" );
- Uri^ myUri = gcnew Uri( baseUri,"shownew.htm?date=today" );
- Console::WriteLine( myUri->Host );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.PathAndQuery Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.PathAndQuery Example/CPP/source.cpp
deleted file mode 100644
index 77b48ab3d82..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.PathAndQuery Example/CPP/source.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
- Uri^ myUri = gcnew Uri( baseUri, "catalog/shownew.htm?date=today" );
-
- Console::WriteLine( myUri->PathAndQuery );
- //
-}
-
-void Method2()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
- Uri^ myUri = gcnew Uri( baseUri, "catalog/shownew.htm?date=today" );
-
- Console::WriteLine( myUri->Query );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Port Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Port Example/CPP/source.cpp
deleted file mode 100644
index 2298149c102..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Port Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
- Uri^ myUri = gcnew Uri( baseUri,"catalog/shownew.htm?date=today" );
- Console::WriteLine( myUri->Port );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Scheme Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Scheme Example/CPP/source.cpp
deleted file mode 100644
index 2a79562ae4c..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Scheme Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
- Uri^ myUri = gcnew Uri( baseUri,"catalog/shownew.htm?date=today" );
- Console::WriteLine( myUri->Scheme );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri Example/CPP/source.cpp
deleted file mode 100644
index 1977347df49..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri1 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri1 Example/CPP/source.cpp
deleted file mode 100644
index 74ea933f0d1..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri1 Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ myUri = gcnew Uri( "http://www.contoso.com/Hello%20World.htm",true );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri3 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri3 Example/CPP/source.cpp
deleted file mode 100644
index aa310799d84..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri3 Example/CPP/source.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com" );
- Uri^ myUri = gcnew Uri( baseUri, "catalog/shownew.htm" );
- Console::WriteLine( myUri->ToString() );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri4 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri4 Example/CPP/source.cpp
deleted file mode 100644
index 1cd0cad6310..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic Uri.Uri4 Example/CPP/source.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-#using
-
-using namespace System;
-void main()
-{
- //
- Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
- Uri^ myUri = gcnew Uri( baseUri,"Hello%20World.htm",false );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.Fragment Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.Fragment Example/CPP/source.cpp
deleted file mode 100644
index 7d57c1f31fb..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.Fragment Example/CPP/source.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- UriBuilder^ uBuild = gcnew UriBuilder( "http://www.contoso.com/" );
- uBuild->Path = "index.htm";
- uBuild->Fragment = "main";
- Uri^ myUri = uBuild->Uri;
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder3 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder3 Example/CPP/source.cpp
deleted file mode 100644
index 8ed7f68ec92..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder3 Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- UriBuilder^ myUri = gcnew UriBuilder( "http", "www.contoso.com" );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder4 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder4 Example/CPP/source.cpp
deleted file mode 100644
index af69e8f961a..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder4 Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- UriBuilder^ myUri = gcnew UriBuilder( "http", "www.contoso.com",8080 );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder5 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder5 Example/CPP/source.cpp
deleted file mode 100644
index 6c6a09487e1..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder5 Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- UriBuilder^ myUri = gcnew UriBuilder( "http","www.contoso.com",8080,"index.htm" );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder6 Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder6 Example/CPP/source.cpp
deleted file mode 100644
index 3e0bf14858e..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder6 Example/CPP/source.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-#using
-#using
-#using
-#using
-
-using namespace System;
-using namespace System::Data;
-using namespace System::Security::Principal;
-using namespace System::Windows::Forms;
-
-void main()
-{
- //
- UriBuilder^ myUri = gcnew UriBuilder( "http","www.contoso.com",8080,"index.htm","#top" );
- //
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic WebProxy Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic WebProxy Example/CPP/source.cpp
deleted file mode 100644
index bfcfe422816..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic WebProxy Example/CPP/source.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Net::Http;
-
-public ref class Sample
-{
-private:
- void sampleFunction()
- {
- //
- WebProxy^ proxyObject = gcnew WebProxy("http://proxyserver:80/", true);
-
- // HttpClient lifecycle management best practices:
- // https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
- HttpClientHandler^ handler = gcnew HttpClientHandler();
- handler->Proxy = proxyObject;
- HttpClient^ client = gcnew HttpClient(handler);
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic WebRequest Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic WebRequest Example/CPP/source.cpp
deleted file mode 100644
index 2a706abc691..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic WebRequest Example/CPP/source.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::Net;
-
-public ref class Sample
-{
-private:
- void sampleFunction()
- {
- //
- // Initialize the WebRequest.
- WebRequest^ myRequest = WebRequest::Create( "http://www.contoso.com" );
-
- // Return the response.
- WebResponse^ myResponse = myRequest->GetResponse();
-
- // Code to use the WebResponse goes here.
-
- // Close the response to free resources.
- myResponse->Close();
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic WebRequest.WebRequest Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic WebRequest.WebRequest Example/CPP/source.cpp
deleted file mode 100644
index ef3028f80a5..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Classic WebRequest.WebRequest Example/CPP/source.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#using
-
-using namespace System;
-using namespace System::Net;
-
-public ref class Sample
-{
-private:
- void sampleFunction()
- {
- //
- WebRequest^ myRequest = WebRequest::Create( "http://www.contoso.com" );
- //
- }
-};
diff --git a/snippets/cpp/VS_Snippets_Remoting/ClassicTcpClient.PublicMethodsAndPropertiesExample/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/ClassicTcpClient.PublicMethodsAndPropertiesExample/CPP/source.cpp
deleted file mode 100644
index 7064ebe4ae4..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/ClassicTcpClient.PublicMethodsAndPropertiesExample/CPP/source.cpp
+++ /dev/null
@@ -1,248 +0,0 @@
-
-
-#using
-
-using namespace System;
-using namespace System::Text;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-public ref class MyTcpClientExample
-{
-public:
-
- //
- // MyTcpClientConstructor is just used to illustrate the different constructors available in in the TcpClient class
- static void MyTcpClientConstructor( String^ myConstructorType )
- {
- if ( myConstructorType == "IPAddressExample" )
- {
-
- //
- //Creates a TCPClient using a local end point.
- IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ];
- IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );
- TcpClient^ tcpClientA = gcnew TcpClient( ipLocalEndPoint );
-
- //
- }
- else
- if ( myConstructorType == "HostNameExample" )
- {
-
- //
- // Creates a TCPClient using hostname and port.
- TcpClient^ tcpClientB = gcnew TcpClient( "www.contoso.com",11000 );
-
- //
- }
- else
- if ( myConstructorType == "DefaultExample" )
- {
-
- //
- //Creates a TCPClient using the default constructor.
- TcpClient^ tcpClientC = gcnew TcpClient;
-
- //
- }
- else
- {
-
- //
- TcpClient^ tcpClientD = gcnew TcpClient( AddressFamily::InterNetwork );
-
- //
- }
- }
-
-
- // MyTcpClientConnection class is just used to illustrate the different connection methods of the TcpClient class.
- static void MyTcpClientConnection( String^ myConnectionType )
- {
- if ( myConnectionType == "HostnameExample" )
- {
-
- //
- //Uses a host name and port number to establish a socket connection.
- TcpClient^ tcpClient = gcnew TcpClient;
- tcpClient->Connect( "www.contoso.com", 11002 );
-
- //
- tcpClient->Close();
- }
- else
- if ( myConnectionType == "IPAddressExample" )
- {
-
- //
- //Uses the IP address and port number to establish a socket connection.
- TcpClient^ tcpClient = gcnew TcpClient;
- IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
- tcpClient->Connect( ipAddress, 11003 );
-
- //
- tcpClient->Close();
- }
- else
- if ( myConnectionType == "RemoteEndPointExample" )
- {
-
- //
- //Uses a remote end point to establish a socket connection.
- TcpClient^ tcpClient = gcnew TcpClient;
- IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ];
- IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddress,11004 );
- tcpClient->Connect( ipEndPoint );
-
- //
- tcpClient->Close();
- }
- else
- {
-
- // Do nothing.
- }
- }
-
-
- // MyTcpClientPropertySetter is just used to illustrate setting and getting various properties of the TcpClient class.
- static void MyTcpClientPropertySetter()
- {
- TcpClient^ tcpClient = gcnew TcpClient;
-
- //
- // sets the receive buffer size using the ReceiveBufferSize public property.
- tcpClient->ReceiveBufferSize = 1024;
-
- // gets the receive buffer size using the ReceiveBufferSize public property.
- if ( tcpClient->ReceiveBufferSize == 1024 )
- Console::WriteLine( "The receive buffer was successfully set to {0}", tcpClient->ReceiveBufferSize );
-
-
- //
- //
- //sets the send buffer size using the SendBufferSize public property.
- tcpClient->SendBufferSize = 1024;
-
- // gets the send buffer size using the SendBufferSize public property.
- if ( tcpClient->SendBufferSize == 1024 )
- Console::WriteLine( "The send buffer was successfully set to {0}", tcpClient->SendBufferSize );
-
-
- //
- //
- // Sets the receive time out using the ReceiveTimeout public property.
- tcpClient->ReceiveTimeout = 5;
-
- // Gets the receive time out using the ReceiveTimeout public property.
- if ( tcpClient->ReceiveTimeout == 5 )
- Console::WriteLine( "The receive time out limit was successfully set {0}", tcpClient->ReceiveTimeout );
-
-
- //
- //
- // sets the send time out using the SendTimeout public property.
- tcpClient->SendTimeout = 5;
-
- // gets the send time out using the SendTimeout public property.
- if ( tcpClient->SendTimeout == 5 )
- Console::WriteLine( "The send time out limit was successfully set {0}", tcpClient->SendTimeout );
-
-
- //
- //
- // sets the amount of time to linger after closing, using the LingerOption public property.
- LingerOption^ lingerOption = gcnew LingerOption( true,10 );
- tcpClient->LingerState = lingerOption;
-
- // gets the amount of linger time set, using the LingerOption public property.
- if ( tcpClient->LingerState->LingerTime == 10 )
- Console::WriteLine( "The linger state setting was successfully set to {0}", tcpClient->LingerState->LingerTime );
-
-
- //
- //
- // Sends data immediately upon calling NetworkStream.Write.
- tcpClient->NoDelay = true;
-
- // Determines if the delay is enabled by using the NoDelay property.
- if ( tcpClient->NoDelay)
- Console::WriteLine( "The delay was set successfully to {0}", tcpClient->NoDelay );
-
-
- //
- tcpClient->Close();
- }
-
- static void MyTcpClientCommunicator()
- {
-
- //
- TcpClient^ tcpClient = gcnew TcpClient;
-
- // Uses the GetStream public method to return the NetworkStream.
- NetworkStream^ netStream = tcpClient->GetStream();
- if ( netStream->CanWrite )
- {
- array^sendBytes = Encoding::UTF8->GetBytes( "Is anybody there?" );
- netStream->Write( sendBytes, 0, sendBytes->Length );
- }
- else
- {
- Console::WriteLine( "You cannot write data to this stream." );
- tcpClient->Close();
-
- // Closing the tcpClient instance does not close the network stream.
- netStream->Close();
- return;
- }
-
- if ( netStream->CanRead )
- {
-
- // Reads NetworkStream into a byte buffer.
- array^bytes = gcnew array(tcpClient->ReceiveBufferSize);
-
- // Read can return anything from 0 to numBytesToRead.
- // This method blocks until at least one byte is read.
- netStream->Read( bytes, 0, (int)tcpClient->ReceiveBufferSize );
-
- // Returns the data received from the host to the console.
- String^ returndata = Encoding::UTF8->GetString( bytes );
- Console::WriteLine( "This is what the host returned to you: {0}", returndata );
- }
- else
- {
- Console::WriteLine( "You cannot read data from this stream." );
- tcpClient->Close();
-
- // Closing the tcpClient instance does not close the network stream.
- netStream->Close();
- return;
- }
-
-
- //
- }
-
-};
-
-
-//end class
-int main()
-{
-
- // Using the default constructor.
- MyTcpClientExample::MyTcpClientConstructor( "DefaultExample" );
-
- // Establish a connection by using the hostname and port number.
- MyTcpClientExample::MyTcpClientConnection( "HostnameExample" );
-
- // Set and verify all communication parameters before attempting communication.
- MyTcpClientExample::MyTcpClientPropertySetter();
-
- // Send and receive data using tcpClient class.
- MyTcpClientExample::MyTcpClientCommunicator();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/CookieCollection_Item_1/CPP/CookieCollection_Item_1.cpp b/snippets/cpp/VS_Snippets_Remoting/CookieCollection_Item_1/CPP/CookieCollection_Item_1.cpp
deleted file mode 100644
index 14edae82980..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/CookieCollection_Item_1/CPP/CookieCollection_Item_1.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-
-
-/*
-This program demonstrates 'Item(string)' and 'Count' properties of 'CookieCollection' class.
-
-This program uses an internal site called "CookiesServer.aspx". The program creates a 'HttpWebRequest'
-object with the 'URL' taken from command line argument. When no cookies are initially sent to
-the server, it responds with a specific page querying the client for information. The client queries
-this information from the user and sends it to the server in the second request. This information is
-used by the server to not only structure the page sent subsequently but also construct some cookies to be
-set by the client, for future requests. The response and the cookies that are sent from the server are
-displayed to the console.
-
-Note: This program requires the "CookiesServer.aspx" server to be running before the execution of this
-program.Please refer the "ReadmeCookiesServer.txt" file for setting up the server.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-using namespace System::Text::RegularExpressions;
-void DisplayCookies( CookieCollection^ cookies )
-{
- //
- //
- // Get the cookies in the 'CookieCollection' object using the 'Item' property.
- // The 'Item' property in C++ is implemented through Indexers.
- // The class that implements indexers is usually a collection of other objects.
- // This class provides access to those objects with the '[i]' syntax.
- try
- {
- if ( cookies->Count == 0 )
- {
- Console::WriteLine( "No cookies to display" );
- return;
- }
-
- Console::WriteLine( "{0}", cookies[ "UserName" ] );
- Console::WriteLine( "{0}", cookies[ "DateOfBirth" ] );
- Console::WriteLine( "{0}", cookies[ "PlaceOfBirth" ] );
- Console::WriteLine( "" );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
- }
- //
- //
-}
-
-void printUsage()
-{
- Console::WriteLine( "Usage : " );
- Console::WriteLine( "CookieCollection_Item_1 " );
- Console::WriteLine( " is the name of the CookiesServer.aspx site installed locally" );
- Console::WriteLine( "\nExample : CookieCollection_Item_1 http://www.MyServer.com/CookiesServer.aspx" );
-}
-
-void GetPage( Uri^ requestUri )
-{
- try
- {
- array^output = gcnew array(120);
- Stream^ myStream;
- Encoding^ asciiEncoding = gcnew ASCIIEncoding;
-
- // Create the request.
- HttpWebRequest^ myHttpWebRequest = dynamic_cast(WebRequest::Create( requestUri ));
-
- // Get the response without any cookies sent to the server.
- HttpWebResponse^ myHttpWebResponse = dynamic_cast(myHttpWebRequest->GetResponse());
- String^ usrName;
- String^ dateBirth;
- String^ placeBirth;
-
- // Get the information from the user as requested by the server and send it over to the server.
- myHttpWebRequest = dynamic_cast(WebRequest::Create( requestUri ));
- myHttpWebRequest->Method = "POST";
- myHttpWebRequest->ContentType = "application/x-www-form-urlencoded";
- Console::WriteLine( "\nEnter the values to be sent to the server :\n" );
- Console::Write( "UserName : " );
- usrName = Console::ReadLine();
- Console::Write( "\nDateOfBirth [dd/mm/yyyy]: " );
- dateBirth = Console::ReadLine();
- Regex^ regex = gcnew Regex( "/" );
- String^ convertDate = regex->Replace( dateBirth, "%2F" );
- Console::Write( "\nPlaceOfBirth : " );
- placeBirth = Console::ReadLine();
- Console::WriteLine( "" );
- output = asciiEncoding->GetBytes( String::Format( "UserName={0}&DateOfBirth={1}&PlaceOfBirth={2}&__EVENTTARGET=PlaceOfBirth&__EVENTARGUMENT=", usrName, convertDate, placeBirth ) );
- myHttpWebRequest->ContentLength = output->Length;
- myStream = myHttpWebRequest->GetRequestStream();
- myStream->Write( output, 0, output->Length );
- myStream->Close();
- myHttpWebResponse->Close();
-
- // Get the response.
- myHttpWebResponse = dynamic_cast(myHttpWebRequest->GetResponse());
-
- // Output the response to the console.
- myStream = myHttpWebResponse->GetResponseStream();
- Console::WriteLine( "Displaying the contents of the page of '{0}' site:", requestUri );
- Console::WriteLine( "" );
- int bytesRead = 0;
- while ( (bytesRead = myStream->Read( output, 0, output->Length )) != 0 )
- Console::Write( asciiEncoding->GetString( output, 0, bytesRead ) );
- Console::WriteLine( "" );
- Console::WriteLine( "\nDisplaying the cookies in the response : " );
- Console::WriteLine( "" );
- DisplayCookies( myHttpWebResponse->Cookies );
- myHttpWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "WebException raised.\nError : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
- }
-
-}
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- try
- {
- if ( args->Length < 2 )
- {
- printUsage();
- return 0;
- }
- GetPage( gcnew Uri( args[ 1 ] ) );
- }
- catch ( UriFormatException^ e )
- {
- Console::WriteLine( "UriFormatException raised.\nError : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
- }
-
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/CookieCollection_Item_2/CPP/CookieCollection_Item_2.cpp b/snippets/cpp/VS_Snippets_Remoting/CookieCollection_Item_2/CPP/CookieCollection_Item_2.cpp
deleted file mode 100644
index 5f84293fef8..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/CookieCollection_Item_2/CPP/CookieCollection_Item_2.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-
-
-/*
-This program demonstrates 'Item(int)' properties of 'CookieCollection' class.
-
-This program uses an internal site called "CookiesServer.aspx". The program creates a 'HttpWebRequest'
-object with the 'URL' taken from command line argument. When no cookies are initially sent to
-the server, it responds with a specific page querying the client for information. The client queries
-this information from the user and sends it to the server in the second request. This information is
-used by the server to not only structure the page sent subsequently but also construct some cookies to be
-set by the client, for future requests. The response and the cookies that are sent from the server are
-displayed to the console.
-
-Note: This program requires the "CookiesServer.aspx" server to be running before the execution of this
-program.Please refer the "ReadmeCookiesServer.txt" file for setting up the server.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-using namespace System::Text::RegularExpressions;
-void DisplayCookies( CookieCollection^ cookies )
-{
- //
- // Get the cookies in the 'CookieCollection' object using the 'Item' property.
- // The 'Item' property in C++ is implemented through Indexers.
- // The class that implements indexers is usually a collection of other objects.
- // This class provides access to those objects with the '[i]' syntax.
- try
- {
- if ( cookies->Count == 0 )
- {
- Console::WriteLine( "No cookies to display" );
- return;
- }
-
- for ( int j = 0; j < cookies->Count; j++ )
- Console::WriteLine( "{0}", cookies[ j ] );
- Console::WriteLine( "" );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
- }
- //
-}
-
-void GetPage( Uri^ requestUri )
-{
- try
- {
- array^output = gcnew array(120);
- Stream^ myStream;
- Encoding^ asciiEncoding = gcnew ASCIIEncoding;
-
- // Create the request.
- HttpWebRequest^ myHttpWebRequest = dynamic_cast(WebRequest::Create( requestUri ));
-
- // Get the response without any cookies sent to the server.
- HttpWebResponse^ myHttpWebResponse = dynamic_cast(myHttpWebRequest->GetResponse());
- String^ usrName;
- String^ dateBirth;
- String^ placeBirth;
-
- // Get the information from the user as requested by the server and send it over to the server.
- myHttpWebRequest = dynamic_cast(WebRequest::Create( requestUri ));
- myHttpWebRequest->Method = "POST";
- myHttpWebRequest->ContentType = "application/x-www-form-urlencoded";
- Console::WriteLine( "\nEnter the values to be sent to the server :\n" );
- Console::Write( "UserName : " );
- usrName = Console::ReadLine();
- Console::Write( "\nDateOfBirth [dd/mm/yyyy]: " );
- dateBirth = Console::ReadLine();
- Regex^ regex = gcnew Regex( "/" );
- String^ convertDate = regex->Replace( dateBirth, "%2F" );
- Console::Write( "\nPlaceOfBirth : " );
- placeBirth = Console::ReadLine();
- Console::WriteLine( "" );
- output = asciiEncoding->GetBytes( String::Format( "UserName={0}&DateOfBirth={1}&PlaceOfBirth={2}&__EVENTTARGET=PlaceOfBirth&__EVENTARGUMENT=", usrName, convertDate, placeBirth ) );
- myHttpWebRequest->ContentLength = output->Length;
- myStream = myHttpWebRequest->GetRequestStream();
- myStream->Write( output, 0, output->Length );
- myStream->Close();
- myHttpWebResponse->Close();
-
- // Get the response.
- myHttpWebResponse = dynamic_cast(myHttpWebRequest->GetResponse());
-
- // Output the response to the console.
- myStream = myHttpWebResponse->GetResponseStream();
- Console::WriteLine( "Displaying the contents of the page of '{0}' site:", requestUri );
- Console::WriteLine( "" );
- int bytesRead = 0;
- while ( (bytesRead = myStream->Read( output, 0, output->Length )) != 0 )
- Console::Write( asciiEncoding->GetString( output, 0, bytesRead ) );
- Console::WriteLine( "" );
- Console::WriteLine( "\nDisplaying the cookies in the response : " );
- Console::WriteLine( "" );
- DisplayCookies( myHttpWebResponse->Cookies );
- myHttpWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "WebException raised.\nError : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
- }
-
-}
-
-void printUsage()
-{
- Console::WriteLine( "Usage : " );
- Console::WriteLine( "CookieCollection_Item_2 " );
- Console::WriteLine( " is the name of the CookiesServer.aspx site installed locally" );
- Console::WriteLine( "\nExample : CookieCollection_Item_2 http://www.MyServer.com/CookiesServer.aspx" );
-}
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- try
- {
- if ( args->Length < 2 )
- {
- printUsage();
- return 0;
- }
- GetPage( gcnew Uri( args[ 1 ] ) );
- }
- catch ( UriFormatException^ e )
- {
- Console::WriteLine( "UriFormatException raised.\nError : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised.\nError : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_Add_Remove/CPP/credentialcache_add_remove.cpp b/snippets/cpp/VS_Snippets_Remoting/CredentialCache_Add_Remove/CPP/credentialcache_add_remove.cpp
deleted file mode 100644
index 30b79abc081..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_Add_Remove/CPP/credentialcache_add_remove.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-// System::Net::CredentialCache->Add;System::Net::CredentialCache::CredentialCache();
-// System::Net::CredentialCache::Remove;System::Net::CredentialCache.
-
-/*This program demontrates the 'Remove' method, 'Add' method and 'CredentialCache'
-constructor of the 'CredentialCache' class. It takes an URL creates a 'WebRequest' Object* for the Url.
-The program stores a known set of credentials in a credential cache and removes a credential when it
-is no longer needed.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-
-void GetPage( String^ url, String^ userName, String^ password, String^ domainName )
-{
- try
- {
-//
-//
- CredentialCache^ myCredentialCache = gcnew CredentialCache;
- // Used Dummy names as credentials. They are to be replaced by credentials applicable locally.
- myCredentialCache->Add( gcnew Uri( "http://www.microsoft.com/" ), "Basic", gcnew NetworkCredential( "user1","passwd1","domain1" ) );
- myCredentialCache->Add( gcnew Uri( "http://www.msdn.com/" ), "Basic", gcnew NetworkCredential( "user2","passwd2","domain2" ) );
- myCredentialCache->Add( gcnew Uri( url ), "Basic", gcnew NetworkCredential( userName,password,domainName ) );
- Console::WriteLine( "\nAdded your credentials to the program's CredentialCache" );
-//
-//
- // Create a webrequest with the specified url.
- WebRequest^ myWebRequest = WebRequest::Create( url );
- myWebRequest->Credentials = myCredentialCache;
- Console::WriteLine( "\nLinked CredentialCache to your request." );
- // Send the request and wait for response.
- WebResponse^ myWebResponse = myWebRequest->GetResponse();
-//
-
- // Process response here.
-
- Console::Write( "Response received successfully." );
-
- // Call 'Remove' method to dispose credentials for current Uri as not required further.
- myCredentialCache->Remove( myWebRequest->RequestUri, "Basic" );
- Console::WriteLine( "\nYour credentials have now been removed from the program's CredentialCache" );
- myWebResponse->Close();
-//
- }
- catch ( WebException^ e )
- {
- if ( e->Response != nullptr )
- {
- Console::WriteLine( "\r\nFailed to obtain a response. The following error occurred : {0}", (dynamic_cast(e->Response))->StatusDescription );
- }
- else
- {
- Console::WriteLine( "\r\nFailed to obtain a response. The following error occurred : {0}", e->Status );
- }
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following exception was raised : {0}", e->Message );
- }
-
-}
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- if ( args->Length < 4 )
- {
- Console::WriteLine( "\n Usage:" );
- Console::WriteLine( "\n CredentialCache_Add_Remove " );
- Console::WriteLine( "\n Example: CredentialCache_Add_Remove http://www.microsoft.com Catherine cath$ microsoft" );
- }
- else if ( args->Length == 4 )
- GetPage( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ] );
- else
- {
- Console::WriteLine( "\nInvalid arguments." );
- return 0;
- }
-
- Console::WriteLine( " Press any key to continue..." );
- Console::ReadLine();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_DefaultCredentials/CPP/credentialcache_defaultcredentials.cpp b/snippets/cpp/VS_Snippets_Remoting/CredentialCache_DefaultCredentials/CPP/credentialcache_defaultcredentials.cpp
deleted file mode 100644
index 778e10ae046..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_DefaultCredentials/CPP/credentialcache_defaultcredentials.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-
-
-// System::Net::CredentialCache::DefaultCredentials.
-/* This program demonstrates the 'DefaultCredentials' property of the 'CredentialCache'
-class.
-Creates an 'HttpWebRequest' Object* to access the local Uri S"http://localhost"(IIS documentation start page)
-Assigns the static property 'DefaultCredentials' of 'CredentialCache' as 'Credentials' for the 'HttpWebRequest'
-Object*. DefaultCredentials returns the system credentials for the current security context in which
-the application is running. For a client-side application, these are usually the Windows credentials
-(user name, password, and domain) of the user running the application.
-These credentials are used internally to authenticate the request.
-The html contents of the start page are displayed to the console.
-
-Note: Make sure that S"Windows Authentication" has been set as Directory Security settings
-for default web site in IIS
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-
-int main()
-{
- try
- {
- //
- // Ensure Directory Security settings for default web site in IIS is "Windows Authentication".
- String^ url = "http://localhost";
-
- // Create a 'HttpWebRequest' object with the specified url.
- HttpWebRequest^ myHttpWebRequest = dynamic_cast(WebRequest::Create( url ));
-
- // Assign the credentials of the logged in user or the user being impersonated.
- myHttpWebRequest->Credentials = CredentialCache::DefaultCredentials;
-
- // Send the 'HttpWebRequest' and wait for response.
- HttpWebResponse^ myHttpWebResponse = dynamic_cast(myHttpWebRequest->GetResponse());
- Console::WriteLine( "Authentication successful" );
- Console::WriteLine( "Response received successfully" );
-
- //
- Console::WriteLine( "\nPress enter to continue" );
- Console::ReadLine();
-
- // Get the stream associated with the response object.
- Stream^ receiveStream = myHttpWebResponse->GetResponseStream();
- Encoding^ encode = System::Text::Encoding::GetEncoding( "utf-8" );
-
- // Pipe the stream to a higher level stream reader with the required encoding format.
- StreamReader^ readStream = gcnew StreamReader( receiveStream,encode );
- Console::WriteLine( "\r\nResponse stream received" );
- array^read = gcnew array(256);
-
- // Read 256 characters at a time.
- int count = readStream->Read( read, 0, 256 );
- Console::WriteLine( "HTML...\r\n" );
- while ( count > 0 )
- {
- // Dump the 256 characters on a string and display the string onto the console.
- String^ output = gcnew String( read,0,count );
- Console::Write( output );
- count = readStream->Read( read, 0, 256 );
- }
- Console::WriteLine( "" );
-
- // Release the resources of response Object*.
- myHttpWebResponse->Close();
-
- // Release the resources of stream Object*.
- readStream->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\r\nException Raised. The following error occurred : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following exception was raised : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_GetCredential/CPP/credentialcache_getcredential.cpp b/snippets/cpp/VS_Snippets_Remoting/CredentialCache_GetCredential/CPP/credentialcache_getcredential.cpp
deleted file mode 100644
index f38f54663af..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_GetCredential/CPP/credentialcache_getcredential.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-
-
-// System::Net::CredentialCache::GetCredential
-/*This program demontrates the 'GetCredential' method of the CredentialCache class. It takes an URL
-creates a 'WebRequest' Object* for the Url. The program stores a known set of credentials in a credential cache.
-'GetCredential' will then retrieve the credentials for the requested Uri.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Collections;
-
-//
-void Display( NetworkCredential^ credential )
-{
- Console::WriteLine( "\nThe credentials are:" );
- Console::WriteLine( "\nUsername : {0} , Password : {1} , Domain : {2}", credential->UserName, credential->Password, credential->Domain );
-}
-
-void GetPage( String^ url, String^ userName, String^ password, String^ domainName )
-{
- try
- {
- CredentialCache^ myCredentialCache = gcnew CredentialCache;
-
- // Dummy names used as credentials.
- myCredentialCache->Add( gcnew Uri( "http://microsoft.com/" ), "Basic", gcnew NetworkCredential( "user1","passwd1","domain1" ) );
- myCredentialCache->Add( gcnew Uri( "http://msdn.com/" ), "Basic", gcnew NetworkCredential( "user2","passwd2","domain2" ) );
- myCredentialCache->Add( gcnew Uri( url ), "Basic", gcnew NetworkCredential( userName,password,domainName ) );
-
- // Create a webrequest with the specified url.
- WebRequest^ myWebRequest = WebRequest::Create( url );
-
- // Call 'GetCredential' to obtain the credentials specific to our Uri.
- NetworkCredential^ myCredential = myCredentialCache->GetCredential( gcnew Uri( url ), "Basic" );
- Display( myCredential );
-
- // Associating only our credentials.
- myWebRequest->Credentials = myCredential;
-
- // Sends the request and waits for response.
- WebResponse^ myWebResponse = myWebRequest->GetResponse();
-
- // Process response here.
- Console::WriteLine( "\nResponse Received." );
- myWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- if ( e->Response != nullptr )
- Console::WriteLine( "\r\nFailed to obtain a response. The following error occurred : {0}", (dynamic_cast(e->Response))->StatusDescription );
- else
- Console::WriteLine( "\r\nFailed to obtain a response. The following error occurred : {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following exception was raised : {0}", e->Message );
- }
-}
-//
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- if ( args->Length < 4 )
- {
- Console::WriteLine( "\n Usage:" );
- Console::WriteLine( "\n CredentialCache_GetCredential " );
- Console::WriteLine( "\n Example: CredentialCache_GetCredential http://www.microsoft.com Catherine cath$ microsoft" );
- }
- else
- if ( (args->Length == 4) )
- {
- GetPage( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ] );
- }
- else
- {
- Console::WriteLine( "\nInvalid arguments." );
- return 0;
- }
-
- Console::WriteLine( "Press any key to continue..." );
- Console::ReadLine();
- return 0;
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_GetEnumerator/CPP/credentialcache_getenumerator.cpp b/snippets/cpp/VS_Snippets_Remoting/CredentialCache_GetEnumerator/CPP/credentialcache_getenumerator.cpp
deleted file mode 100644
index 86beeaa5a72..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/CredentialCache_GetEnumerator/CPP/credentialcache_getenumerator.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
-// System::Net::CredentialCache::GetEnumerator
-/*This program demontrates the 'GetEnumerator' method of the CredentialCache class.
-It takes an URL, creates a 'WebRequest' Object* for the Url. The program stores a known set of credentials
-in a credential cache which is then bound to the request. If the url requested has it's credentials in the cache
-the response will be OK . 'GetEnumerator' method is used to enlist all the credentials stored in the
-'CredentialCache' Object*.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Collections;
-
-//
-void Display( NetworkCredential^ credential )
-{
- Console::WriteLine( "\n\tUsername : {0} , Password : {1} , Domain : {2}", credential->UserName, credential->Password, credential->Domain );
-}
-
-void GetPage( String^ url, String^ userName, String^ password, String^ domainName )
-{
- try
- {
- CredentialCache^ myCredentialCache = gcnew CredentialCache;
-
- // Dummy Credentials used here.
- myCredentialCache->Add( gcnew Uri( "http://microsoft.com/" ), "Basic", gcnew NetworkCredential( "user1","passwd1","domain1" ) );
- myCredentialCache->Add( gcnew Uri( "http://msdn.com/" ), "Basic", gcnew NetworkCredential( "user2","passwd2","domain2" ) );
- myCredentialCache->Add( gcnew Uri( url ), "Basic", gcnew NetworkCredential( userName,password,domainName ) );
-
- // Creates a webrequest with the specified url.
- WebRequest^ myWebRequest = WebRequest::Create( url );
- myWebRequest->Credentials = myCredentialCache;
- IEnumerator^ listCredentials = myCredentialCache->GetEnumerator();
- Console::WriteLine( "\nDisplaying credentials stored in CredentialCache: " );
- while ( listCredentials->MoveNext() )
- Display( dynamic_cast(listCredentials->Current) );
- Console::WriteLine( "\nNow Displaying the same using 'foreach' : " );
-
- // Can use foreach with CredentialCache(Since GetEnumerator function of IEnumerable* has been implemented by 'CredentialCache' class.
- IEnumerator^ myEnum = myCredentialCache->GetEnumerator();
- while ( myEnum->MoveNext() )
- {
- NetworkCredential^ credential = safe_cast(myEnum->Current);
- Display( credential );
- }
- WebResponse^ myWebResponse = myWebRequest->GetResponse();
-
- // Process response here.
- Console::WriteLine( "\nResponse Received." );
- myWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- if ( e->Response != nullptr )
- Console::WriteLine( "\r\nFailed to obtain a response. The following error occurred : {0}", (dynamic_cast(e->Response))->StatusDescription );
- else
- Console::WriteLine( "\r\nFailed to obtain a response. The following error occurred : {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following exception was raised : {0}", e->Message );
- }
-}
-//
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- if ( args->Length < 4 )
- {
- Console::WriteLine( "\n Usage:" );
- Console::WriteLine( "\n CredentialCache_GetEnumerator " );
- Console::WriteLine( "\n Example: CredentialCache_GetEnumerator http://www.microsoft.com Catherine cath$ microsoft" );
- }
- else
- if ( args->Length == 4 )
- {
- GetPage( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ] );
- }
- else
- {
- Console::WriteLine( "\n Invalid arguments." );
- return 0;
- }
-
- Console::WriteLine( "Press any key to continue..." );
- Console::ReadLine();
- return 0;
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_Constructor/CPP/dnspermission_constructor.cpp b/snippets/cpp/VS_Snippets_Remoting/DnsPermission_Constructor/CPP/dnspermission_constructor.cpp
deleted file mode 100644
index cfe2812f5b9..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_Constructor/CPP/dnspermission_constructor.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
-This program demonstrates the 'Constructor' of 'DnsPermission' class.
-It creates an instance of 'DnsPermission' class and checks for permission.Then it
-creates a 'SecurityElement' Object* and prints it's attributes which hold the XML
-encoding of 'DnsPermission' instance .
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-using namespace System::Collections;
-
-public ref class DnsPermissionExample
-{
- //
-public:
- void useDns()
- {
- // Create a DnsPermission instance.
- DnsPermission^ permission = gcnew DnsPermission( PermissionState::Unrestricted );
-
- // Check for permission.
- permission->Demand();
- // Create a SecurityElement Object* to hold XML encoding of the DnsPermission instance.
- SecurityElement^ securityElementObj = permission->ToXml();
- Console::WriteLine( "Tag, Attributes and Values of 'DnsPermission' instance :" );
- Console::WriteLine( "\n\tTag : {0}", securityElementObj->Tag );
- // Print the attributes and values.
- PrintKeysAndValues( securityElementObj->Attributes );
- }
-
-private:
- void PrintKeysAndValues( Hashtable^ myList )
- {
- // Get the enumerator that can iterate through the hash table.
- IDictionaryEnumerator^ myEnumerator = myList->GetEnumerator();
- Console::WriteLine( "\n\t-KEY-\t-VALUE-" );
- while ( myEnumerator->MoveNext() )
- {
- Console::WriteLine( "\t {0}:\t {1}", myEnumerator->Key, myEnumerator->Value );
- }
- Console::WriteLine();
- }
- //
-};
-
-int main()
-{
- try
- {
- DnsPermissionExample^ dnsPermissionExampleObj = gcnew DnsPermissionExample;
- dnsPermissionExampleObj->useDns();
- }
- catch ( SecurityException^ e )
- {
- Console::WriteLine( "SecurityException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_Copy/CPP/dnspermission_copy.cpp b/snippets/cpp/VS_Snippets_Remoting/DnsPermission_Copy/CPP/dnspermission_copy.cpp
deleted file mode 100644
index 0e9c78efb39..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_Copy/CPP/dnspermission_copy.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
-This program demonstrates the 'Copy' method of 'DnsPermission' class.
-It creates an identical copy of 'DnsPermission' instance.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-using namespace System::Collections;
-
-class DnsPermissionExample
-{
- //
-public:
- void UseDns()
- {
- // Create a DnsPermission instance.
- DnsPermission^ myPermission = gcnew DnsPermission( PermissionState::Unrestricted );
- // Check for permission.
- myPermission->Demand();
- // Create an identical copy of the above 'DnsPermission' Object*.
- DnsPermission^ myPermissionCopy = dynamic_cast(myPermission->Copy());
- Console::WriteLine( "Attributes and Values of 'DnsPermission' instance :" );
- // Print the attributes and values.
- PrintKeysAndValues( myPermission->ToXml()->Attributes );
- Console::WriteLine( "Attribute and values of copied instance :" );
- PrintKeysAndValues( myPermissionCopy->ToXml()->Attributes );
- }
-
-private:
- void PrintKeysAndValues( Hashtable^ myHashtable )
- {
- // Get the enumerator that can iterate through the hash table.
- IDictionaryEnumerator^ myEnumerator = myHashtable->GetEnumerator();
- Console::WriteLine( "\t-KEY-\t-VALUE-" );
- while ( myEnumerator->MoveNext() )
- {
- Console::WriteLine( "\t {0}:\t {1}", myEnumerator->Key, myEnumerator->Value );
- }
- Console::WriteLine();
- }
- //
-};
-
-int main()
-{
- try
- {
- DnsPermissionExample * dnsPermissionExampleObj = new DnsPermissionExample;
- dnsPermissionExampleObj->UseDns();
- }
- catch ( SecurityException^ e )
- {
- Console::WriteLine( "SecurityException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_FromXml/CPP/dnspermission_fromxml.cpp b/snippets/cpp/VS_Snippets_Remoting/DnsPermission_FromXml/CPP/dnspermission_fromxml.cpp
deleted file mode 100644
index 3674b00df6c..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_FromXml/CPP/dnspermission_fromxml.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
-This program demonstrates the 'FromXml' method of 'DnsPermission' class.
-It creates an instance of 'DnsPermission' class and prints the XML encoding of that instance.Then it
-creates a 'SecurityElement' Object* and adds the attributes corresponding to the above 'DnsPermission'
-Object*. A new 'DnsPermission' instance is reconstructed from the 'SecurityElement' instance by calling
-'FromXml' method and it's XML encoding is printed.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-using namespace System::Collections;
-
-public ref class DnsPermissionExample
-{
- //
-public:
- void ConstructDnsPermission()
- {
- try
- {
- // Create a DnsPermission instance.
- DnsPermission^ permission = gcnew DnsPermission( PermissionState::None );
- // Create a SecurityElement instance by calling the ToXml method on the
- // DnsPermission instance.
- // Print its attributes, which hold the XML encoding of the DnsPermission
- // instance.
- Console::WriteLine( "Attributes and Values of 'DnsPermission' instance :" );
- PrintKeysAndValues( permission->ToXml()->Attributes );
-
- // Create a SecurityElement instance.
- SecurityElement^ securityElementObj = gcnew SecurityElement( "IPermission" );
- // Add attributes and values of the SecurityElement instance corresponding to
- // the permission instance.
- securityElementObj->AddAttribute( "version", "1" );
- securityElementObj->AddAttribute( "Unrestricted", "true" );
- securityElementObj->AddAttribute( "class", "System.Net.DnsPermission" );
-
- // Reconstruct a DnsPermission instance from an XML encoding.
- DnsPermission^ permission1 = gcnew DnsPermission( PermissionState::None );
- permission1->FromXml( securityElementObj );
-
- // Print the attributes and values of the constructed DnsPermission Object*.
- Console::WriteLine( "After reconstruction Attributes and Values of new DnsPermission instance :" );
- PrintKeysAndValues( permission1->ToXml()->Attributes );
- }
- catch ( NullReferenceException^ e )
- {
- Console::WriteLine( "NullReferenceException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( SecurityException^ e )
- {
- Console::WriteLine( "SecurityException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "ArgumentNullException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- }
-
-private:
- void PrintKeysAndValues( Hashtable^ myList )
- {
- // Get the enumerator that can iterate through the hash table.
- IDictionaryEnumerator^ myEnumerator = myList->GetEnumerator();
- Console::WriteLine( "\t-KEY-\t-VALUE-" );
- while ( myEnumerator->MoveNext() )
- {
- Console::WriteLine( "\t {0}:\t {1}", myEnumerator->Key, myEnumerator->Value );
- }
- Console::WriteLine();
- }
- //
-};
-
-int main()
-{
- DnsPermissionExample^ dnsPermissionExampleObj = gcnew DnsPermissionExample;
- dnsPermissionExampleObj->ConstructDnsPermission();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_IsSubsetOf/CPP/dnspermission_issubsetof.cpp b/snippets/cpp/VS_Snippets_Remoting/DnsPermission_IsSubsetOf/CPP/dnspermission_issubsetof.cpp
deleted file mode 100644
index 929717f0e2e..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_IsSubsetOf/CPP/dnspermission_issubsetof.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
-This program demonstrates the 'IsSubsetOf' method of 'DnsPermission' class.
-'IsSubsetOf' method returns true, if the current DnsPermission instance allows no
-more access to DNS servers than does the specified 'DnsPermission' instance.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-using namespace System::Collections;
-
-public ref class DnsPermissionExample
-{
-private:
- DnsPermission^ permission;
-
- //
-public:
- void useDns()
- {
- // Create a DnsPermission instance.
- permission = gcnew DnsPermission( PermissionState::Unrestricted );
- DnsPermission^ dnsPermission1 = gcnew DnsPermission( PermissionState::None );
- // Check for permission.
- permission->Demand();
- dnsPermission1->Demand();
- // Print the attributes and values.
- Console::WriteLine( "Attributes and Values of 'DnsPermission' instance :" );
- PrintKeysAndValues( permission->ToXml()->Attributes );
- Console::WriteLine( "Attributes and Values of specified 'DnsPermission' instance :" );
- PrintKeysAndValues( dnsPermission1->ToXml()->Attributes );
- Subset( dnsPermission1 );
- }
-
-private:
- void Subset( DnsPermission^ Permission1 )
- {
- if ( permission->IsSubsetOf( Permission1 ) )
- {
- Console::WriteLine( "Current 'DnsPermission' instance is a subset of specified 'DnsPermission' instance." );
- }
- else
- {
- Console::WriteLine( "Current 'DnsPermission' instance is not a subset of specified 'DnsPermission' instance." );
- }
- }
-
- void PrintKeysAndValues( Hashtable^ myList )
- {
- // Get the enumerator that can iterate through the hash table.
- IDictionaryEnumerator^ myEnumerator = myList->GetEnumerator();
- Console::WriteLine( "\t-KEY-\t-VALUE-" );
- while ( myEnumerator->MoveNext() )
- {
- Console::WriteLine( "\t {0}:\t {1}", myEnumerator->Key, myEnumerator->Value );
- }
- Console::WriteLine();
- }
- //
-};
-
-int main()
-{
- try
- {
- DnsPermissionExample^ dnsPermissionExampleObj = gcnew DnsPermissionExample;
- dnsPermissionExampleObj->useDns();
- }
- catch ( SecurityException^ e )
- {
- Console::WriteLine( "SecurityException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_IsUnrestricted/CPP/dnspermission_isunrestricted.cpp b/snippets/cpp/VS_Snippets_Remoting/DnsPermission_IsUnrestricted/CPP/dnspermission_isunrestricted.cpp
deleted file mode 100644
index 0c760523b02..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/DnsPermission_IsUnrestricted/CPP/dnspermission_isunrestricted.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
-This program demonstrates the 'IsUnrestricted' method of 'DnsPermission' class.
-It checks the overall permission state of the Object* and it will return true if the
-'DnsPermission' instance was created with unrestricted permission state otherwise false.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Security;
-using namespace System::Security::Permissions;
-using namespace System::Collections;
-
-public ref class DnsPermissionExample
-{
- //
-public:
- void useDns()
- {
- // Create a DnsPermission instance.
- DnsPermission^ permission = gcnew DnsPermission( PermissionState::Unrestricted );
- // Check for permission.
- permission->Demand();
- Console::WriteLine( "Attributes and Values of DnsPermission instance :" );
- // Print the attributes and values.
- PrintKeysAndValues( permission->ToXml()->Attributes );
- // Check the permission state.
- if ( permission->IsUnrestricted() )
- {
- Console::WriteLine( "Overall permissions : Unrestricted" );
- }
- else
- {
- Console::WriteLine( "Overall permissions : Restricted" );
- }
- }
-
-private:
- void PrintKeysAndValues( Hashtable^ myList )
- {
- // Get the enumerator that can iterate through the hash table.
- IDictionaryEnumerator^ myEnumerator = myList->GetEnumerator();
- Console::WriteLine( "\t-KEY-\t-VALUE-" );
- while ( myEnumerator->MoveNext() )
- {
- Console::WriteLine( "\t {0}:\t {1}", myEnumerator->Key, myEnumerator->Value );
- }
- Console::WriteLine();
- }
- //
-};
-
-int main()
-{
- try
- {
- DnsPermissionExample^ dnsPermissionExampleObj = gcnew DnsPermissionExample;
- dnsPermissionExampleObj->useDns();
- }
- catch ( SecurityException^ e )
- {
- Console::WriteLine( "SecurityException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Dns_Begin_EndResolve/CPP/dns_begin_endresolve.cpp b/snippets/cpp/VS_Snippets_Remoting/Dns_Begin_EndResolve/CPP/dns_begin_endresolve.cpp
deleted file mode 100644
index d3f14c02e89..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Dns_Begin_EndResolve/CPP/dns_begin_endresolve.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-This program demonstrates 'BeginResolve' and 'EndResolve' methods of Dns class.
-It obtains the 'IPHostEntry' Object* by calling 'BeginResolve' and 'EndResolve' method
-of 'Dns' class by passing a URL, a callback function and an instance of 'RequestState'
-class.Then prints host name, IP address list and aliases.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Threading;
-
-//
-//
-public ref class DnsBeginGetHostByName
-{
-public:
- static System::Threading::ManualResetEvent^ allDone = nullptr;
- ref class RequestState
- {
- public:
- IPHostEntry^ host;
- RequestState()
- {
- host = nullptr;
- }
- };
-
- static void RespCallback( IAsyncResult^ ar )
- {
- try
- {
- // Convert the IAsyncResult* Object* to a RequestState Object*.
- RequestState^ tempRequestState = dynamic_cast(ar->AsyncState);
-
- // End the asynchronous request.
- tempRequestState->host = Dns::EndResolve( ar );
- allDone->Set();
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "ArgumentNullException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- }
-};
-
-int main()
-{
- DnsBeginGetHostByName::allDone = gcnew ManualResetEvent( false );
-
- // Create an instance of the RequestState class.
- DnsBeginGetHostByName::RequestState^ myRequestState =
- gcnew DnsBeginGetHostByName::RequestState;
-
- // Begin an asynchronous request for information like host name, IP addresses, or
- // aliases for specified the specified URI.
- IAsyncResult^ asyncResult = Dns::BeginResolve( "www.contoso.com",
- gcnew AsyncCallback( DnsBeginGetHostByName::RespCallback ), myRequestState );
-
- // Wait until asynchronous call completes.
- DnsBeginGetHostByName::allDone->WaitOne();
- Console::WriteLine( "Host name : {0}", myRequestState->host->HostName );
- Console::WriteLine( "\nIP address list : " );
- for ( int index = 0; index < myRequestState->host->AddressList->Length; index++ )
- Console::WriteLine( myRequestState->host->AddressList[ index ] );
- Console::WriteLine( "\nAliases : " );
- for ( int index = 0; index < myRequestState->host->Aliases->Length; index++ )
- Console::WriteLine( myRequestState->host->Aliases[ index ] );
-}
-//
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostByAddress_IPAddress/CPP/dns_gethostbyaddress_ipaddress.cpp b/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostByAddress_IPAddress/CPP/dns_gethostbyaddress_ipaddress.cpp
deleted file mode 100644
index 500d528483d..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostByAddress_IPAddress/CPP/dns_gethostbyaddress_ipaddress.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-This program demonstrates 'GetHostByAddress(IPAddress)' method of 'Dns' class.
-It takes an IP address String* from commandline or uses default value and creates
-an instance of IPAddress for the specified IP address String*. Obtains the IPHostEntry
-Object* by calling 'GetHostByAddress' method of 'Dns' class and prints host name,
-IP address list and aliases.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-class DnsHostByAddress
-{
-public:
- void DisplayHostAddress( String^ IpAddressString )
- {
- // Call 'GetHostByAddress(IPAddress)' method giving an 'IPAddress' Object* as argument.
- // Obtain an 'IPHostEntry' instance, containing address information of the specified host.
- //
- try
- {
- IPAddress^ hostIPAddress = IPAddress::Parse( IpAddressString );
- IPHostEntry^ hostInfo = Dns::GetHostByAddress( hostIPAddress );
-
- // Get the IP address list that resolves to the host names contained in
- // the Alias property.
- array^address = hostInfo->AddressList;
-
- // Get the alias names of the addresses in the IP address list.
- array^alias = hostInfo->Aliases;
- Console::WriteLine( "Host name : {0}", hostInfo->HostName );
- Console::WriteLine( "\nAliases :" );
- for ( int index = 0; index < alias->Length; index++ )
- Console::WriteLine( alias[ index ] );
- Console::WriteLine( "\nIP address list : " );
- for ( int index = 0; index < address->Length; index++ )
- Console::WriteLine( address[ index ] );
- }
- catch ( SocketException^ e )
- {
- Console::WriteLine( "SocketException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( FormatException^ e )
- {
- Console::WriteLine( "FormatException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "ArgumentNullException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- //
- }
-};
-
-int main()
-{
- String^ IpAddressString = "";
- DnsHostByAddress * myDnsHostByAddress = new DnsHostByAddress;
- Console::Write( "Type an IP address (press Enter for default, default is '207.46.131.199'): " );
- IpAddressString = Console::ReadLine();
- if ( IpAddressString->Length > 0 )
- myDnsHostByAddress->DisplayHostAddress( IpAddressString );
- else
- myDnsHostByAddress->DisplayHostAddress( "207.46.131.199" );
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostByName/CPP/dns_gethostbyname.cpp b/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostByName/CPP/dns_gethostbyname.cpp
deleted file mode 100644
index a65db62149f..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostByName/CPP/dns_gethostbyname.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
-This program demonstrates 'GetHostByName' method of 'Dns' class.
-It takes a URL String* from commandline or uses default value, and obtains
-the 'IPHostEntry' Object* by calling 'GetHostByName' method of 'Dns' class.Then
-prints host name, IP address list and aliases.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-public ref class DnsHostByName
-{
-public:
- void DisplayHostName( String^ hostName )
- {
- // Call the GetHostByName method passing a DNS style host name(for example,
- // S"www.contoso.com") as an argument.
- // Obtain the IPHostEntry instance, that contains information of the specified host.
- //
- try
- {
- IPHostEntry^ hostInfo = Dns::GetHostByName( hostName );
-
- // Get the IP address list that resolves to the host names contained in the
- // Alias property.
- array^address = hostInfo->AddressList;
-
- // Get the alias names of the addresses in the IP address list.
- array^alias = hostInfo->Aliases;
- Console::WriteLine( "Host name : {0}", hostInfo->HostName );
- Console::WriteLine( "\nAliases : " );
- for ( int index = 0; index < alias->Length; index++ )
- Console::WriteLine( alias[ index ] );
- Console::WriteLine( "\nIP address list : " );
- for ( int index = 0; index < address->Length; index++ )
- Console::WriteLine( address[ index ] );
- }
- catch ( SocketException^ e )
- {
- Console::WriteLine( "SocketException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "ArgumentNullException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- //
- }
-};
-
-int main()
-{
- String^ hostName = "";
- DnsHostByName^ myDnsHostByName = gcnew DnsHostByName;
- Console::Write( "Type a URL (press Enter for default, default is 'www.microsoft.net') : " );
- hostName = Console::ReadLine();
- if ( hostName->Length > 0 )
- myDnsHostByName->DisplayHostName( hostName );
- else
- myDnsHostByName->DisplayHostName( "www.microsoft.net" );
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostName/CPP/dns_gethostname.cpp b/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostName/CPP/dns_gethostname.cpp
deleted file mode 100644
index 975e9204362..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Dns_GetHostName/CPP/dns_gethostname.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-This program demonstrates the 'GetHostName' method of 'Dns' class.
-It creates a 'DnsHostName' instance and calls 'GetHostName' method to get the local host
-computer name. Then prints the computer name on the console.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-public ref class DnsHostName
-{
- //
-public:
- void DisplayLocalHostName()
- {
- try
- {
- // Get the local computer host name.
- String^ hostName = Dns::GetHostName();
- Console::WriteLine( "Computer name : {0}", hostName );
- }
- catch ( SocketException^ e )
- {
- Console::WriteLine( "SocketException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- }
- //
-};
-
-int main()
-{
- DnsHostName^ dnsHostNameObj = gcnew DnsHostName;
- dnsHostNameObj->DisplayLocalHostName();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/Dns_Resolve/CPP/dns_resolve.cpp b/snippets/cpp/VS_Snippets_Remoting/Dns_Resolve/CPP/dns_resolve.cpp
deleted file mode 100644
index f280df48999..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/Dns_Resolve/CPP/dns_resolve.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
-This program demonstrates 'Resolve' method of 'Dns' class.
-It takes a URL or IP address String* from commandline or uses default value and obtains the 'IPHostEntry'
-Object* by calling 'Resolve' method of 'Dns' class. Then prints host name, IP address list and aliases.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::Net::Sockets;
-
-class DnsResolve
-{
-public:
- void DisplayHostAddress( String^ hostString )
- {
- // Call the Resolve method passing a DNS style host name or an IP address in dotted-quad notation
- // (for example, S"www.contoso.com" or S"207.46.131.199") to obtain an IPHostEntry instance that contains
- // address information for the specified host.
- //
- try
- {
- IPHostEntry^ hostInfo = Dns::Resolve( hostString );
-
- // Get the IP address list that resolves to the host names contained in the
- // Alias property.
- array^address = hostInfo->AddressList;
-
- // Get the alias names of the addresses in the IP address list.
- array^alias = hostInfo->Aliases;
- Console::WriteLine( "Host name : {0}", hostInfo->HostName );
- Console::WriteLine( "\nAliases : " );
- for ( int index = 0; index < alias->Length; index++ )
- {
- Console::WriteLine( alias[ index ] );
-
- }
- Console::WriteLine( "\nIP Address list :" );
- for ( int index = 0; index < address->Length; index++ )
- {
- Console::WriteLine( address[ index ] );
-
- }
- }
- catch ( SocketException^ e )
- {
- Console::WriteLine( "SocketException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "ArgumentNullException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( NullReferenceException^ e )
- {
- Console::WriteLine( "NullReferenceException caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception caught!!!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- //
- }
-};
-
-int main()
-{
- String^ hostString = "";
- DnsResolve * myDnsResolve = new DnsResolve;
- Console::Write( "Type a URL or IP address (press Enter for default, default is '207.46.131.199') : " );
- hostString = Console::ReadLine();
- if ( hostString->Length > 0 )
- myDnsResolve->DisplayHostAddress( hostString );
- else
- myDnsResolve->DisplayHostAddress( "207.46.131.199" );
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ContentLength/CPP/filewebrequest_contentlength.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ContentLength/CPP/filewebrequest_contentlength.cpp
deleted file mode 100644
index ff1a5cacc7d..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ContentLength/CPP/filewebrequest_contentlength.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-// System::Net::FileWebRequest::ContentLength;System::Net::FileWebRequest::RequestUri;
-
-/*
-This program demonstrates 'ContentLength'and 'RequestUri' property of 'FileWebRequest' class.
-The path of a file where user would like to write something is obtained from command line argument.
-Then a 'WebRequest' Object* is created. The 'ContentLength' property of 'FileWebRequest' is used to
-set the length of the file content that was written.
-*/
-
-#using
-
-using namespace System::Net;
-using namespace System;
-using namespace System::IO;
-using namespace System::Text;
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the file name as command line parameter where you want to write:" );
- Console::WriteLine( "Usage:FileWebRequest_ContentLen //\nExample:FileWebRequest_ContentLen shafeeque/shaf/hello.txt" );
- }
- else
- {
- try
- {
- // Create an 'Uri' Object*.
- Uri^ myUrl = gcnew Uri( String::Concat( "file://", args[ 1 ] ) );
- FileWebRequest^ myFileWebRequest = nullptr;
-
-//
- myFileWebRequest = (FileWebRequest^)( WebRequest::Create( myUrl ) );
-
- Console::WriteLine( "Enter the string you want to write into the file:" );
- String^ userInput = Console::ReadLine();
- ASCIIEncoding^ encoder = gcnew ASCIIEncoding;
- array^ byteArray = encoder->GetBytes( userInput );
-
- // Set the 'Method' property of 'FileWebRequest' Object* to 'POST' method.
- myFileWebRequest->Method = "POST";
-
- // The 'ContentLength' property is used to set the content length of the file.
- myFileWebRequest->ContentLength = byteArray->Length;
-//
-
-//
- // Compare the file name and 'RequestUri' is same or not.
- if ( myFileWebRequest->RequestUri->Equals( myUrl ) )
- {
- // 'GetRequestStream' method returns the stream handler for writing into the file.
- Stream^ readStream = myFileWebRequest->GetRequestStream();
- // Write to the stream
- readStream->Write( byteArray, 0, userInput->Length );
- readStream->Close();
- }
-
- Console::WriteLine( "\nThe String you entered was successfully written into the file." );
- Console::WriteLine( "The content length sent to the server is {0}.", myFileWebRequest->ContentLength );
-//
- }
- catch ( ArgumentException^ e )
- {
- Console::WriteLine( "The ArgumentException is : {0}", e->Message );
- }
- catch ( UriFormatException^ e )
- {
- Console::WriteLine( "The UriFormatException is : {0}", e->Message );
- }
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ReqBeginEnd/CPP/filewebrequest_reqbeginend.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ReqBeginEnd/CPP/filewebrequest_reqbeginend.cpp
deleted file mode 100644
index 7203551b787..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ReqBeginEnd/CPP/filewebrequest_reqbeginend.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-
-
-// System::Net::FileWebRequest::BeginGetRequestStream;System::Net::FileWebRequest::EndGetRequestStream;
-// Snippet1 and Snippet2 go together
-/*
-This program demonstrates 'BeginGetRequestStream' and 'EndGetRequestStream' method of 'FileWebRequest' class
-The path of the file from where content is to be read is obtained as a command line argument and a 'webRequest'
-Object* is created.Using the 'BeginGetRequestStream' method and 'EndGetRequestStream' of 'FileWebRequest' class
-a stream Object* is obtained which is used to write into the file.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-using namespace System::Threading;
-
-//
-//
-public ref class RequestDeclare
-{
-public:
- FileWebRequest^ myFileWebRequest;
- String^ userinput;
- RequestDeclare()
- {
- myFileWebRequest = nullptr;
- }
-
-};
-
-ref class FileWebRequest_reqbeginend
-{
-public:
- static ManualResetEvent^ allDone = gcnew ManualResetEvent( false );
- static void ReadCallback( IAsyncResult^ ar )
- {
- try
- {
-
- // State of the request is asynchronous.
- RequestDeclare^ requestDeclare = dynamic_cast(ar->AsyncState);
- FileWebRequest^ myFileWebRequest = requestDeclare->myFileWebRequest;
- String^ sendToFile = requestDeclare->userinput;
-
- // End the Asynchronus request by calling the 'EndGetRequestStream()' method.
- Stream^ readStream = myFileWebRequest->EndGetRequestStream( ar );
-
- // Convert the String* into Byte array.
- ASCIIEncoding^ encoder = gcnew ASCIIEncoding;
- array^byteArray = encoder->GetBytes( sendToFile );
-
- // Write to the stream.
- readStream->Write( byteArray, 0, sendToFile->Length );
- readStream->Close();
- allDone->Set();
- Console::WriteLine( "\nThe String you entered was successfully written into the file." );
- Console::WriteLine( "\nPress Enter to continue." );
- }
- catch ( ApplicationException^ e )
- {
- Console::WriteLine( "ApplicationException is : {0}", e->Message );
- }
-
- }
-
-};
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the file name as command line parameter:" );
- Console::WriteLine( "Usage:FileWebRequest_reqbeginend //\n" );
- Console::WriteLine( "Example:FileWebRequest_reqbeginend shafeeque/shaf/hello.txt" );
- }
- else
- {
- try
- {
-
- // Place a webrequest.
- WebRequest^ myWebRequest = WebRequest::Create( String::Concat( "file://", args[ 1 ] ) );
-
- // Create an instance of the 'RequestDeclare' and associate the 'myWebRequest' to it.
- RequestDeclare^ requestDeclare = gcnew RequestDeclare;
- requestDeclare->myFileWebRequest = dynamic_cast(myWebRequest);
-
- // Set the 'Method' property of 'FileWebRequest' Object* to 'POST' method.
- requestDeclare->myFileWebRequest->Method = "POST";
- Console::WriteLine( "Enter the String* you want to write into the file:" );
- requestDeclare->userinput = Console::ReadLine();
-
- // Begin the Asynchronous request for getting file content using 'BeginGetRequestStream()' method .
- IAsyncResult^ r = dynamic_cast(requestDeclare->myFileWebRequest->BeginGetRequestStream( gcnew AsyncCallback( &FileWebRequest_reqbeginend::ReadCallback ), requestDeclare ));
- FileWebRequest_reqbeginend::allDone->WaitOne();
- Console::Read();
- }
- catch ( ProtocolViolationException^ e )
- {
- Console::WriteLine( "ProtocolViolationException is : {0}", e->Message );
- }
- catch ( InvalidOperationException^ e )
- {
- Console::WriteLine( "InvalidOperationException is : {0}", e->Message );
- }
- catch ( UriFormatException^ e )
- {
- Console::WriteLine( "UriFormatExceptionException is : {0}", e->Message );
- }
-
- }
-}
-
-//
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ResBeginEnd/CPP/filewebrequest_resbeginend.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ResBeginEnd/CPP/filewebrequest_resbeginend.cpp
deleted file mode 100644
index 0a0ee8a55eb..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebRequest_ResBeginEnd/CPP/filewebrequest_resbeginend.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-// System::Net::FileWebRequest::BeginGetResponse;System::Net::FileWebRequest::EndGetResponse;
-// Snippet1 and Snippet2 go together
-/*
-This program demonstrates 'BeginGetResponse' and 'EndGetResponse' methods of 'FileWebRequest' class.
-The path of the file from where content is to be read is obtained as a command line argument and a
-'WebRequest' Object* is created. Using the 'BeginGetResponse' method and 'EndGetResponse' of 'FileWebRequest'
-class a 'FileWebResponse' Object* is obtained which is used to print the content on the file.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Threading;
-
-//
-//
-public ref class RequestDeclare
-{
-public:
- FileWebRequest^ myFileWebRequest;
- RequestDeclare()
- {
- myFileWebRequest = nullptr;
- }
-
-};
-
-ref class FileWebRequest_resbeginend
-{
-public:
- static ManualResetEvent^ allDone = gcnew ManualResetEvent( false );
- static void RespCallback( IAsyncResult^ ar )
- {
-
- // State of request is asynchronous.
- RequestDeclare^ requestDeclare = dynamic_cast(ar->AsyncState);
- FileWebRequest^ myFileWebRequest = requestDeclare->myFileWebRequest;
-
- // End the Asynchronus request by calling the 'EndGetResponse()' method.
- FileWebResponse^ myFileWebResponse = dynamic_cast(myFileWebRequest->EndGetResponse( ar ));
-
- // Reade the response into Stream.
- StreamReader^ streamReader = gcnew StreamReader( myFileWebResponse->GetResponseStream() );
- array^readBuffer = gcnew array(256);
- int count = streamReader->Read( readBuffer, 0, 256 );
- Console::WriteLine( "The contents of the file are :\n" );
- while ( count > 0 )
- {
- String^ str = gcnew String( readBuffer,0,count );
- Console::WriteLine( str );
- count = streamReader->Read( readBuffer, 0, 256 );
- }
-
- streamReader->Close();
-
- // Release the response Object* resources.
- myFileWebResponse->Close();
- allDone->Set();
- Console::WriteLine( "File reading is over." );
- }
-
-};
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the file name as command line parameter:" );
- Console::WriteLine( "Usage:FileWebRequest_resbeginend //\n" );
- Console::WriteLine( "Example:FileWebRequest_resbeginend shafeeque/shaf/hello.txt" );
- }
- else
- {
- try
- {
-
- // Place a 'Webrequest'.
- WebRequest^ myWebRequest = WebRequest::Create( String::Concat( "file://", args[ 1 ] ) );
-
- // Create an instance of the 'RequestDeclare' and associating the 'myWebRequest' to it.
- RequestDeclare^ myRequestDeclare = gcnew RequestDeclare;
- myRequestDeclare->myFileWebRequest = dynamic_cast(myWebRequest);
-
- // Begin the Asynchronous request for getting file content using 'BeginGetResponse()' method.
- IAsyncResult^ asyncResult = dynamic_cast(myRequestDeclare->myFileWebRequest->BeginGetResponse( gcnew AsyncCallback( &FileWebRequest_resbeginend::RespCallback ), myRequestDeclare ));
- FileWebRequest_resbeginend::allDone->WaitOne();
- }
- catch ( ArgumentNullException^ e )
- {
- Console::WriteLine( "ArgumentNullException is : {0}", e->Message );
- }
- catch ( UriFormatException^ e )
- {
- Console::WriteLine( "UriFormatException is : {0}", e->Message );
- }
-
- }
-}
-
-//
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_Close/CPP/filewebresponse_close.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_Close/CPP/filewebresponse_close.cpp
deleted file mode 100644
index 7125135810a..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_Close/CPP/filewebresponse_close.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-// System::Net::FileWebResponse::Close
-/*This program demontrates the 'Close' method of 'FileWebResponse' Class.
-It takes an Uri from console and creates a 'FileWebRequest' Object* for the Uri::It then gets back
-the response Object* from the Uri. The response Object* can be processed as desired. The program then
-closes the response Object* and releases resources associated with it.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-
-//
-void GetPage( String^ url )
-{
- try
- {
- Uri^ fileUrl = gcnew Uri( String::Concat( "file://", url ) );
- // Create a FileWebrequest with the specified Uri.
- FileWebRequest^ myFileWebRequest = dynamic_cast(WebRequest::Create( fileUrl ));
- // Send the 'fileWebRequest' and wait for response.
- FileWebResponse^ myFileWebResponse = dynamic_cast(myFileWebRequest->GetResponse());
- // Process the response here.
- Console::WriteLine( "\nResponse Received::Trying to Close the response stream.." );
- // Release resources of response Object*.
- myFileWebResponse->Close();
- Console::WriteLine( "\nResponse Stream successfully closed." );
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\r\nWebException thrown. The Reason for failure is : {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following Exception was raised : {0}", e->Message );
- }
-}
-//
-
-int main()
-{
- array^args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the file name as command line parameter:" );
- Console::WriteLine( "Usage:FileWebResponse_Close // \nExample:FileWebResponse_Close microsoft/shared/hello.txt" );
- }
- else
- {
- GetPage( args[ 1 ] );
- }
-
- Console::WriteLine( "Press any key to continue..." );
- Console::ReadLine();
- return 0;
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_ContentLength_ContentType/CPP/filewebresponse_contentlength_contenttype.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_ContentLength_ContentType/CPP/filewebresponse_contentlength_contenttype.cpp
deleted file mode 100644
index 5dff4113057..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_ContentLength_ContentType/CPP/filewebresponse_contentlength_contenttype.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// System::Net::FileWebResponse::ContentLength;System::Net::FileWebResponse::ContentType.
-
-/* This program demonstrates the 'ContentLength' and 'ContentType' properties of the 'FileWebResponse' class.
-It creates a web request and queries for a response. It then prints the content length
-and content type of the entity body in the response onto the console */
-
-#using
-
-using namespace System;
-using namespace System::Net;
-
-//
-//
-void GetPage( String^ url )
-{
- try
- {
- Uri^ fileUrl = gcnew Uri( String::Concat( "file://", url ) );
- // Create a 'FileWebrequest' Object* with the specified Uri.
- FileWebRequest^ myFileWebRequest = (FileWebRequest^)( WebRequest::Create( fileUrl ) );
- // Send the 'fileWebRequest' and wait for response.
- FileWebResponse^ myFileWebResponse = (FileWebResponse^)( myFileWebRequest->GetResponse() );
- // Print the ContentLength and ContentType properties received as headers in the response Object*.
- Console::WriteLine( "\nContent length : {0}, Content Type : {1}", myFileWebResponse->ContentLength, myFileWebResponse->ContentType );
- // Release resources of response Object*.
- myFileWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\r\nWebException thrown. The Reason for failure is : {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following Exception was raised : {0}", e->Message );
- }
-}
-//
-//
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the file name as command line parameter:" );
- Console::WriteLine( "Usage:FileWebResponse_ContentLength_ContentType // \nExample:FileWebResponse_ContentLength_ContentType microsoft/shared/hello.txt" );
- }
- else
- {
- GetPage( args[ 1 ] );
- }
-
- Console::WriteLine( "Press any key to continue..." );
- Console::ReadLine();
- return 0;
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_GetResponseStream/CPP/filewebresponse_getresponsestream.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_GetResponseStream/CPP/filewebresponse_getresponsestream.cpp
deleted file mode 100644
index 37b23a614f8..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_GetResponseStream/CPP/filewebresponse_getresponsestream.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-// System::Net::FileWebResponse::GetResponseStream.
-
-/* This program demonstrates the 'GetResponseStream' method of the 'FileWebResponse' class.
-It creates a 'FileWebRequest' Object* and queries for a response.
-The response stream obtained is piped to a higher level stream reader. The reader reads
-256 characters at a time, writes them into a String* and then displays the String* onto the console*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-
-void GetPage( String^ url )
-{
- try
- {
-//
- Uri^ fileUrl = gcnew Uri( String::Concat( "file://", url ) );
- // Create a 'FileWebrequest' Object* with the specified Uri.
- FileWebRequest^ myFileWebRequest = (FileWebRequest^)( WebRequest::Create( fileUrl ) );
- // Send the 'FileWebRequest' Object* and wait for response.
- FileWebResponse^ myFileWebResponse = (FileWebResponse^)( myFileWebRequest->GetResponse() );
-
- // Get the stream Object* associated with the response Object*.
- Stream^ receiveStream = myFileWebResponse->GetResponseStream();
-
- Encoding^ encode = System::Text::Encoding::GetEncoding( "utf-8" );
- // Pipe the stream to a higher level stream reader with the required encoding format.
- StreamReader^ readStream = gcnew StreamReader( receiveStream,encode );
- Console::WriteLine( "\r\nResponse stream received" );
-
- array^ read = gcnew array(256);
- // Read 256 characters at a time.
- int count = readStream->Read( read, 0, 256 );
- Console::WriteLine( "File Data...\r\n" );
- while ( count > 0 )
- {
- // Dump the 256 characters on a String* and display the String* onto the console.
- String^ str = gcnew String( read,0,count );
- Console::Write( str );
- count = readStream->Read( read, 0, 256 );
- }
- Console::WriteLine( "" );
- // Release resources of stream Object*.
- readStream->Close();
- // Release resources of response Object*.
- myFileWebResponse->Close();
-//
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\r\nWebException thrown. The Reason for failure is : {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following Exception was raised : {0}", e->Message );
- }
-}
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the file name as command line parameter:" );
- Console::WriteLine( "Usage:FileWebResponse_GetResponseStream // \nExample:FileWebResponse_GetResponseStream microsoft/shared/hello.txt" );
- }
- else
- {
- GetPage( args[ 1 ] );
- }
-
- Console::WriteLine( "Press any key to continue..." );
- Console::ReadLine();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_Headers/CPP/filewebresponse_headers.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_Headers/CPP/filewebresponse_headers.cpp
deleted file mode 100644
index 3d637455677..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_Headers/CPP/filewebresponse_headers.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-// System::Net::FileWebResponse::Headers
-
-/* This program demonstrates the 'Headers' property of the 'FileWebResponse' class.
-It creates a web request and queries for a response. It then prints [Out] all* the response
-headers (name -value pairs) onto the console. */
-
-#using
-
-using namespace System;
-using namespace System::Net;
-
-//
-void GetPage( String^ url )
-{
- try
- {
- Uri^ fileUrl = gcnew Uri( String::Concat( "file://", url ) );
- // Create a 'FileWebrequest' Object^ with the specified Uri .
- FileWebRequest^ myFileWebRequest = (FileWebRequest^)(WebRequest::Create( fileUrl ));
- // Send the 'FileWebRequest' and wait for response.
- FileWebResponse^ myFileWebResponse = (FileWebResponse^)(myFileWebRequest->GetResponse());
- // Display all Headers present in the response received from the Uri.
- Console::WriteLine( "\r\nThe following headers were received in the response:" );
- // Display each header and the key of the response Object^.
- for ( int i = 0; i < myFileWebResponse->Headers->Count; ++i )
- Console::WriteLine( "\nHeader Name: {0}, Header value : {1}",
- myFileWebResponse->Headers->Keys[ i ], myFileWebResponse->Headers[ (HttpRequestHeader)i ] );
- myFileWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\r\nWebException thrown. The Reason for failure is: {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following Exception was raised: {0}", e->Message );
- }
-
-}
-//
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease type the file name as command line parameter as:" );
- Console::WriteLine( "Usage:FileWebResponse_Headers // \nExample:FileWebResponse_Headers microsoft/shared/hello.txt" );
- }
- else
- {
- GetPage( args[ 1 ] );
- }
-
- Console::WriteLine( "Press any key to continue..." );
- Console::ReadLine();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_ResponseUri/CPP/filewebresponse_responseuri.cpp b/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_ResponseUri/CPP/filewebresponse_responseuri.cpp
deleted file mode 100644
index 677397be699..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/FileWebResponse_ResponseUri/CPP/filewebresponse_responseuri.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// System::Net::FileWebResponse::ResponseUri
-
-/* This program demonstrates the 'ResponseUri' property of the 'FileWebResponse' class.
-It creates a 'FileWebRequest' Object* and queries for a response. It then displays the Uri of the file
-system resource that provided the response.
-*/
-
-#using
-
-using namespace System;
-using namespace System::Net;
-
-//
-void GetPage( String^ url )
-{
- try
- {
- Uri^ fileUrl = gcnew Uri( String::Concat( "file://", url ) );
-
- // Create a 'FileWebrequest' object with the specified Uri .
- FileWebRequest^ myFileWebRequest = (FileWebRequest^)( WebRequest::Create( fileUrl ) );
-
- // Send the 'fileWebRequest' and wait for response.
- FileWebResponse^ myFileWebResponse = (FileWebResponse^)( myFileWebRequest->GetResponse() );
- Console::WriteLine( "\nThe Uri of the file system resource that provided the response is :\n {0}\n\n", myFileWebResponse->ResponseUri );
-
- // Release resources of response object.
- myFileWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\r\nWebException thrown. The Reason for failure is : {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nThe following Exception was raised : {0}", e->Message );
- }
-}
-//
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease type the file name as command line parameter as:" );
- Console::WriteLine( "Usage:FileWebResponse_ResponseUri // \nExample:FileWebResponse_ResponseUri microsoft/shared/hello.txt" );
- }
- else
- {
- GetPage( args[ 1 ] );
- }
-
- Console::WriteLine( "Press any key to continue..." );
- Console::ReadLine();
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpVersion_Version10/CPP/httpversion_version10.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpVersion_Version10/CPP/httpversion_version10.cpp
deleted file mode 100644
index 21704539710..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpVersion_Version10/CPP/httpversion_version10.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/*System::Net::HttpVersion::Version10
-This program demonstrates the 'Version10' field of the 'HttpVersion' Class.
-The 'Version' property of 'HttpRequestMessage' class identifies the Version of HTTP being used.
-Then the default value of 'Version' property is displayed to the console.
-The 'Version10' field of the 'HttpVersion' class is assigned to the 'Version' property of the 'HttpRequestMessage' Class.
-The changed Version and the 'Version' of the response object are displayed.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Net::Http;
-
-int main()
-{
- try
- {
- //
- // HttpClient lifecycle management best practices:
- // https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
- HttpClient^ client = gcnew HttpClient();
-
- HttpRequestMessage^ request = new HttpRequestMessage(HttpMethod::Get, "http://www.microsoft.com");
- Console::WriteLine("Default HTTP request version is {0}", request.Version);
-
- request.Version = HttpVersion.Version10;
- Console::WriteLine("Request version after assignment is {0}", request.Version);
-
- HttpResponseMessage^ response = client->Send(request);
- Console::WriteLine("Response HTTP version {0}", response.Version);
- //
- Console::WriteLine("\nPress 'Enter' Key to Continue..............");
- Console::Read();
- }
- catch (HttpRequestException^ e)
- {
- Console::WriteLine("HttpRequestException Caught!");
- Console::WriteLine("Message : {0} ", e->Message);
- Console::WriteLine("Source : {0} ", e->Source);
- }
- catch (Exception^ e)
- {
- Console::WriteLine("Exception Caught!");
- Console::WriteLine("Source : {0}", e->Source);
- Console::WriteLine("Message : {0}", e->Message);
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Accept/CPP/httpwebrequest_accept.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Accept/CPP/httpwebrequest_accept.cpp
deleted file mode 100644
index defe1c29135..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Accept/CPP/httpwebrequest_accept.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/* System::Net::HttpWebRequest::Accept
-This program demonstrates 'Accept' property of the 'HttpWebRequest' class.
-A new 'HttpWebRequest' Object* is created. The 'Accept' property of 'HttpWebRequest'
-class is set to 'image/*' that in turn sets the 'Accept' field of HTTP Request Headers to
-S"image/*". HTTP Request and Response headers are displayed to the console.
-The contents of the page of the requested URI are displayed to the console.
-'Accept' property is set with an aim to receive the response in a specific format.
-
-Note: This program requires http://localhost/CodeSnippetTest::html as Command line parameter.
-If the requested page contains any content other than 'image/*' an error of 'status (406) Not Acceptable'
-is returned. The functionality of 'Accept' property is supported only by servers that use HTTP 1.1
-protocol.Please refer to RFC 2616 for further information on HTTP Headers.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-
-void GetPage( String^ myUri )
-{
- try
- {
-//
- // Create a 'HttpWebRequest' object.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( myUri ) );
- // Set the 'Accept' property to accept an image of any type.
- myHttpWebRequest->Accept = "image/*";
- // The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
-//
- Console::WriteLine( "\nHTTP Request Headers :\n\n {0}", myHttpWebRequest->Headers );
- Console::WriteLine( "\nHTTP Response Headers :\n\n {0}", myHttpWebResponse->Headers );
- Console::WriteLine( "Press 'Enter' Key to Continue......." );
- Console::Read();
- // Displaying the contents of the page to the console
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^ readBuffer = gcnew array(256);
- int count = streamRead->Read( readBuffer, 0, 256 );
- Console::WriteLine( "\nThe contents of HTML page are......." );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuffer,0,count );
- Console::Write( outputData );
- count = streamRead->Read( readBuffer, 0, 256 );
- }
- Console::WriteLine( "\nPress 'Enter' Key to Continue......" );
- Console::Read();
- streamRead->Close();
- streamResponse->Close();
- myHttpWebResponse->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException Caught!" );
- Console::WriteLine( "Message : {0} ", e->Message );
- }
-}
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- try
- {
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the Uri address as a command line parameter" );
- Console::WriteLine( "Usage:HttpWebRequest_Accept http://www.microsoft.com/library/homepage/images/ms-banner.gif" );
- }
- else
- {
- GetPage( args[ 1 ] );
- }
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_AllowAutoRedirect/CPP/httpwebrequest_allowautoredirect.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_AllowAutoRedirect/CPP/httpwebrequest_allowautoredirect.cpp
deleted file mode 100644
index 1e2f153e109..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_AllowAutoRedirect/CPP/httpwebrequest_allowautoredirect.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/* System::Net::HttpWebRequest::AllowAutoRedirect System::Net::HttpWebRequest->Address
-This program demonstrates the 'AllowAutoRedirect' and 'Address' properties of the 'HttpWebRequest' Class.
-A new 'HttpWebRequest' Object* is created. The 'AllowAutoredirect' property, which redirects a page automatically
-to the new Uri, is set to true. Using the 'Address' property, the address of the 'Responding Uri' is printed to
-console. The contents of the redirected page are displayed to the console.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-int main()
-{
- try
- {
-//
-//
- // Create a new HttpWebRequest Object to the mentioned URL.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com" ) );
- myHttpWebRequest->MaximumAutomaticRedirections = 1;
- myHttpWebRequest->AllowAutoRedirect = true;
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
-//
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^ readBuff = gcnew array(256);
- int count = streamRead->Read( readBuff, 0, 256 );
- Console::WriteLine( "\nThe contents of Html Page are : " );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuff,0,count );
- Console::Write( outputData );
- count = streamRead->Read( readBuff, 0, 256 );
- }
- streamResponse->Close();
- streamRead->Close();
- // Release the HttpWebResponse Resource.
- myHttpWebResponse->Close();
- Console::WriteLine( "\nThe Requested Uri is {0}", myHttpWebRequest->RequestUri );
- Console::WriteLine( "\nThe Actual Uri responding to the request is \n {0}", myHttpWebRequest->Address );
-//
- Console::WriteLine( "\nPress any Key to Continue.........." );
- Console::Read();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "WebException raised!" );
- Console::WriteLine( "\nMessage: {0}", e->Message );
- Console::WriteLine( "\nStatus: {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised!" );
- Console::WriteLine( "\nSource : {0}", e->Source );
- Console::WriteLine( "\nMessage : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_AllowWriteStreamBuffering/CPP/httpwebrequest_allowwritestreambuffering.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_AllowWriteStreamBuffering/CPP/httpwebrequest_allowwritestreambuffering.cpp
deleted file mode 100644
index da5e28f5284..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_AllowWriteStreamBuffering/CPP/httpwebrequest_allowwritestreambuffering.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/*System::Net::HttpWebRequest::AllowWriteStreamBuffering
-This program demonstrates 'AllowWriteStreamBuffering' property of 'HttpWebRequestClass'.
-A new 'HttpWebRequest' Object* is created.
-The 'AllowWriteStreamBuffering' property value is set to false.
-If the 'AllowWriteStreamBuffering' is set to false,
-then 'ContentLength' property should be set to the length of data to be posted before posting the data
-else the Http Status(411) Length required is returned.
-Data to be posted to the Uri is requested from the user.
-The 'Method' property is set to POST to be able to post data to the Uri.
-The 'GetRequestStream' method of the 'HttpWebRequest' class returns a stream Object*.
-This stream Object* is used to write data to the Uri.
-The HTML contents of the page are displayed to the console after the posted data is accepted by the URL
-
-Note:This program posts data to the Uri : http://www20.brinkster.com/codesnippets/next.asp.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-int main()
-{
- try
- {
-//
- // Create a new 'HttpWebRequest' object to the mentioned Uri.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com/codesnippets/next.asp" ) );
- // Set AllowWriteStreamBuffering to 'false'.
- myHttpWebRequest->AllowWriteStreamBuffering = false;
- Console::WriteLine( "\nPlease Enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) uri:" );
- String^ inputData = Console::ReadLine();
- String^ postData = String::Concat( "firstone= ", inputData );
- // Set 'Method' property of 'HttpWebRequest' class to POST.
- myHttpWebRequest->Method = "POST";
- ASCIIEncoding^ encodedData = gcnew ASCIIEncoding;
- array^ byteArray = encodedData->GetBytes( postData );
- // Set 'ContentType' property of the 'HttpWebRequest' class to S"application/x-www-form-urlencoded".
- myHttpWebRequest->ContentType = "application/x-www-form-urlencoded";
- // If the AllowWriteStreamBuffering property of HttpWebRequest is set to false, the contentlength has to be set to length of data to be posted else Exception(411) is raised.
- myHttpWebRequest->ContentLength = byteArray->Length;
- Stream^ newStream = myHttpWebRequest->GetRequestStream();
- newStream->Write( byteArray, 0, byteArray->Length );
- newStream->Close();
- Console::WriteLine( "\nData has been posted to the Uri\n\nPlease wait for the response.........." );
- // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
-//
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^ readBuff = gcnew array(256);
- int count = streamRead->Read( readBuff, 0, 256 );
- Console::WriteLine( "\nThe contents of the Html page are : " );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuff,0,count );
- Console::WriteLine( outputData );
- count = streamRead->Read( readBuff, 0, 256 );
- }
- streamResponse->Close();
- streamRead->Close();
- // Release the HttpWebResponse Resource.
- myHttpWebResponse->Close();
- Console::WriteLine( "\nPress 'Enter' Key to Continue................." );
- Console::Read();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- Console::WriteLine( "\n(The 'ContentLength' property of 'HttpWebRequest' is not set after 'AllowWriteStreamBuffering' is set to 'false'.)" );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException Caught!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_BeginGetRequestStream/CPP/httpwebrequest_begingetrequeststream.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_BeginGetRequestStream/CPP/httpwebrequest_begingetrequeststream.cpp
deleted file mode 100644
index 452b35e9ca7..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_BeginGetRequestStream/CPP/httpwebrequest_begingetrequeststream.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/* System::Net::HttpWebRequest::BeginGetRequestStream, System::Net::HttpWebRequest::EndGetRequestStream
-
-This program demonstrates the 'BeginGetRequestStream' and 'EndGetRequestStream' methods of the 'HttpWebRequest' class.
-A new 'HttpWebRequest' Object is created. The 'Method' property of the 'HttpWebRequest' Object* is set to
-'POST'. The 'ContentType' property is set to S"application/x-www-form-urlencoded". Then, the 'BeginGetRequestStream'
-method of 'HttpWebRequest' class starts the Asynchronous writing to the 'HttpWebRequest' Object*. The
-'EndGetRequestStream' method of 'HttpWebRequest' class ends the Asynchronous writing of data and returns a
-stream Object*. The 'Stream' Object* is used to write data to the 'HttpWebRequest' Object*.
-
-Note: This program POSTs data to the Uri: http://www20.Brinkster::com/codesnippets/next.asp
-*/
-//
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-using namespace System::Threading;
-ref class HttpWebRequestBeginGetRequest
-{
-public:
- static ManualResetEvent^ allDone = gcnew ManualResetEvent( false );
- static void Main()
- {
-
- //
- // Create a new HttpWebRequest object.
- HttpWebRequest^ request = dynamic_cast(WebRequest::Create( "http://www.contoso.com/example.aspx" ));
-
- // Set the ContentType property.
- request->ContentType = "application/x-www-form-urlencoded";
-
- // Set the Method property to 'POST' to post data to the Uri.
- request->Method = "POST";
-
- // Start the asynchronous operation.
- AsyncCallback^ del = gcnew AsyncCallback(GetRequestStreamCallback);
- request->BeginGetRequestStream( del, request );
-
- // Keep the main thread from continuing while the asynchronous
- // operation completes. A real world application
- // could do something useful such as updating its user interface.
- allDone->WaitOne();
- }
-
-
-private:
- static void GetRequestStreamCallback(IAsyncResult^ asynchronousResult)
- {
- HttpWebRequest^ request = dynamic_cast(asynchronousResult->AsyncState);
-
- // End the operation
- Stream^ postStream = request->EndGetRequestStream(asynchronousResult);
-
- Console::WriteLine("Please enter the input data to be posted:");
- String^ postData = Console::ReadLine();
-
- // Convert the string into a byte array.
- array^ByteArray = Encoding::UTF8->GetBytes(postData);
-
- // Write to the request stream.
- postStream->Write(ByteArray, 0, postData->Length);
- postStream->Close();
-
- // Start the asynchronous operation to get the response
- AsyncCallback^ del = gcnew AsyncCallback(GetResponseCallback);
- request->BeginGetResponse(del, request);
- }
-
- static void GetResponseCallback(IAsyncResult^ asynchronousResult)
- {
- HttpWebRequest^ request = dynamic_cast(asynchronousResult->AsyncState);
-
- // End the operation
- HttpWebResponse^ response = dynamic_cast(request->EndGetResponse(asynchronousResult));
- Stream^ streamResponse = response->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader(streamResponse);
- String^ responseString = streamRead->ReadToEnd();
- Console::WriteLine(responseString);
- // Close the stream object
- streamResponse->Close();
- streamRead->Close();
-
- // Release the HttpWebResponse
- response->Close();
- allDone->Set();
- }
- //
-};
-
-void main()
-{
- HttpWebRequestBeginGetRequest::Main();
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_BeginGetResponse/CPP/httpwebrequest_begingetresponse.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_BeginGetResponse/CPP/httpwebrequest_begingetresponse.cpp
deleted file mode 100644
index fb120510b57..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_BeginGetResponse/CPP/httpwebrequest_begingetresponse.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-
-
-// System::Net::HttpWebRequest::BeginGetResponse System::Net::HttpWebRequest::EndGetResponse
-/**
-* Snippet1, Snippet2, Snippet3 go together.
-* This program shows how to use BeginGetResponse and EndGetResponse methods of the
-* HttpWebRequest class.
-* It uses an asynchronous approach to get the response for the HTTP Web Request.
-* The RequestState class is defined to chekc the state of the request.
-* After a HttpWebRequest Object* is created, its BeginGetResponse method is used to start
-* the asynchronous response phase.
-* Finally, the EndGetResponse method is used to end the asynchronous response phase .
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-using namespace System::Threading;
-public ref class RequestState
-{
-private:
-
- // This class stores the State of the request.
- const int BUFFER_SIZE;
-
-public:
- StringBuilder^ requestData;
- array^BufferRead;
- HttpWebRequest^ request;
- HttpWebResponse^ response;
- Stream^ streamResponse;
- RequestState()
- : BUFFER_SIZE( 1024 )
- {
- BufferRead = gcnew array(BUFFER_SIZE);
- requestData = gcnew StringBuilder( "" );
- request = nullptr;
- streamResponse = nullptr;
- }
-
-};
-
-ref class HttpWebRequest_BeginGetResponse
-{
-public:
- static ManualResetEvent^ allDone = gcnew ManualResetEvent( false );
- static int BUFFER_SIZE = 1024;
-
- //
- //
- static void RespCallback( IAsyncResult^ asynchronousResult )
- {
- try
- {
-
- // State of request is asynchronous.
- RequestState^ myRequestState = dynamic_cast(asynchronousResult->AsyncState);
- HttpWebRequest^ myHttpWebRequest2 = myRequestState->request;
- myRequestState->response = dynamic_cast(myHttpWebRequest2->EndGetResponse( asynchronousResult ));
-
- // Read the response into a Stream object.
- Stream^ responseStream = myRequestState->response->GetResponseStream();
- myRequestState->streamResponse = responseStream;
-
- // Begin the Reading of the contents of the HTML page and print it to the console.
- IAsyncResult^ asynchronousInputRead = responseStream->BeginRead( myRequestState->BufferRead, 0, BUFFER_SIZE, gcnew AsyncCallback( ReadCallBack ), myRequestState );
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nException raised!" );
- Console::WriteLine( "\nMessage: {0}", e->Message );
- Console::WriteLine( "\nStatus: {0}", e->Status );
- }
-
- }
-
- static void ReadCallBack( IAsyncResult^ asyncResult )
- {
- try
- {
- RequestState^ myRequestState = dynamic_cast(asyncResult->AsyncState);
- Stream^ responseStream = myRequestState->streamResponse;
- int read = responseStream->EndRead( asyncResult );
-
- // Read the HTML page and then print it to the console.
- if ( read > 0 )
- {
- myRequestState->requestData->Append( Encoding::ASCII->GetString( myRequestState->BufferRead, 0, read ) );
- IAsyncResult^ asynchronousResult = responseStream->BeginRead( myRequestState->BufferRead, 0, BUFFER_SIZE, gcnew AsyncCallback( ReadCallBack ), myRequestState );
- }
- else
- {
- Console::WriteLine( "\nThe contents of the Html page are : " );
- if ( myRequestState->requestData->Length > 1 )
- {
- String^ stringContent;
- stringContent = myRequestState->requestData->ToString();
- Console::WriteLine( stringContent );
- }
- Console::WriteLine( "Press any key to continue.........." );
- Console::ReadLine();
- responseStream->Close();
- allDone->Set();
- }
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nException raised!" );
- Console::WriteLine( "\nMessage: {0}", e->Message );
- Console::WriteLine( "\nStatus: {0}", e->Status );
- }
-
- }
-
-};
-
-int main()
-{
- try
- {
-
- // Create a HttpWebrequest object to the desired URL.
- HttpWebRequest^ myHttpWebRequest1 = dynamic_cast(WebRequest::Create( "http://www.contoso.com" ));
-
- // Create an instance of the RequestState and assign the previous myHttpWebRequest1
- // object to its request field.
- RequestState^ myRequestState = gcnew RequestState;
- myRequestState->request = myHttpWebRequest1;
-
- // Start the asynchronous request.
- IAsyncResult^ result = dynamic_cast(myHttpWebRequest1->BeginGetResponse( gcnew AsyncCallback( HttpWebRequest_BeginGetResponse::RespCallback ), myRequestState ));
- HttpWebRequest_BeginGetResponse::allDone->WaitOne();
-
- // Release the HttpWebResponse resource.
- myRequestState->response->Close();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nException raised!" );
- Console::WriteLine( "\nMessage: {0}", e->Message );
- Console::WriteLine( "\nStatus: {0}", e->Status );
- Console::WriteLine( "Press any key to continue.........." );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException raised!" );
- Console::WriteLine( "Source : {0} ", e->Source );
- Console::WriteLine( "Message : {0} ", e->Message );
- Console::WriteLine( "Press any key to continue.........." );
- Console::Read();
- }
-
-}
-
-//
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Connection/CPP/httpwebrequest_connection.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Connection/CPP/httpwebrequest_connection.cpp
deleted file mode 100644
index 6d2c9db2782..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Connection/CPP/httpwebrequest_connection.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
-// System::Net::HttpWebRequest::KeepAlive System::Net::HttpWebRequest::Connection
-/**
-* This program demonstrates Connection and KeepAlive properties of the
-* HttpWebRequest Class.
-* Two new HttpWebRequest objects are created. The KeepAlive property of one of
-* the objects is set to false that in turn sets the value of Connection field of
-* the HTTP request Headers to Close.
-* The Connection property of the other HttpWebRequest Object* is assigned the
-* value Close. This throws an ArgumentException which is caught. The HTTP request
-* Headers are displayed to the console.
-* The contents of the HTML page of the requested URI are displayed.
-**/
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-//
-int main()
-{
- try
- {
-
- // Create a new HttpWebRequest object. Make sure that
- // a default proxy is set if you are behind a firewall.
- HttpWebRequest^ myHttpWebRequest1 = dynamic_cast(WebRequest::Create( "http://www.contoso.com" ));
- myHttpWebRequest1->KeepAlive = false;
-
- // Assign the response object of HttpWebRequest to a HttpWebResponse variable.
- HttpWebResponse^ myHttpWebResponse1 = dynamic_cast(myHttpWebRequest1->GetResponse());
- Console::WriteLine( "\nThe HTTP request Headers for the first request are: \n {0}", myHttpWebRequest1->Headers );
- Console::WriteLine( "Press Enter Key to Continue.........." );
- Console::Read();
- Stream^ streamResponse = myHttpWebResponse1->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^readBuff = gcnew array(256);
- int count = streamRead->Read( readBuff, 0, 256 );
- Console::WriteLine( "The contents of the Html page are.......\n" );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuff,0,count );
- Console::Write( outputData );
- count = streamRead->Read( readBuff, 0, 256 );
- }
- Console::WriteLine();
-
- // Close the Stream object.
- streamResponse->Close();
- streamRead->Close();
-
- // Release the resources held by response object.
- myHttpWebResponse1->Close();
-
- //
- // Create a new HttpWebRequest object for the specified Uri.
- HttpWebRequest^ myHttpWebRequest2 = dynamic_cast(WebRequest::Create( "http://www.contoso.com" ));
- myHttpWebRequest2->Connection = "Close";
-
- // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse2 = dynamic_cast(myHttpWebRequest2->GetResponse());
-
- // Release the resources held by response object.
- myHttpWebResponse2->Close();
- Console::WriteLine( "\nThe Http RequestHeaders are \n {0}", myHttpWebRequest2->Headers );
-
- //
- Console::WriteLine( "\nPress 'Enter' Key to Continue........." );
- Console::Read();
- }
- catch ( ArgumentException^ e )
- {
- Console::WriteLine( "\nThe second HttpWebRequest Object* has raised an Argument Exception as 'Connection' Property is set to 'Close'" );
- Console::WriteLine( "\n {0}", e->Message );
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "WebException raised!" );
- Console::WriteLine( "\n {0}", e->Message );
- Console::WriteLine( "\n {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised!" );
- Console::WriteLine( "Source : {0} ", e->Source );
- Console::WriteLine( "Message : {0} ", e->Message );
- }
-
-}
-
-//
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_ContentLength/CPP/httpwebrequest_contentlength.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_ContentLength/CPP/httpwebrequest_contentlength.cpp
deleted file mode 100644
index 39d85a9efc9..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_ContentLength/CPP/httpwebrequest_contentlength.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-System::Net::HttpWebRequest::Method, System::Net::HttpWebRequest::ContentLength, System::Net::HttpWebRequest::ContentType
-System::Net::HttpWebRequest::GetRequestStream
-This program the demonstrates 'Method', 'ContentLength', and 'ContentType' properties and the 'GetRequestStream'
-method of the HttpWebRequest Class.
-It creates a 'HttpWebRequest' Object*. The 'Method' property of 'HttpWebRequestClass' is set to 'POST'.
-The 'ContentType' property is set to 'application/x-www-form-urlencoded'. The 'ContentLength' property
-is set to the length of the Byte stream to be posted. A new 'Stream' Object* is obtained from the
-'GetRequestStream' method of the 'HttpWebRequest' class. Data to be posted is requested from the user.
-Data is posted using the stream Object*. The HTML contents of the page are then displayed to the console
-after the Posted data is accepted by the URL.
-Note: This program POSTs data to the Uri: http://www20.Brinkster::com/codesnippets/next.asp
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-int main()
-{
- try
- {
- // Create a new WebRequest Object to the mentioned Uri.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com/codesnippets/next.asp" ) );
-
- Console::WriteLine( "\nThe value of 'ContentLength' property before sending the data is {0}", myHttpWebRequest->ContentLength );
-
-//
-//
- // Set the 'Method' property of the 'Webrequest' to 'POST'.
- myHttpWebRequest->Method = "POST";
- Console::WriteLine( "\nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :" );
-
- // Create a new String* Object* to POST data to the Url.
- String^ inputData = Console::ReadLine();
-
-//
-//
- String^ postData = String::Concat( "firstone= ", inputData );
- ASCIIEncoding^ encoding = gcnew ASCIIEncoding;
- array^ byte1 = encoding->GetBytes( postData );
-
- // Set the content type of the data being posted.
- myHttpWebRequest->ContentType = "application/x-www-form-urlencoded";
-
- // Set the content length of the String* being posted.
- myHttpWebRequest->ContentLength = byte1->Length;
-
- Stream^ newStream = myHttpWebRequest->GetRequestStream();
-
- newStream->Write( byte1, 0, byte1->Length );
- Console::WriteLine( "The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest->ContentLength );
-
- // Close the Stream Object*.
- newStream->Close();
-//
-//
-//
-//
- Console::WriteLine( "\nThe String* entered is successfully posted to the Uri " );
- Console::WriteLine( "Please wait for the response......." );
-
- // Assign the response Object* of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^ readBuff = gcnew array(256);
- int count = streamRead->Read( readBuff, 0, 256 );
-
- Console::WriteLine( "\nThe contents of the HTML page are : " );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuff,0,count );
- Console::WriteLine( outputData );
- count = streamRead->Read( readBuff, 0, 256 );
- }
-
- // Close the Stream object.
- streamResponse->Close();
- streamRead->Close();
-
- // Release the resources held by response Object*.
- myHttpWebResponse->Close();
- Console::WriteLine( "\nPress 'Enter' Key to Continue............." );
- Console::Read();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "WebException raised!" );
- Console::WriteLine( "\n {0}", e->Message );
- Console::WriteLine( "\n {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "Exception raised!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Headers/CPP/httpwebrequest_headers.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Headers/CPP/httpwebrequest_headers.cpp
deleted file mode 100644
index dbc0defcc7f..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Headers/CPP/httpwebrequest_headers.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*System::Net::HttpWebRequest::Headers
-This program demonstrates the 'Headers' property of 'HttpWebRequest' Class.
-A new 'HttpWebRequest' Object* is created.
-The (name, value) collection of the Http Headers are displayed to the console.
-The contents of the HTML page of the requested URI are displayed to the console.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-int main()
-{
- try
- {
-//
- // Create a new 'HttpWebRequest' Object to the mentioned URL.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com" ) );
- // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
- Console::WriteLine( "\nThe HttpHeaders are \n\n\tName\t\tValue\n {0}", myHttpWebRequest->Headers );
- // Print the HTML contents of the page to the console.
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^ readBuff = gcnew array(256);
- int count = streamRead->Read( readBuff, 0, 256 );
- Console::WriteLine( "\nThe HTML contents of page the are : \n\n " );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuff,0,count );
- Console::Write( outputData );
- count = streamRead->Read( readBuff, 0, 256 );
- }
- streamResponse->Close();
- streamRead->Close();
- // Release the HttpWebResponse Resource.
- myHttpWebResponse->Close();
-//
- Console::WriteLine( "\nPress 'Enter' Key to Continue........." );
- Console::Read();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- Console::WriteLine( "Status : {0}", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException Caught!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_IfModifiedSince/CPP/httpwebrequest_ifmodifiedsince.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_IfModifiedSince/CPP/httpwebrequest_ifmodifiedsince.cpp
deleted file mode 100644
index 2ffbd73948e..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_IfModifiedSince/CPP/httpwebrequest_ifmodifiedsince.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-
-
-/*
-System::Net::HttpWebRequest::IfModifiedSince
-This program demonstrates the 'IfModifiedSince' property of the 'HttpWebRequest' class .
-A new 'HttpWebrequest' Object* is created.
-A new 'DateTime' Object* is created with the value intialized to the present DateTime.
-The 'IfModifiedSince' property of 'HttpWebRequest' Object* is compared with the 'DateTime' Object*.
-If the requested page has been modified since the time of the DateTime Object*
-then the output displays the page has been modified
-else the response headers and the contents of the page of the requested Uri are printed to the Console.
-*/
-#using
-
-using namespace System;
-using namespace System::Net;
-using namespace System::IO;
-using namespace System::Text;
-int main()
-{
- try
- {
-
- //
- // Create a new 'Uri' object with the mentioned string.
- Uri^ myUri = gcnew Uri( "http://www.contoso.com" );
-
- // Create a new 'HttpWebRequest' object with the above 'Uri' object.
- HttpWebRequest^ myHttpWebRequest = dynamic_cast(WebRequest::Create( myUri ));
-
- // Create a new 'DateTime' object.
- DateTime targetDate = DateTime::Now;
- // Set a target date of a week ago
- targetDate.AddDays(-7.0);
- myHttpWebRequest->IfModifiedSince = targetDate;
-
- try
- {
-
- // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = dynamic_cast(myHttpWebRequest->GetResponse());
- Console::WriteLine( "Response headers \n {0}\n", myHttpWebResponse->Headers );
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^readBuff = gcnew array(256);
- int count = streamRead->Read( readBuff, 0, 256 );
- Console::WriteLine( "\nThe contents of Html Page are : \n" );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuff,0,count );
- Console::Write( outputData );
- count = streamRead->Read( readBuff, 0, 256 );
- }
- streamResponse->Close();
- streamRead->Close();
-
- // Release the HttpWebResponse Resource.
- myHttpWebResponse->Close();
- Console::WriteLine( "\nPress 'Enter' key to continue................." );
- Console::Read();
- }
- catch ( WebException^ e )
- {
- if (e->Response)
- {
- if ( ((HttpWebResponse ^)e->Response)->StatusCode == HttpStatusCode::NotModified)
- Console::WriteLine("\nThe page has not been modified since {0}", targetDate);
- else
- Console::WriteLine("\nUnexpected status code = {0}", ((HttpWebResponse ^)e->Response)->StatusCode);
- }
- else
- Console::WriteLine("\nUnexpected Web Exception {0}" + e->Message);
- }
-//
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException Caught!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException raised!" );
- Console::WriteLine( "Source : {0}", e->Source );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-
-}
-
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_PipeLined/CPP/httpwebrequest_pipelined.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_PipeLined/CPP/httpwebrequest_pipelined.cpp
deleted file mode 100644
index df05ea9c022..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_PipeLined/CPP/httpwebrequest_pipelined.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/*System::Net.HttpWebRequest::PipeLined
-This program demonstrates 'Pipelined' property of the 'HttpWebRequest' class.
-A new 'HttpWebRequest' Object* is created. The 'Pipelined' property is displayed to the console.
-HTTP Request and Response Headers are displayed to the console. The contents of the page of the
-requested URI are displayed to the console.
-
-Note:The 'Pipelined' property is supported only by servers that allow Pipelining of requests.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-void GetPage( String^ myUri )
-{
- try
- {
-//
- // Create a 'HttpWebRequest' object.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( myUri ) );
- // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
- // Display the contents of the page to the console.
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^ readBuffer = gcnew array(256);
- int count = streamRead->Read( readBuffer, 0, 256 );
- Console::WriteLine( "\nThe contents of HTML page are......." );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuffer,0,count );
- Console::Write( outputData );
- count = streamRead->Read( readBuffer, 0, 256 );
- }
- Console::WriteLine( "\nHTTP Request Headers :\n\n {0}", myHttpWebRequest->Headers );
- Console::WriteLine( "\nHTTP Response Headers :\n\n {0}", myHttpWebResponse->Headers );
- streamRead->Close();
- streamResponse->Close();
- // Release the response object resources.
- myHttpWebResponse->Close();
- Console::WriteLine( "\n'Pipelined' property is: {0}", myHttpWebRequest->Pipelined );
- Console::WriteLine( "\nPress 'Enter' Key to Continue......" );
- Console::Read();
-//
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException Caught!" );
- Console::WriteLine( "Message : {0} ", e->Message );
- }
-}
-
-int main()
-{
- array^ args = Environment::GetCommandLineArgs();
- try
- {
- if ( args->Length < 2 )
- {
- Console::WriteLine( "\nPlease enter the Uri address as a command line parameter:" );
- Console::WriteLine( "->Item[ Usage:HttpWebRequest_Pipelined http://www.microsoft.com ]" );
- }
- else
- {
- GetPage( args[ 1 ] );
- }
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException Caught!" );
- Console::WriteLine( "Message : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_ProtocolVersion/CPP/httpwebrequest_protocolversion.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_ProtocolVersion/CPP/httpwebrequest_protocolversion.cpp
deleted file mode 100644
index c8320fd47ff..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_ProtocolVersion/CPP/httpwebrequest_protocolversion.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* System::Net::HttpWebRequest::ProtocolVersion
-This Program demonstrates the 'ProtocolVersion' property of the 'HttpWebRequest' Class.
-The 'ProtocolVersion' is a property that identifies the Version of the Protocol being used.
-A new 'HttpWebRequest' Object* is created. Then the default version, being used is displayed onto
-the console. It is then set to another version and displayed to the Console::The HTML contents
-of the page of the requested Uri are printed to the console.
-Note: Here the 'ProtocolVersion' property displays the ProtocolVersion being used.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-int main()
-{
- try
- {
-//
- // Create a new 'HttpWebRequest' Object to the mentioned URL.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.microsoft.com" ) );
- // Use the existing 'ProtocolVersion' , and display it onto the console.
- Console::WriteLine( "\nThe 'ProtocolVersion' of the protocol used is {0}", myHttpWebRequest->ProtocolVersion );
- // Set the 'ProtocolVersion' property of the 'HttpWebRequest' to 'Version1::0' .
- myHttpWebRequest->ProtocolVersion = HttpVersion::Version10;
- // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
- Console::WriteLine( "\nThe 'ProtocolVersion' of the protocol changed to {0}", myHttpWebRequest->ProtocolVersion );
- Console::WriteLine( "\nThe protocol version of the response Object* is {0}", myHttpWebResponse->ProtocolVersion );
-//
- Console::WriteLine( "\nPress any Key to Continue.............." );
- Console::Read();
- Console::Read();
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array^ readBuff = gcnew array(256);
- int count = streamRead->Read( readBuff, 0, 256 );
- Console::WriteLine( "\nThe contents of the HTML Page are :" );
- while ( count > 0 )
- {
- String^ outputData = gcnew String( readBuff,0,count );
- Console::Write( outputData );
- count = streamRead->Read( readBuff, 0, 256 );
- }
- streamResponse->Close();
- streamRead->Close();
- // Release the HttpWebResponse Resource.
- myHttpWebResponse->Close();
- Console::WriteLine( "\nPress any Key to Continue.............." );
- Console::Read();
- Console::Read();
- }
- catch ( WebException^ e )
- {
- Console::WriteLine( "\nWebException raised!" );
- Console::WriteLine( "\nMessage: {0} ", e->Message );
- Console::WriteLine( "\nStatus: {0} ", e->Status );
- }
- catch ( Exception^ e )
- {
- Console::WriteLine( "\nException raised!" );
- Console::WriteLine( "\nSource : {0}", e->Source );
- Console::WriteLine( "\nMessage : {0}", e->Message );
- }
-}
diff --git a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Referer/CPP/httpwebrequest_referer.cpp b/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Referer/CPP/httpwebrequest_referer.cpp
deleted file mode 100644
index b5053d05743..00000000000
--- a/snippets/cpp/VS_Snippets_Remoting/HttpWebRequest_Referer/CPP/httpwebrequest_referer.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/*System::Net::HttpWebRequest::Referer
-This program demonstrates the 'Referer' property of the 'HttpWebRequest' class.
-A new 'HttpWebRequest' Object* is created. The 'Referer' property is displayed to the console.
-HTTP Request and Response Headers are displayed to the console. The contents of the page of the
-requested URI are displayed to the console.
-
-Note: The 'Referer' property is used by the server to store the address of the Uri that has referred
-the request to that server.Please refer to RFC 2616 for more information on HTTP Headers.
-*/
-
-#using
-
-using namespace System;
-using namespace System::IO;
-using namespace System::Net;
-using namespace System::Text;
-
-void GetPage( String^ myUri )
-{
- try
- {
-//
- // Create a 'HttpWebRequest' object.
- HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( myUri ) );
- // Set referer property to http://www.microsoft.com .
- myHttpWebRequest->Referer = "http://www.microsoft.com";
- // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
- HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
- // Display the contents of the page to the console.
- Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
- StreamReader^ streamRead = gcnew StreamReader( streamResponse );
- array