<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Uses Reflection to create an instance of a generic type specified using the default constructor.</Title>
      <Shortcut>UsesReflectiontocreateaninstanceofagenerictypespecifiedusingthedefaultconstructor.</Shortcut>
      <Description>Uses Reflection to create an instance of a generic type specified using the default constructor. [C#]</Description>
      <Author>John Tolar</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=2514b9dd-a540-4039-9d6c-2ca0b4cc9007</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[/// <summary>
        /// Creates an instance of the generic type specified using the default
        /// constructor.
        /// </summary>
        /// <typeparam name="T">The type to instantiate.</typeparam>
        /// <param name="type">The System.Type being instantiated.</param>
        /// <returns>An instance of the specified type.</returns>
        /// <example>
        /// typeof(MyObject).CreateInstance();
        /// </example>
        public static T CreateInstance<T>(this Type type) where T : new()
        {
            return Activator.CreateInstance<T>();
        }]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>