Controlling Component Visibility Beyond Private and Internal

When you are working on applications it's common to run across situations where you want to restrict access to a component you have written. Usually, you control this access using the private and/or internal keywords when defining the component. A class marked as internal can be accessed by any other class in the same assembly, but that may not be the level of restriction needed within the codebase. Access to a private class is restricted to those components that are inside the same class or struct that contains the private class, which prevents any other classes from accessing it. In one situation we are restricting access to the component to only the class or struct that contains it. In the other situation, we are allowing access to the component from any other component that is in the same assembly. What if needed something in between?

PostSharp offers the ability to define component access rules that exist between the scope of the internal and private keywords. This gives us the opportunity to restrict access to a component only from other components in the same namespace. We can also restrict access to a select few other components.

As an example let's look at a data access related class. As a precaution against developer's circumventing our data access structure we want to limit access to this repository class.

This topic contains the following sections:

Our first step is to limit access to this class only to other classes within the validation namespace.

Put the caret on the internal class that should have restricted access. Select "Add architectural constraint. " from the smart tag options.

Private pass beyond

Select "Prohibit use outside of given types" from the list of options.

Private pass beyond

Verify that you will be adding the ComponentInternalAttribute attribute to the correct piece of code.

Private pass beyond

Once the download, installation and configuration of PostSharp have finished you can close the wizard and look at the changes that were made to your codebase.

Private pass beyond

You'll notice that the only thing that has changed in the code is the addition of the [ComponentInternalAttribute] attribute.

The [ComponentInternalAttribute] attribute is templated to accept a string for the namespace that should be able to access this method. There are two options that you could use. The first is to pass the attribute an array of typeof(. ) values that represents the types that can access this method. The second option is to pass in an array of strings that contain the namespaces of the code that should be able to access this method. For our example, replace the typeof(TODO) with a string for the validation namespace.

If you try to access this component from a namespace that hasn't been granted access you will see a compile time warning in the Output window.

Private pass beyond

If you are trying to access the component from a namespace that is in a different project you will need PostSharp to process that project for the validation to occur.

Under some circumstances, namespace level restrictions may not be tight enough for your needs. In that situation, you have the ability to apply this constraint at a type level.

To restrict access at a component type level you need to explicitly define which component types will have access. This is done by passing types into the constructor of the ComponentInternalAttribute attribute's constructor. The construct accepts an array of Type which allows you to define many different component types that should be granted access.

Now if you try to access this component from a type that hasn't been granted access you will see a compile time warning in the Output window.

Private pass beyond

Because of framework limitations or automated testing requirements you sometimes need to declare components as public so that you can perform the desired tasks or testing. For some of those components, you probably don't want external applications accessing them. For instance, WPF controls need a default constructor for use in the designer, but sometimes you want another constructor to be used at run time, so you want to prevent the default constructor to be used from code.

PostSharp offers you the ability to decorate a publically declared component in such a way that it is not accessible by applications that reference its assembly. All you need to do is apply the InternalAttribute attribute.

Let's mark the Customer class so that it can only be accessed from the assembly it resides in.

Place the caret on the publically declared component that you want to restrict external access to and expand the smart tag. Select "Add architectural constraint".

Private pass beyond

When prompted to select a constraint, choose to "Prohibit use outside of the project".

Private pass beyond

The summary page gives you the opportunity to review the selections that you have made. If you notice that the configuration is not what you wanted you can click the Previous button and adjust your selections. If the configuration meets your needs click Next . In this demo, you will see that the [InternalAttribute] attribute is being added to the Customer class.

Private pass beyond

Once the download, installation and configuration of PostSharp have finished you can close the wizard and look at the changes that were made to your codebase.

Private pass beyond

You'll notice that the only thing that has changed in the code is the addition of the [InternalAttribute] attribute.


Finally – A Bipartisan Internet Privacy Bill that Can Pass Congress

Private pass beyond

Private pass beyond

Can the government access information stored on the cloud without a warrant? Under current law, the answer is a hard maybe.

Congress can quickly fix this uncertainty by passing the bipartisan International Communications Privacy Act (ICPA), updated in the Senate this month by Sen. Orrin Hatch (R-Utah) and Chris Coons (D-Del.). This law will strengthen privacy of email and other electronic data, all while respecting the data privacy laws of other countries.

To understand just how complicated current electronic privacy law is, look no further than the Microsoft v. United States case. The United States government cited the 1986 Electronic Communications Privacy Act (ECPA) as precedent to access Microsoft customers’ emails and other electronic communications because under that legislation, law enforcement can access any data older than 180 days. That law was passed in 1986, long before the cloud was even invented. Microsoft, which has a moral and legal obligation to respect all countries’ laws, took dispute with their interpretation of ECPA.

On July 14, 2016, the Second Circuit Court of Appeals also took issue with the government’s interpretation. Reversing the Southern District Court of New York’s opinion, the appeals court sided with the plaintiff, stating that the government cannot compel Microsoft, or any other company, to turn over foreign nationals’ emails stored on servers outside the United States. The ruling cast doubt on whether ECPA applies extraterritorially. However, uncertainty still persists since the DOJ promptly filed to reopen this case.

Congress can and should clear this up by passing ICPA, which will ensure that the government strikes the right balance between privacy rights and the needs of law enforcement and other agencies working to protect us from terrorism.

ICPA will require law enforcement agencies to respect the privacy laws of other countries. The legislation will simplify U.S. law regarding computer data within the United States and, when necessary, authorize U.S. law enforcement to obtain data relating to foreign nationals located outside the United States.

Perhaps most importantly, ICPA will reform the Mutual Legal Assistance Treaty (MLAT) to provide greater accessibility, transparency, and accountability. The legislation will also require the Attorney General to create an online docketing system for MLAT requests and to publish statistics on the number of such requests.

The importance of passing this legislation becomes even more clear when analyzing the empirical data surrounding terrorism, which overwhelmingly shows that becoming more selective on data collection is one of the best ways to protect our national security.

Studies show that the mass collection of e-mails has led to tens of thousands of false leads for every real hit, making locating terrorists the equivalent of finding a needle in a haystack. That’s why the Pulse nightclub shooter, Boston marathon bombers, and Garland shooters were all successful even though the CIA and FBI received an abundance of cautionary tips on the perpetrators’ possible intentions well in advance.

Before killing 50 innocent Americans, Omar Mateen had been questioned twice by the FBI after members of his local mosque reported him. Similarly, the CIA and FBI were cautioned about the Tsarnaev brothers years before the Boston Bombing, while the government did not act on the probable cause it had to investigate the shooters in Garland. The CIA and FBI were too overwhelmed with other leads to analyze the situation at hand, and we paid with American lives. Clearly, paying more attention to those that we, through the Fourth Amendment, have probable cause to investigate would be in everyone’s best interest.

Congress should not wait years before the court decides to act on this issue. The body should do its job and protect the American people by working to reform the law now. Passing ICPA would certainly be a great place to start.

Dean Chambers is a political commentator and former national pollster whose work has been featured on the Drudge Report and on The Rush Limbaugh Program, as well as parodied by Stephen Colbert, Chris Matthews, and Rachel Maddow.


Beyond The Mat: The Private Lives Of The Miyao Brothers

Private pass beyond

Private pass beyond

Sometimes, people get caught up in trying to replicate successful athletes' lives. They believe following in their footsteps will allow them to achieve similar results. But as I learned by spending time with the Miyao brothers, this simply isn't realistic.

witnessed firsthand after a training session. I've never seen someone eat so much food. Plate after plate was copious, but healthy. He enjoyed every second.