public static TargetMapping DeriveMapping(string targetName, string prefix, TypeInfo typeInfo)
        {
            TargetMapping mapping          = null;
            var           baseTypes        = typeInfo.GetAllBaseTypes().Where(x => x.IsGenericType);
            var           firstGenericType = baseTypes.First();

            // TODO: Consider root and namespace layers or nested types, when problems are better understood
            if (TryGetMapping(firstGenericType, typeof(CodeFirstMetadataNamespace <>), typeof(TargetNamespaceMapping <>), targetName, prefix, ref mapping))
            {
                return(mapping);
            }
            if (TryGetMapping(firstGenericType, typeof(CodeFirstMetadataClass <>), typeof(TargetClassMapping <>), targetName, prefix, ref mapping))
            {
                return(mapping);
            }
            if (TryGetMapping(firstGenericType, typeof(CodeFirstMetadataMethod <>), typeof(TargetMethodMapping <>), targetName, prefix, ref mapping))
            {
                return(mapping);
            }
            if (TryGetMapping(firstGenericType, typeof(CodeFirstMetadataProperty <>), typeof(TargetPropertyMapping <>), targetName, prefix, ref mapping))
            {
                return(mapping);
            }
            if (TryGetMapping(firstGenericType, typeof(CodeFirstMetadataParameter <>), typeof(TargetParameterMapping <>), targetName, prefix, ref mapping))
            {
                return(mapping);
            }
            throw new NotImplementedException();
        }
 private static bool TryGetMapping(TypeInfo firstGenericType, Type sourceType, Type targetType,
                                   string targetName, string prefix, ref TargetMapping mapping)
 {
     if (firstGenericType.GetGenericTypeDefinition() == sourceType.GetTypeInfo())
     {
         // Not crazy about this, but a lot of mapping work happens in the constructors here
         mapping = ReflectionHelpers.CreateInstanceOfType <TargetMapping>(targetType.GetTypeInfo(),
                                                                          firstGenericType, targetName, prefix, firstGenericType);
         return(true);
     }
     return(false);
 }
 private static bool TryGetMapping(TypeInfo firstGenericType, Type sourceType, Type targetType,
  string targetName, string prefix, ref TargetMapping mapping)
 {
     if (firstGenericType.GetGenericTypeDefinition() == sourceType.GetTypeInfo())
      {
     // Not crazy about this, but a lot of mapping work happens in the constructors here
     mapping = ReflectionHelpers.CreateInstanceOfType<TargetMapping>(targetType.GetTypeInfo(),
              firstGenericType, targetName, prefix, firstGenericType);
     return true;
      }
      return false;
 }