Information Technology Reference
In-Depth Information
trusted. The only alternative is to avoid the protected resource entirely.
Consider the Windows Registry, for example. If your program needs to
access the Registry, you must install your program to the end user's com-
puter so that it has the necessary privileges to access the Registry. You sim-
ply can't safely create a Registry editor that runs from the Web. That's the
way it should be.
The .NET Security model means that your program's actions are checked
against its rights. Pay attention to the rights your program needs and try
to minimize them. Don't ask for rights you don't need. The fewer pro-
tected resources your assembly needs, the less likely it will generate secu-
rity exceptions. Avoid using secure resources, and consider alternatives
whenever possible. When you do need higher security permissions for
some algorithms, isolate that code in its own assembly.
Item 49: Prefer CLS-Compliant Assemblies
The .NET environment is language agnostic: Developers can incorporate
components written in different .NET languages without limitations. In
practice, it's almost true. You must create assemblies that are compliant
with the Common Language Subsystem (CLS) to guarantee that develop-
ers writing programs in other languages can use your components.
One of C#'s advantages is that because it was designed to run on the CLR,
almost all of your C# assemblies will be CLS compliant. That's not true
for many other languages. Many F# constructs do not compile down to
CLS-compliant types. DLR languages, such as IronPython and IronRuby,
do not create CLS-compliant assemblies in this release. That's one of the
reasons C# is an excellent choice for component development in .NET. C#
components can be consumed by all the languages that run on the CLR.
That's because it's not that hard to create C# components that are CLS
compliant.
CLS compliance is a new twist on that least common denominator
approach to interoperability. The CLS specification is a subset of opera-
tions that every language must support. To create a CLS-compliant assem-
bly, you must create an assembly whose public interface is limited to those
features in the CLS specification. Then any language supporting the CLS
specification must be capable of using the component. This does not mean
you must limit your entire programming palette to the CLS-compliant
subset of the C# language, however.
 
 
Search WWH ::




Custom Search