Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where does Metadata come from?

Status
Not open for further replies.

glyns

Programmer
Dec 15, 2008
125
GB
I've been given a c# project to look after while the guy is on honeymoon for a month so I can't ask him this :-(. In the project in the App_Code folder is a file called helper.cs. In it are lines like this
MembershipUser user = Membership.GetUser(Username)

When I go to definition on Membership (or MembershipUser)
it takes me to a file called "Membership [from metadata]"

I think I've got the gist of what metadata is, but how is the contents of the metadata file created? For example GetUser has a number of alternatives
Code:
public static MembershipUser GetUser();
public static MembershipUser GetUser(bool userIsOnline);
public static MembershipUser GetUser(string username);
Say I want to add another one,
Code:
public static MembershipUser GetUser(string username, string password);
where/how would I do this? With what would I have to interact?

Thanks
 

the members above are part of a class. Which class, I cannot say from the snippets provided. My guess is the Membership Provider class, but that's just a guess.

The method GetUser has 3 overloads and returns the object MembershipUser.

to add another overload you would need to navigate to the class, add the new member, compile, test, deploy. The object may not be available for editing (.net assembly, 3rd party assembly, etc.) in that case there are some OOP techniques like the proxy, adapter and decorator patterns which may help.

reviewing the code above, why would you need GetUser(string username, string password) when you already have GetUser(string username)?

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
They're members are part of the class Membership
The text of this class is held at the following location
c:\users\me\appdata\Local\Temp\3152$System.Web.dll$v2.0.50727\System.Web.Security.MembershipUser.cs

Trimmed down as it's huge it looks a bit like this
Code:
using System;
namespace System.Web.Security
{
  public static class Membership {
public static MembershipUser GetUser();
public static MembershipUser GetUser(bool userIsOnline);
public static MembershipUser GetUser(string username);
There are another half dozen "GetUser"s and a load of other options but I just showed those 3 for simplicity

Adding "GetUser(string username, string password)" was an example of something to add, "GetUser(string

UserID)" works just as well.

I've grepped the entire project and the only time the word "Membership" exists is in the aforementioned

helper.cs at the lines
Code:
MembershipUser user = Membership.GetUser(Username);
and
Code:
sec.Logon = Membership.ValidateUser(user.UserName, Password);
and the project solution file with a reference pointing to
c:\users\me\appdata\Local\Temp\3152$System.Web.dll$v2.0.50727\System.Web.Security.MembershipUser.cs

I can't find where to navigate to, to add the line
Code:
public static MembershipUser GetUser(string UserID);
let alone do any of the rest of it
 
And strangely I *did* google this first for quite a while, that's why I said "I think I've got the gist of what metadata is"

I couldn't find the answer to the question or make any headway to answering it via google, that's why I asked it here.

The link you helpfully provided was the first thing I went looking for and does in fact answer none of the questions I have.

Thanks for trying though
 
strangely I *did* google this first for quite a while, that's why I said "I think I've got the gist of what metadata is"
it's important to be explicit on forums of what you have already done. how are we to interepret *gist* for *google*. the same would be true of code samples.

as for MembershipUser. this is a class in an external library. There is no way for you to directly access the source and modify it. However, your question scratches the surface of a much broader concept though: OOP patterns. Patterns will open the door for design principles. The most common set of design principles is S.O.L.I.D. From there a whole world of OOP like you never imagined.

Some resources that helped me along the way.
Head First: Design Patterns (book) great introduction to OOP patterns.
Nothin' But .Net (training by J.P. Boodhoo, simply amazing)
& are blog aggregaters. Most of posts are about .net development. There is all kinds of information on SOLID, unit testing, TDD, BDD, OSS framework.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Hi glyns,

When you're looking at some code in an open project in visual studio and you right-click and go to the definition of an object, you will be taken to where that object is defined. If the object has been defined in a project that is not one of your open projects then visual studio will attempt to show you as much info on the object as it can, from the metadata.

I think what you need to do is find the project that the objects you're interested in belong to, and open them. Then add to the code as you like.

To overload a method in C# you simply add a new method with the same name. I think in VB you need to specify that it overloads another method.

Example:
Code:
private void MyMethod(string s, int i)
{
    // do something
}

private void MyMethod(int i)
{
    // do something

    // often here you would call MyMethod above passing a default 
    // value for s, and in the above MyMethod you would handle the 
    // default value appropriately.
    MyMehod([some default value], i);
}


Like Jason said though, for this to show correctly in your project that references it you would have to recompile it after you've finished coding, and update your references in the project that references it.

Hope that helps.
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top