|
Guys,
I have implementing small academic project can any one let me know some of the Free SMS API's. so that i can use them in my project... please i am trying to do some thing realistic and its a big challenge for me... Thanks in Advance..
|
|
|
|
|
|
HI all,
How can i clear IE history with c#
Thanks
Rakesh
|
|
|
|
|
Don't repeat. You have already asked this in the Q&A section
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Repost: Already asked in Q&A.
Don't post in multiple places, all that happens is you annoy people, duplicate effort, and waste time.
It can reduce your chances of getting an answer...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Ok, so here is the problem. I got native dll which contains and utilizes my own class for building dynamic string arrays. Here is a simple example how it works in C(++):
wchar_t **GetArray()
{
ArrayBuilder *arrb = new ArrayBuilder();
arrb->Append(L"test1");
arrb->Append(L"test2");
arrb->Append(L"test3");
return arrb->GetArray();
}
wchar_t **myarray = GetArray();
wprintf(L"Element1: %s, element2: %s and element3: %s\r\n", myarray[0], myarray[1], myarray[2]);
Assuming that i am exporting this small test function "GetArray" from dll:
extern "C" { __declspec(dllexport)wchar_t **GetArray() }
How can i get this string array in my C# app? I have tried something like:
[DllImport("db.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern List<String> GetArray();
or
public static extern String[] GetArray();
or
public static extern Array GetArray();
Nothing works. It throws that it "cannot marshal return value: Generic types cannot be marshaled", or, in case of last approach, some HRESULT error. So in fact i have missed something, but what? What is the right way to call this function in C# app?
Thanks
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Alright, i got it.
[DllImport("db.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr GetArray();
IntPtr test = dbFunc.GetArray();
StringBuilder zzz = new StringBuilder();
int i = 0;
for (; ; )
{
IntPtr p = new IntPtr(test.ToInt32() + Marshal.SizeOf(typeof(IntPtr)) * i++);
IntPtr stuff = Marshal.ReadIntPtr(p);
if (stuff == IntPtr.Zero) break;
string s1 = Marshal.PtrToStringAuto(stuff);
zzz.Append(s1 + ",");
}
MessageBox.Show(zzz.Remove(zzz.Length - 1, 1).ToString());
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
What should I use as a rule of thumb for being able to tell when it's time to break a large class into two?
I know that a class should have only one responsibility, but sometimes it's hard to tell.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
That's the question of the ages! I don't really have a good answer for you. One criteria is if the methods / fields / properties seem unrelated then group the related ones into separate classes.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Thanks. Does that imply that if they are closely related, then it doesn't matter how big the class gets?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
not necessarily, you just need to use a more refined meaning of "closely related"
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Different developers will have different ideas so like most things I do, just make sure you have a good argument to do it so when other members question why you did it, you have an answer.
For me, I start looking at redesigning a class when its over 10,000 - 15,000 lines.
Architecture is extensible, code is minimal.
|
|
|
|
|
If I was in your place, I would consider this:
1. Can the methods and properties be re-grouped into smaller batches and they will still work independently.
2. If they cannot, can I see signs of possible parent child relationship? If yes: inheritance.
3. How the class used in the application?
If all you are concerned about is the size of class file, then partial class comes to rescue. Or else you can use regions and expand only the one you are concerned with.
|
|
|
|
|
i like partial classes. I hate regions.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Some classes are just going to be big, that's how it is sometimes. However, when we think about a 'rule' or a 'law' (in litigation or in engineering), we don't follow the rule blindly - we think "what is the law there to protect? What's its purpose?".
So, one of the golden rules "don't write mammoth classes" comes down to understandability, flexibility and separation of concerns (there are possibly more interpretations). That being the case, if your class is readable, fairly flexible and has a clear single purpose, then you've satisfied the underlying reasons for the rule - even if the class happens to have 2000 methods.
If you really think it's not achieving this, maybe only in terms of readability, then you could use partial classes[^]; you could restructure the class internally, maybe to use some encapsulated classes (you can't mention refactoring without mentioning Martin Fowler[^]); you could come to terms with the size Really, it's up to you if it's working or not.
Last but not least, I think the greatest invention in C#-land was the #region directive[^] - in a huge class, this is invaluable!!
EDIT: d@nish already beat me to partials and regions! damn... I thought I was so original
|
|
|
|
|
I agree with all that you say, but I have to say I hate regions. Partial classes are better. Just my opinion, personal preference...
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Interesting though, is it just an inexplicable idiosyncrasy or do you have an explicit reason? It's just I've never known people to use partial classes except in conjunction with code generators.
EDIT: Modified to question as according to Manfred partial classes are not a joke
modified on Thursday, January 27, 2011 6:58 PM
|
|
|
|
|
I'm not quite sure why you marked your reply as a joke. If I'd see anybody on my team distribute a class into partials because it "got to big" I would not be "amused" to say the least.
|
|
|
|
|
It was marked as a joke because initially I was just going to post a crying face, joking that I was deeply offended by Ahmed's pure hatred for regions. Then I was curious, as I've never seen, nor thought to, separate a class into partials (except when using code generation, obviously).
Interesting, why are you so against partials?
|
|
|
|
|
I'm not per se against partials, but I do think the splitting of big classes into smaller pieces is an abuse of this otherwise great feature if the only intend is to get smaller code chunks.
In my opinion good/acceptable uses:
- Separation of generated and hand written code
- Separating the implementation of interfaces from "regular" class code especially when there are many interfaces to implement
- Splitting the implementation of a "big" class for disconnected teams (no access to a common source repository)
- Separate static stuff from instance stuff
Let me know your take on the usage scenarios.
Cheers!
|
|
|
|
|
Normally it would only be the first point you mentioned for working with code generation, but I like the idea of seperating out interface implementations! That's cool! Am I getting you right, so eg. An IList<t>, IEnumerable<t> (contrived):
Filename: MyList.IList.cs
public partial class MyList : IList<string> { ... }
Filename: MyList.IEnumerable.cs
public partial class MyList : IEnumerable<string> { ... }
Is this kind of what you mean (naming convention notwithstanding)?
Also, I think I may even adopt using partials for separating static and instance code. I normally use regions for that, but it still annoys me when I confuse them... Very interesting insight! Thank you, I'm glad I asked you that question
|
|
|
|
|
You got what I was trying to say even though I'm not sure if you can write it that way. My take on this would be that you would have to mention all the implemented interfaces in every partial class definition, but to be really sure I would need to try your take on this in a real example.
|
|
|
|
|
Because regions are horribly abused and the break the natural collapsing of methods that the IDE does, making it harder to read code.
Because people abuse regions to "break-up" a very large functions into smaller pieces. If it needs a f***ing region, then put that section of code into another method! and if there are so many methods that you need to region-ize them, then put them into a separate file (partial class)!
aaaaaggghh!
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
So it's really about how you've seen them used? Ok, well I hardly ever use a region inside a method, I think that's a bit crazy. There is one exception to this - when there is horrific yet necessary code, I may "region it out" of a method saying "Ugly Code - DO NOT TOUCH" or something similar I think I've only committed this atrocity once...
I generally use regions to separate parts of the class, eg.
public class SomeClass : IUpdateable, IDrawable
{
#region Private fields
#region Constructor
#region Properties
#region Methods
#region Static methods
#region Event production
#region Event consumption
#region IUpdateable implementation
#region IDrawable implementation
}
It's usually pretty free-form my region-ising and its naming convention, but I tend to have the four: Private fields, Constructor, Properties and Methods in every class. For me it makes it easier when I go back to it to edit, for example, a method - I don't want to scroll or whatever, I just want to see the methods.
|
|
|
|
|
I've regioned some error-handling in some methods, but it's not a habit.
|
|
|
|