assembly.GetTypes() vs assembly.DefinedTypes.Select(t => t.AsType());

public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly)
    {
        try
        {
#if NET40
            return assembly.GetTypes();
#else
            return assembly.DefinedTypes.Select(t => t.AsType());
#endif
        }
        catch (ReflectionTypeLoadException ex)
        {
            // The exception is thrown if some types cannot be loaded in partial trust.
            // For our purposes we just want to get the types that are loaded, which are
            // provided in the Types property of the exception.
            return ex.Types.Where(t => t != null);
        }
    }

What are differences between assembly.GetTypes() and assembly.DefinedTypes.Select(t => t.AsType())?

Original code:
https://entityframework.codeplex.com/SourceControl/latest#src/Common/AssemblyExtensions.cs

0

From the MSDN documentation: “The DefinedTypes property is comparable to the Assembly.GetTypes method, except that the DefinedTypes property returns a collection of TypeInfo objects, and the Assembly.GetTypes method returns an array of Type objects.”

Not terribly useful at first sight. Looking further into the documentation on TypeInfo is much more informative: “A TypeInfo object represents the type definition itself, whereas a Type object represents a reference to the type definition. Getting a TypeInfo object forces the assembly that contains that type to load. In comparison, you can manipulate Type objects without necessarily requiring the runtime to load the assembly they reference.”

The reason for this is outlined in a microsoft blog post, outlining the changes to the reflection API introduced in .NET 4.5. The main difference is that the Type now no longer necessarily forces the loading of the type, and works much more as a slim handle into the type metadata, hence making introspection much lighter.

At a minimum, the returned objects are different types, with one being an array of Types and the other being a generic IQueryable<Type>.

Here is the code from Assembly.GetTypes()

[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine | ResourceScope.Assembly, ResourceScope.Machine | ResourceScope.Assembly)] 
public virtual Type[] GetTypes() 
{
    Module[] m = GetModules(false); 

    int iNumModules = m.Length;
    int iFinalLength = 0;
    Type[][] ModuleTypes = new Type[iNumModules][]; 

    for (int i = 0; i < iNumModules; i++) 
    { 
        ModuleTypes[i] = m[i].GetTypes();
        iFinalLength += ModuleTypes[i].Length; 
    }

    int iCurrent = 0;
    Type[] ret = new Type[iFinalLength]; 
    for (int i = 0; i < iNumModules; i++)
    { 
        int iLength = ModuleTypes[i].Length; 
        Array.Copy(ModuleTypes[i], 0, ret, iCurrent, iLength);
        iCurrent += iLength; 
    }

    return ret;
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

assembly.GetTypes() vs assembly.DefinedTypes.Select(t => t.AsType());

public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly)
    {
        try
        {
#if NET40
            return assembly.GetTypes();
#else
            return assembly.DefinedTypes.Select(t => t.AsType());
#endif
        }
        catch (ReflectionTypeLoadException ex)
        {
            // The exception is thrown if some types cannot be loaded in partial trust.
            // For our purposes we just want to get the types that are loaded, which are
            // provided in the Types property of the exception.
            return ex.Types.Where(t => t != null);
        }
    }

What are differences between assembly.GetTypes() and assembly.DefinedTypes.Select(t => t.AsType())?

Original code:
https://entityframework.codeplex.com/SourceControl/latest#src/Common/AssemblyExtensions.cs

0

From the MSDN documentation: “The DefinedTypes property is comparable to the Assembly.GetTypes method, except that the DefinedTypes property returns a collection of TypeInfo objects, and the Assembly.GetTypes method returns an array of Type objects.”

Not terribly useful at first sight. Looking further into the documentation on TypeInfo is much more informative: “A TypeInfo object represents the type definition itself, whereas a Type object represents a reference to the type definition. Getting a TypeInfo object forces the assembly that contains that type to load. In comparison, you can manipulate Type objects without necessarily requiring the runtime to load the assembly they reference.”

