|
96 | 96 |
|
97 | 97 | Assemblies contain type definitions. The <xref:System.Activator.CreateInstance%2A> method creates an instance of a type from a currently running assembly. The <xref:System.Activator.CreateInstanceFrom%2A> method creates an instance from a file that contains an assembly. The <xref:System.Activator.CreateComInstanceFrom%2A> method creates an instance of a COM object from a file that contains an assembly.
|
98 | 98 |
|
| 99 | +
|
| 100 | +
|
99 | 101 | ## Examples
|
100 | 102 | The following example shows how to use the <xref:System.Activator> class to dynamically construct objects at run time.
|
101 | 103 |
|
| 104 | + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ActivatorX/cpp/ActivatorX.cpp" id="Snippet1"::: |
102 | 105 | :::code language="csharp" source="~/snippets/csharp/System/Activator/Overview/ActivatorX.cs" id="Snippet1":::
|
103 | 106 | :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ActivatorX/fs/ActivatorX.fs" id="Snippet1":::
|
104 | 107 | :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/ActivatorX.vb" id="Snippet1":::
|
|
406 | 409 | > [!NOTE]
|
407 | 410 | > Starting with .NET Framework 2.0, this method can be used to access nonpublic types if the caller has been granted <xref:System.Security.Permissions.ReflectionPermission> with the <xref:System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess?displayProperty=nameWithType> flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later.
|
408 | 411 |
|
| 412 | +
|
| 413 | +
|
409 | 414 | ## Examples
|
410 | 415 | The following code example demonstrates how to call the <xref:System.Activator.CreateInstance%28System.Type%29> method. Instances of several different types are created and their default values are displayed.
|
411 | 416 |
|
| 417 | + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ActivatorX/cpp/source2.cpp" id="Snippet4"::: |
412 | 418 | :::code language="csharp" source="~/snippets/csharp/System/Activator/Overview/source2.cs" interactive="try-dotnet" id="Snippet4":::
|
413 | 419 | :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ActivatorX/fs/source2.fs" id="Snippet4":::
|
414 | 420 | :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/source2.vb" id="Snippet4":::
|
@@ -1901,6 +1907,7 @@ An error occurred when attempting remote activation in a target specified in <pa
|
1901 | 1907 | ## Remarks
|
1902 | 1908 | The <xref:System.Activator.CreateInstance%60%601> generic method is used by compilers to implement the instantiation of types specified by type parameters. For example, in the following generic method, the implementation of `new T()` uses the <xref:System.Activator.CreateInstance%60%601> generic method.
|
1903 | 1909 |
|
| 1910 | + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.activation.createinstance~~1/cpp/remarks.cpp" id="Snippet1"::: |
1904 | 1911 | :::code language="csharp" source="~/snippets/csharp/System/Activator/CreateInstanceT/remarks.cs" id="Snippet1":::
|
1905 | 1912 | :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.activation.createinstance~~1/fs/remarks.fs" id="Snippet1":::
|
1906 | 1913 | :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activation.createinstance~~1/vb/remarks.vb" id="Snippet1":::
|
@@ -1993,9 +2000,12 @@ Note: In <see href="https://go.microsoft.com/fwlink/?LinkID=247912">.NET for Win
|
1993 | 2000 |
|
1994 | 2001 | For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the <xref:System.Reflection.Assembly.LoadFrom%2A?displayProperty=nameWithType> and <xref:System.Activator.CreateInstance%2A> methods.
|
1995 | 2002 |
|
| 2003 | +
|
| 2004 | +
|
1996 | 2005 | ## Examples
|
1997 | 2006 | The following code example demonstrates how to call the <xref:System.Activator.CreateInstanceFrom%2A> method. This code example is part of a larger example provided for the <xref:System.Activator> class.
|
1998 | 2007 |
|
| 2008 | + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ActivatorX/cpp/ActivatorX.cpp" id="Snippet3"::: |
1999 | 2009 | :::code language="csharp" source="~/snippets/csharp/System/Activator/Overview/ActivatorX.cs" id="Snippet3":::
|
2000 | 2010 | :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ActivatorX/fs/ActivatorX.fs" id="Snippet3":::
|
2001 | 2011 | :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/ActivatorX.vb" id="Snippet3":::
|
|
0 commit comments