Gist: psisContainer > Filter Directories using Powershell

To filter the folders (i.e., directories) available in the current context, the following property can be used with a predicate:$_.psiscontainer

In essence, it returns a boolean indicating whether the current object is a directory or not. Hence, the following script prints the absolute path of the each sub-directories from the current context.

ls –r | ?{$_.psiscontainer} | select fullname

Remove SVN binding

By invoking the following powershell commands, svn binding can be removed effectively from the current source directory.

Get-ChildItem -Include .svn -Recurse -Force | ForEach-Object { del $_.FullName -Recurse -Force }
view raw gistfile1.ps1 hosted with ❤ by GitHub

It just traverses all the subdirectories of the current directory and remove its enclosed .svn directories. As a result, the associated svn bindings get removed.

Code Snippet: Adding a File to .net Resource

Last few days, I was thinking to jot down all the code snippet that I used very frequently.  Here comes the first one –

Today’s post will be covering a simple aspect of every .net project where one has to add files in Resource and get it from there for further processing.

To Add & Get the file from the resource , we have to –

1. Select the file that we want to put in the resource –



And from the property window, set the Build Action = “Embedded Resource”.


2. To get file from the resource, we have to write following few lines of codes –



In this code snippet , as we can see , I am getting the resource from the Assembly Menifest and returning it as XmlReader to the caller as –



And we are done.

Interface 101: Explicit Interface Implementation using C#

The primary motivation of introducing inerface is to enforce OO-style of thinking while revoking the drawbacks of multiple inheritance. In fact, the support for explicit interface implementation is an important tool in OO-developers’ toolbox. Utilizing this concept, we can implement multiple interfaces in a class, and still no ambiguity gets introduced.

In fact, explicit interface implementation ensures private accessibility via interface reference. That is, in order to access any member of a class that implements an interface explicitly, an interface reference is required, which supports the concept called “Run-time Bindings“, and introduces a higher level of abstraction.

In the rest of the post we focus on following–

glyphicons Defining interfaces,
glyphicons Implementation of the interfaces explicitly,
glyphicons Advantages of explicit interface implementation.

To do so, we start by defining interfaces and shows how to apply explicit interface implementation using an example. Please note that, this is a simple and contrived example, intended only to be illustrative.

public interface ISimpleCalculator{
int Add(int num1, int num2);
public interface ICalculator{
double Add(double num1, double num2);

The following class Calculator implements both interfaces using explicit interface implementation.

public class Calculator:ISimpleCalculator,ICalculator{
int ISimpleCalculator.Add (int num1, int num2)
return num1 + num2;
double ICalculator.Add (double num1, double num2)
return num1 + num2;
view raw gistfile1.cs hosted with ❤ by GitHub

Now that we have implemented these interfaces, next we see outlines several examples to show how to use this implementation. The first example below tries to use the Add method without interface reference.

Calculator calc = new Calculator();
calc.Add(); // Uncomment it to get the Compile time Error
view raw gistfile1.txt hosted with ❤ by GitHub

Therefore, it gets a compile time error as the implementation is private and can only be accessed via interface reference as follows.

ISimpleCalculator simpleCalc = calc;
int result = simpleCalc.Add(5, 10); // returns 15
view raw gistfile1.txt hosted with ❤ by GitHub

As we have notice that the both interfaces have Add as a member. In fact, Calculator class also implements both Add method via polymorphic references. Next example shows how to invoke ICalculator.Add by using an instance of Calculator.

ICalculator floatingNumberCalculator = calc;
floatingNumberCalculator.Add(3.2 ,5.8);
view raw gistfile1.cs hosted with ❤ by GitHub

To sum up, the key take-aways from this discussion regarding explicit interface implementation are as follows.

glyphicons It make the whole implementation Abstract/Private . That is , you need the interface reference to access that implementation.

glyphicons It allow you to implement multiple Interface and at the same time, does not introduce any ambiguity. So, the polymorphic reference or runtime binding can be implement very efficiently.

We highly appreciate any comment or query regarding this post. Thanks!

See More


[R-1: 02-04-2013] Updated formatting to make this post more consistent with current CSS.