[英]How can I distinguish between managed & unmanaged code in C#
As per MSDN, 根据MSDN,
Managed Code - Code that could be understood and managed by CLR
Unmanaged Code - Code that could not handled by CLR
But I am wondering how do I identify which resource or class is CLR compliant & which Not. 但是我想知道如何确定哪个资源或类符合CLR,哪些不符合。
I referred below links 我在下面提到了链接
How do we distinguish between managed and unmanaged resources in C#? 我们如何在C#中区分托管资源和非托管资源? Is TextFieldParser unmanaged? TextFieldParser是否不受管理?
public class Customer { //What makes this CLR compliant } public class DbConnectionHandler: IDisposable { //Database Connection & other related stuff //What makes this CLR Non-Compliant }
If I am using EF (LINQ to Entities), it is translated to native SQL. 如果我使用的是EF(LINQ to Entities),它将转换为本机SQL。 SO all LINQ falls under Unmanaged Code category? 因此,所有LINQ都属于“非托管代码”类别吗?
Thanks! 谢谢!
"unmanaged" here is referring to in-process execution of non-CLR code (don't confuse that with "CLR compliant", whatever that might mean); 这里的“非托管”是指非CLR代码的进程内执行(无论将其与“符合CLR的规范”混为一谈,无论其含义是什么); so - EF and LINQ are managed (or mostly managed), but they often talk indirectly to unmanaged dlls (think: C/C++ dlls, etc - nothing to do with the CLR) at some point - for example, many of the ADO.NET providers are really P/Invoke layers to an unmanaged database drivers - or unsafe
code that talks to manually allocated raw memory in the local process (a chunk of memory allocated via Marshal.AllocHGlobal
, for example). 因此-EF和LINQ是受管理的(或大部分受管理的),但它们有时在某些时候与非受管理的 dll(例如C / C ++ dll等,与CLR无关)进行间接对话-例如,许多ADO。 NET提供程序实际上是非托管数据库驱动程序的P / Invoke层-或与本地进程中手动分配的原始内存(例如,通过Marshal.AllocHGlobal
分配的内存块)进行对话的unsafe
代码。 Usually these exist in a dual state: there's a managed layer that abstracts and hides the unmanaged layer - so application level code rarely talks to unmanaged code directly. 通常,它们以双重状态存在:有一个托管层可以抽象并隐藏非托管层-因此应用程序级代码很少直接与非托管代码对话。
The fact that native SQL is involved is unrelated, as that isn't "managed" or "unmanaged" - it isn't in-process, so it is a different category altogether. 涉及本机SQL的事实是无关的,因为它不是“托管” 或 “非托管”的-它不是进程内的,因此完全是另一类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.