PDA

Click to See Complete Forum and Search --> : communityserver source code


ItWasntMe
Dec 28th, 2005, 07:53 PM
Hi everyone!

I have been looking at the community server source code, found at http://www.communityserver.org/. I understand most of the source but there is one area that's confusing me. Can someone please tell me what the following code is doing? It looks like its returning a class as a data type, are classes themself considered data types? I tried returing a class in my own example to understand what was going on but I get a compiler error saying that a class cannot be passed back.

I tried searching MSDN for information but since I don't know what to search for its hard to find any relevent information.

Does anyone know of an article that will explain using code like this?

I'm not going to post all the code here, just the lines I am having trouble with, and a few surronding lines.

I'm not sure if anyone will even undestand with this limited example, but basically from what I can understand CommonDataProvider is a class and in the second example its returning itself in the return statement, after being returned the first example has access to the CreateUpdateDeleteUser method which is a method found in the SqlProvider.cs.

Maybe if someone else has looked at this code they will know what I'm talking about.

Users.cs

// Create Instance of the CommonDataProvider
CommonDataProvider dp = CommonDataProvider.Instance();
User createdUser = dp.CreateUpdateDeleteUser(user, DataProviderAction.Create, out status);


CommonDataProvider.cs

An instance of the user-specified data provider class. This class must inherit the CommonDataProvider interface.

public abstract class CommonDataProvider {
public static readonly string CommonDataProviderName = "CommonDataProvider";

private static CommonDataProvider _defaultInstance = null;

static CommonDataProvider()
{
CreateDefaultCommonProvider();
}

/// <summary>
/// Returns an instance of the user-specified data provider class.
/// </summary>
/// <returns>An instance of the user-specified data provider class. This class must inherit the
/// CommonDataProvider interface.</returns>
public static CommonDataProvider Instance() {
return _defaultInstance;
}

public static CommonDataProvider Instance (Provider dataProvider)
{
CommonDataProvider fdp = CSCache.Get(dataProvider.Name) as CommonDataProvider;
if(fdp == null)
{
fdp = DataProviders.Invoke(dataProvider) as CommonDataProvider;
CSCache.Max(dataProvider.Name,fdp);
}
return fdp;
}


If you need more information or code, please let me know. This has been bugging me for a few days, I think I'm thinking too much into it and I can't see what's actually going on here.

Thanks for any help!

Edit: I did notice that system.reflection is being use at the top of the file. I'm not sure if that has anything to do with it. I thought that it had to do with creating an object from an assembly, but I don't see them using any assembly in here, they are just calling another class. I'm going to read chapter on reflection and see if it answers my questions. I'm not sure if I'm on the right track or not.