Example #1
0
        /// <summary>
        /// Used to make generic types in a single location.  This helps to make sure that all generic types are made in the same way and that
        /// all generic types that are based upon type builder actually use th typeBuilder.MakeGenericType() method and not Type.MakeGenericType() method.
        /// </summary>
        /// <param name="genericTypeDefinition"></param>
        /// <param name="typeParameters"></param>
        /// <returns></returns>
        public System.Type MakeGenericType(System.Type genericTypeDefinition, Type[] typeParameters)
        {
            return(AssemblyLib.MakeGenericType(genericTypeDefinition, typeParameters));

            //  if (genericTypeDefinition is TypeBuilder typeBuilder)
            //  {
            //// For TypeBuilder.GetConstructor(), TypeBuilder.GetMethod() and TypeBuilder.GetField() to work,
            //// the typebuilder needs to keep track of generic types that it produces.  To do this, the typeBuilder
            //// MakeGeneric method needs to be used over just the normal Type.MakeGenericType() method.
            //   //for (int i = 0; i < typeParameters.Length; i++)
            //   //{
            //   // Console.WriteLine($"MakeGenericType TP[{i}]: {typeParameters[i].Name}");
            //   //}

            //   return typeBuilder.MakeGenericType(typeParameters);
            //  }

            //  //for (int i = 0; i < typeParameters.Length; i++)
            //  //{
            //  // var parameter = typeParameters[i];

            //  // if (parameter.DeclaringType != null && ReferenceEquals(genericTypeDefinition, parameter.DeclaringType))
            //  // {
            //  //  throw new Exception("Declaring type of parameter is same as generic type definition.");
            //  // }
            //  //}

            //  var result = genericTypeDefinition.MakeGenericType(typeParameters);

            //  //if (result.IsGenericTypeDefinition)
            //  //{
            //  // throw new Exception("MakeGenericType returned a generic type definition and not a generic instance.");
            //  //}
            //        return result;
        }
Example #2
0
 public void NumberOfPropertiesShouldBeCorrect()
 {
     Assert.Equal(0, AssemblyLib.GetAssemblyInfo(PATH)?.NamespaceInfos?.Values.First().DataTypeInfos.First().PropertyInfos.Length);
 }
Example #3
0
 public void NumberOfMethodsShouldBeCorrect()
 {
     Assert.Equal(3, AssemblyLib.GetAssemblyInfo(PATH)?.NamespaceInfos.Values.First().DataTypeInfos.First().MethodInfos.Length);
 }
Example #4
0
 public void NumberOfNamespacesShouldBeCorrect()
 {
     Assert.Equal(1, AssemblyLib.GetAssemblyInfo(PATH)?.NamespaceInfos?.Count);
 }
Example #5
0
 public void ShouldReturnNullForInvalidFile()
 {
     Assert.Null(AssemblyLib.GetAssemblyInfo(INCORRECT_FILE_PATH));
 }