Welcome to weblogs.com.pk Sign in | Join | Help

C# Wishes (Part 1)

This post is made in hurry, as firstly I am at remote location, secondly, I just wanted to post these two wishes that I was missing a lot while coding a couple of classes for a new business process.

 

I also have few other wishes that I will try to post sometime in near future. If you have certain wishes, feel free to write in feedback/comments.

 

Warning: The code shown in this post may not be syntactically correct.

 

in keyword

 

It would be nice if "in" keyword in C#, can also behave like TSQL's "in"

 

For example:

 

int i=1;

int[] goodValues=this.goodValues; //May be from DB

int[] badValues=this.badValues;

if (i in goodValues) && (!i in badValues)

{

   //i is good, lets do something with it

}

 

friend keyword

 

It would be nice if C/C++’s friend keyword is added to C#, but with more power

 

Yes, we have internal keyword, that dont expose the class across assembly, but what if we need to produce one assembly, and still need that certain classes are called within assembly through their proper wrappers, or may be certain classes cann't be called from unwanted classes, even in the same assembly. It can be helpful to enforce certain enterprise development rules and also to enforce certain patterns/practises.

The friend capability should cover friend classes, as well as friend namespaces, i-e white list of classe(s) and white list of namespace(s) that can access certain class

For example:

  • Team1 is assigned to implement Facade1 and Facade2 classes
  • Team1 is very good in databases; they are also assigned to code DBhelper class that other teams involved in the given Product can use.
  • Facade1 and Facade2 will be used by the classes that are implementing public interfaces.
  • Team1 has implemented helper class that they only want that it can be used by the Facade classes, that they are exposing.
  • We need single assembly, Company.Product

 

namespace Company.Product

{

   public nterface IFunctionality

   {

      //Some interface

   }

   public class Factory

   {

      public IFunctionality GetImplementation()

      {

         //Factory code

      }

   }

   internal class Implementation : IFunctionality

   {

      //Implements IFucntionality

      //using Facade1, Facade2 from Team1

      //and other Facades from other Teams

   }

}

namespace Company.Product.Team2

{

   internal class Facade3

   {

      //Implementation that also uses Company.Product.Team1.DBHelper

   }

}

namespace Company.Product.Team1

{

internal class Facade1

{

   //Implementation that uses helper

}

internal class Facade2

{

   //Implementation that uses helper

}

friend[classes={Company.Product.Team1.Facade1, Company.Product.Team1.Facade2}]

internal class helper

{

   //Implementation

}

internal class DBHelper

{

}

}

Published Saturday, April 3, 2004 10:23 PM by khurram

Comments

No Comments

New Comments to this post are disabled