The reason for this is outlined in a microsoft blog post, outlining the changes to the reflection API introduced in .NET 4.5. The main difference is that the Type now no longer necessarily forces the loading of the type, and works much more as a slim handle into the type metadata, hence making introspection much lighter.

At a minimum, the returned objects are different types, with one being an array of Types and the other being a generic IQueryable<Type>.

Here is the code from Assembly.GetTypes()

[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine | ResourceScope.Assembly, ResourceScope.Machine | ResourceScope.Assembly)] 
public virtual Type[] GetTypes() 
{
    Module[] m = GetModules(false); 

    int iNumModules = m.Length;
    int iFinalLength = 0;
    Type[][] ModuleTypes = new Type[iNumModules][]; 

    for (int i = 0; i < iNumModules; i++) 
    { 
        ModuleTypes[i] = m[i].GetTypes();
        iFinalLength += ModuleTypes[i].Length; 
    }

    int iCurrent = 0;
    Type[] ret = new Type[iFinalLength]; 
    for (int i = 0; i < iNumModules; i++)
    { 
        int iLength = ModuleTypes[i].Length; 
        Array.Copy(ModuleTypes[i], 0, ret, iCurrent, iLength);
        iCurrent += iLength; 
    }

    return ret;
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

assembly.GetTypes() vs assembly.DefinedTypes.Select(t => t.AsType());

public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly)
    {
        try
        {
#if NET40
            return assembly.GetTypes();
#else
            return assembly.DefinedTypes.Select(t => t.AsType());
#endif
        }
        catch (ReflectionTypeLoadException ex)
        {
            // The exception is thrown if some types cannot be loaded in partial trust.
            // For our purposes we just want to get the types that are loaded, which are
            // provided in the Types property of the exception.
            return ex.Types.Where(t => t != null);
        }
    }

What are differences between assembly.GetTypes() and assembly.DefinedTypes.Select(t => t.AsType())?

Original code:
https://entityframework.codeplex.com/SourceControl/latest#src/Common/AssemblyExtensions.cs

0

From the MSDN documentation: “The DefinedTypes property is comparable to the Assembly.GetTypes method, except that the DefinedTypes property returns a collection of TypeInfo objects, and the Assembly.GetTypes method returns an array of Type objects.”

Not terribly useful at first sight. Looking further into the documentation on TypeInfo is much more informative: “A TypeInfo object represents the type definition itself, whereas a Type object represents a reference to the type definition. Getting a TypeInfo object forces the assembly that contains that type to load. In comparison, you can manipulate Type objects without necessarily requiring the runtime to load the assembly they reference.”

The reason for this is outlined in a microsoft blog post, outlining the changes to the reflection API introduced in .NET 4.5. The main difference is that the Type now no longer necessarily forces the loading of the type, and works much more as a slim handle into the type metadata, hence making introspection much lighter.

At a minimum, the returned objects are different types, with one being an array of Types and the other being a generic IQueryable<Type>.

Here is the code from Assembly.GetTypes()

[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine | ResourceScope.Assembly, ResourceScope.Machine | ResourceScope.Assembly)] 
public virtual Type[] GetTypes() 
{
    Module[] m = GetModules(false); 

    int iNumModules = m.Length;
    int iFinalLength = 0;
    Type[][] ModuleTypes = new Type[iNumModules][]; 

    for (int i = 0; i < iNumModules; i++) 
    { 
        ModuleTypes[i] = m[i].GetTypes();
        iFinalLength += ModuleTypes[i].Length; 
    }

    int iCurrent = 0;
    Type[] ret = new Type[iFinalLength]; 
    for (int i = 0; i < iNumModules; i++)
    { 
        int iLength = ModuleTypes[i].Length; 
        Array.Copy(ModuleTypes[i], 0, ret, iCurrent, iLength);
        iCurrent += iLength; 
    }

    return ret;
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật