Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
QuestionC# windows forms With MS SQL DataBase Pin
Zeyad Jalil6-Sep-16 23:56
professionalZeyad Jalil6-Sep-16 23:56 
AnswerRe: C# windows forms With MS SQL DataBase Pin
Garth J Lancaster7-Sep-16 0:14
professionalGarth J Lancaster7-Sep-16 0:14 
GeneralRe: C# windows forms With MS SQL DataBase Pin
Zeyad Jalil7-Sep-16 0:17
professionalZeyad Jalil7-Sep-16 0:17 
AnswerRe: C# windows forms With MS SQL DataBase Pin
OriginalGriff7-Sep-16 0:46
mveOriginalGriff7-Sep-16 0:46 
AnswerRe: C# windows forms With MS SQL DataBase Pin
Pete O'Hanlon7-Sep-16 1:16
mvePete O'Hanlon7-Sep-16 1:16 
QuestionCreate a static class to return properties Pin
Mycroft Holmes6-Sep-16 22:02
professionalMycroft Holmes6-Sep-16 22:02 
AnswerRe: Create a static class to return properties Pin
#realJSOP7-Sep-16 1:19
mve#realJSOP7-Sep-16 1:19 
AnswerRe: Create a static class to return properties Pin
Pete O'Hanlon7-Sep-16 2:10
mvePete O'Hanlon7-Sep-16 2:10 
As you are realising, you need to have a Class/Method combination to achieve what you want. Saying that, you can achieve a slightly similar syntax using any of the following techniques. First of all, let's assume that you have these elements to do the parsing:
C#
public static class BuParser
{
  public static  BuEntity ParseElement(string value)
  {
    string[] breakdown = value.Split('_');

    return new BuEntity()
    {
      Rolename = breakdown[0],
      Entity = breakdown[1],
      BusinessUnit = breakdown[2]
    };
  }
}
public class BuEntity
{
  public string Rolename;
  public string Entity;
  public string BusinessUnit;
}
Okay, given these classes, the first technique is to use extension methods. Something like this:
C#
public static class Parser
{
  public static BuEntity Parse(this object o, string role)
  {
    return BuParser.ParseElement(role);
  }

  public static BuEntity Parse(this string role)
  {
    return BuParser.ParseElement(role);
  }
}
Calling these would look like this:
C#
string roleName = this.Parse("Developer_Admin_CodeProject").Rolename;
string businessUnit = "Developer_Admin_CodeProject".Parse().BusinessUnit;
Now, there is another technique you could use - I would recommend not using it because it subverts syntax, but you could have
C#
public class Parser2
{
  public BuEntity this[string role]
  {
    get { return BuParser.ParseElement(role); }
  }
}
Calling that would look something like this:
C#
string entity = new Parser2()["Developer_Admin_CodeProject"].Entity;

This space for rent

GeneralRe: Create a static class to return properties Pin
Mycroft Holmes7-Sep-16 2:48
professionalMycroft Holmes7-Sep-16 2:48 
AnswerRe: Create a static class to return properties Pin
Richard Deeming7-Sep-16 2:17
mveRichard Deeming7-Sep-16 2:17 
GeneralRe: Create a static class to return properties Pin
BillWoodruff7-Sep-16 5:08
professionalBillWoodruff7-Sep-16 5:08 
GeneralRe: Create a static class to return properties Pin
Richard Deeming7-Sep-16 6:59
mveRichard Deeming7-Sep-16 6:59 
Questionhow to add localdb in console apps using vs2013 Pin
Tridip Bhattacharjee5-Sep-16 23:18
professionalTridip Bhattacharjee5-Sep-16 23:18 
AnswerRe: how to add localdb in console apps using vs2013 Pin
OriginalGriff5-Sep-16 23:31
mveOriginalGriff5-Sep-16 23:31 
AnswerRe: how to add localdb in console apps using vs2013 Pin
ZurdoDev6-Sep-16 4:12
professionalZurdoDev6-Sep-16 4:12 
GeneralRe: how to add localdb in console apps using vs2013 Pin
Eddy Vluggen6-Sep-16 5:20
professionalEddy Vluggen6-Sep-16 5:20 
GeneralRe: how to add localdb in console apps using vs2013 Pin
ZurdoDev6-Sep-16 5:53
professionalZurdoDev6-Sep-16 5:53 
Questionreceive values from a listbox Pin
eli stein2005-Sep-16 6:05
eli stein2005-Sep-16 6:05 
AnswerRe: receive values from a listbox Pin
Dave Kreskowiak5-Sep-16 6:50
mveDave Kreskowiak5-Sep-16 6:50 
GeneralRe: receive values from a listbox Pin
eli stein2005-Sep-16 7:25
eli stein2005-Sep-16 7:25 
AnswerRe: receive values from a listbox Pin
Maciej Los5-Sep-16 19:41
mveMaciej Los5-Sep-16 19:41 
SuggestionRe: receive values from a listbox Pin
Richard Deeming6-Sep-16 1:58
mveRichard Deeming6-Sep-16 1:58 
GeneralRe: receive values from a listbox Pin
Maciej Los6-Sep-16 3:36
mveMaciej Los6-Sep-16 3:36 
QuestionC# Pin
Member 123725154-Sep-16 8:25
Member 123725154-Sep-16 8:25 
AnswerRe: C# Pin
Pete O'Hanlon4-Sep-16 10:09
mvePete O'Hanlon4-Sep-16 10:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.