Click here to Skip to main content
15,896,475 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# COM Interop Pin
Eddy Vluggen1-Jun-11 0:57
professionalEddy Vluggen1-Jun-11 0:57 
AnswerRe: C# COM Interop Pin
DaveyM691-Jun-11 0:59
professionalDaveyM691-Jun-11 0:59 
QuestionBitmap.SelectActiveFrame Pin
H@is@here31-May-11 12:53
H@is@here31-May-11 12:53 
QuestionLoad image that really are 2 images into imagelist Pin
manchukuo31-May-11 9:20
manchukuo31-May-11 9:20 
AnswerRe: Load image that really are 2 images into imagelist Pin
Mark Salsbery31-May-11 11:19
Mark Salsbery31-May-11 11:19 
GeneralRe: Load image that really are 2 images into imagelist Pin
manchukuo31-May-11 11:28
manchukuo31-May-11 11:28 
Questionhow to put imagens randomly? Pin
Rapsten31-May-11 5:56
Rapsten31-May-11 5:56 
AnswerRe: how to put imagens randomly? Pin
RobCroll31-May-11 13:15
RobCroll31-May-11 13:15 
QuestionRectanlgeF.Parse(string s) extension method? Pin
Chesnokov Yuriy31-May-11 1:58
professionalChesnokov Yuriy31-May-11 1:58 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Not Active31-May-11 2:03
mentorNot Active31-May-11 2:03 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Chesnokov Yuriy31-May-11 2:22
professionalChesnokov Yuriy31-May-11 2:22 
AnswerRe: RectanlgeF.Parse(string s) extension method? [modified] Pin
musefan31-May-11 2:26
musefan31-May-11 2:26 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
Pete O'Hanlon31-May-11 2:33
mvePete O'Hanlon31-May-11 2:33 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
musefan31-May-11 2:42
musefan31-May-11 2:42 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 2:42
sitebuilderLuc Pattyn31-May-11 2:42 
yes and no.

Extension methods, while requiring a static keyword, are really instance methods; now Parse and TryParse are basically static methods, they operate on a string and return a specific type, they don't operate on that type (the MSDN example is string.WordCount which operates on an existing string and returns an int).

So you could have this definition (note the first argument isn't used at all):
public static class MoreTryParse {
	public static bool TryParse(this RectangleF dummy, string s, out RectangleF rect) {
		float x=0;
		float y=0;
		float w=0;
		float h=0;
		if (s.StartsWith("(") && s.EndsWith(")")) s=s.Substring(1, s.Length-2);
		string[] sa=s.Split(',');
		if (sa.Length==4 && float.TryParse(sa[0], out x) && float.TryParse(sa[1], out y) &&
			float.TryParse(sa[2], out w)&& float.TryParse(sa[3], out h)) {
			rect=new RectangleF(x, y, w, h);
			return true;
		} else {
			rect=new RectangleF(0, 0, 0, 0);
			return false;
		}
	}
}


but then you would have to call it like this:
public void test(string s) {
	RectangleF rect=new RectangleF();
	bool result=rect.TryParse(s, out r1);
	log(s+"  result="+result+"  rect="+rect.ToString());
}

which is a bit silly, as you have to create a dummy RectangleF in order to get the actual one.

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Please use <PRE> tags for code snippets, they improve readability.
CP Vanity has been updated to V2.3

AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Chesnokov Yuriy31-May-11 2:47
professionalChesnokov Yuriy31-May-11 2:47 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 2:55
sitebuilderLuc Pattyn31-May-11 2:55 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
BobJanova31-May-11 3:04
BobJanova31-May-11 3:04 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 4:00
sitebuilderLuc Pattyn31-May-11 4:00 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
BobJanova31-May-11 23:09
BobJanova31-May-11 23:09 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn1-Jun-11 0:17
sitebuilderLuc Pattyn1-Jun-11 0:17 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Shameel31-May-11 3:05
professionalShameel31-May-11 3:05 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
Pete O'Hanlon31-May-11 3:39
mvePete O'Hanlon31-May-11 3:39 
QuestionClicking a button with SendMessage [modified] Pin
musefan30-May-11 23:36
musefan30-May-11 23:36 
AnswerRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:15
professionalShameel31-May-11 0:15 

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.