|
Hi,
Is there a way to produce a partial method with CodeDom?
Ex. partial void MyMethod() { ... }
It looks like the MemberAttributes doesn't have "Partial" in it
CodeMemberMethod codeMemberMethod = new CodeMemberMethod();
codeMemberMethod.Attributes = MemberAttributes.Public...but no MemberAttributes.Partial?
My problem is that I'm generating some code to implement partial method.
I have this class (created "by hand"):
public partial class MyClass
{
partial void MyMethod();
partial void MyMethodB();
}
Then with CodeDom, I want to generate the implementation of those partial method. Something like:
public partial class MyClass
{
partial void MyMethod()
{
}
partial void MyMethodB()
{
}
}
That's why I need the "Partial" in System.CodeDom.MemberAttributes.
May be I'm all wrong...it's something else the MemberAttributes that I should use to do this?
Thank
|
|
|
|
|
Create an abstract class and then use CodeDom to return an instance. You don't even need an abstract class as you can use an interface as well.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Sorry, but the CodeDOM classes don't support partial methods.
|
|
|
|
|
|
I created 3000 labels and added them into my form (I really didn't need these labels, I was just testing).
My C# code:
int x, y;
Label[] lab = new Label[3000];
for (int i = 0; i < 3000; i++)
{
lab[i] = new Label();
x = i / 100;
y = i % 100;
lab[i].Tag = string.Format("{0},{1}", x.ToString(), y.ToString());
lab[i].AutoSize = false;
lab[i].Top = (x - 1) * 10;
lab[i].Left = (y - 1) * 10;
lab[i].Height = 10;
lab[i].Width = 10;
this.Controls.Add(lab[i]);
}
My VB6.0 code:
Dim i%
Dim x$
Dim y$
For i% = 2 To 3000
Load lblPage(t%)
x$ = i% \ 100 + 1
y$ = i% Mod 100
lblPage(i%).Tag = x$ + "," + y$
lblPage(i%).Top = (i% \ 100) * lblPage(1).Height
lblPage(i%).Left = (i% Mod 100 - 1) * lblPage(1).Width
lblPage(i%).Visible = True
Next i%
And my problem is speed!
C#: about 5seconds
VB6: less than a second!!!
Why?
Besides I have to insert approximately 100MB .Net Framework package in my installation package while I really don't need all of .Net Framework features, in this case I have to tell my users: "Please be patient! We'll continue after a while! "
Is there anyway to solve these problems? If not I think I'll not use C# anymore!
|
|
|
|
|
Pedram Behroozi wrote: And my problem is speed!
Then use C++...
Stupidity is an International Association - Enrique Jardiel Poncela
Die deutsche Sprache sollte sanft und ehrfurchtsvoll zu den toten Sprachen abgelegt werden, denn nur die Toten haben die Zeit, diese Sprache zu lernen. - Mark Twain
|
|
|
|
|
You're creating 3000 labels and adding them to the screen. Of course that's gonna be slow; that's a horrible abuse of the UI system. (As many VB6 apps are!)
Your VB6 code is different than your C# code. The C# code creates 3000 labels and adds them to the screen. Your VB6 code assumes your labels are already created and merely sets their visible status.
Tell us what you're trying to do. We'll tell you how to get good performance.
Pedram Behroozi wrote: Besides I have to insert approximately 100MB .Net Framework
Use the .NET 3.5 SP1 client profile. It's just over 20MB.
Another thing to consider is that all Windows Vista machines come pre-installed with .NET 3.
modified on Friday, September 26, 2008 1:50 PM
|
|
|
|
|
Judah Himango wrote: Tell us what you're trying to do. We'll tell you how to get good performance.
As I said before, I was just testing. I encountered the speed problem before in many cases. Like reading records from a file using StreamReader or even BinaryReader while the same VB6 application executed that in a moment!
Judah Himango wrote: Use the .NET 3.5 SP1 client profile. It's just over 20MB.
Even 20MB is a huge size! Imagine I want to write a simple Phonebook, My application needs 20.01MB free space!
|
|
|
|
|
The problem is that you're writing VB code in C#. Write C# code meant to run on the .NET framework, .NET performance will blow VB6 out of the water.
Pedram Behroozi wrote: Even 20MB is a huge size!
No it's not. Standard hard drive these days are 500 GB. That means the .NET framwork is 1/25,000th the size of the hard drive.
If you don't want to use the whole .NET framework, use Silverlight. It's a 4 MB subset of the .NET framework.
modified on Friday, September 26, 2008 2:30 PM
|
|
|
|
|
Pedram Behroozi wrote: Even 20MB is a huge size!
Do you realize this is the year 2008 and 20mb is a splash in the bucket these days? Maybe in 1991 with an 80MB hard drive it would be a whole different story
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Few issues to point out:
- you are comparing two totally different languages and environments. What is optimal in VB6 may not be optimal in C# and vice versa
- your code is not equal. You have several major differences in your code
- predefined labels in VB6
- in C# you access properties which you do not use in VB6
- you modify control collection in C# and so on
- the output is different in .Net (MSIL) than in VB6 (native EXE)
- you may have not optimized code and you may have DEBUG & TRACE options on in C# etc.
However, in real world situation, in most cases .Net beats VB6 in all areas, since you have more possibilities to achieve the same goal but in a more efficient way.
I'm all the time referring to .Net instead of C#, because C# is just one of the languages you can use in .Net. If you make the same test using VB.NET, you'll have similar results. However C# gives you the opportunity to use more efficient coding than VB.NET so it would be more reasonable choice for the language.
If performance still is an issue with MSIL code, you can always use ngen at target machine.
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Mika Wendelius wrote: If performance still is an issue with MSIL code,
Definitely yes, I wrote a program that should read 5000 records from a file. I tried C# to add these records to a DataGridView control (I even tried simple ListBox) and to be honest with you C# done it in 20 seconds. But my uncle wrote this application via VB6 and japed me!
I actually preferred C#, but I need high speed and low size.
Mika Wendelius wrote: you can always use ngen at target machine.
What is "ngen at target machine"?
|
|
|
|
|
For the first comment: You must play by the rules of C#. If done properly, it beats VB6, that's for sure, but the code is not the same or even transferrable.
For the second comment: Native Image Generator (Ngen.exe)[^]
Mika
P.s. Have faith and work your way with C# and you'll show your uncle
The need to optimize rises from a bad design
|
|
|
|
|
Use AddRange.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Move this line outside the loop
this.Controls.Add(lab[i]); and change it to
this.Controls.AddRange(lab);
|
|
|
|
|
They give the same result
|
|
|
|
|
The two pieces of code don't even do the same thing.
Why would you want to even create 3,000 labels for your form. I'd hate to see the UI with something like that.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Just for testing!
What about using StreamReader, BinaryReader, DataGridView, ListBox?
These classes and objects are common but these are not as fast as I need.
|
|
|
|
|
The .NET framework has put more funcionality into the Label object, so there is more overhead.
If all that you are going to do is to put ridiculous amounts of controls in the form, you can stick with VB6.
If you want to do something else, you can have very much use for it. For example, creating an instance of a class is considerably faster in C# compared to VB6.
You should also consider that VB6 is a dead language. There is no further development, and Microsoft doesn't support it any longer.
Pedram Behroozi wrote: Besides I have to insert approximately 100MB .Net Framework package in my installation package while I really don't need all of .Net Framework features
Where did you get hold of a 100 MB framework package? The .Net Framework 2.0 package is 22 MB.
Besides, you are comparing apples and oranges. There is a runtime library required for running VB6 programs also, the only difference is that VB6 is so old that the RTL has been included with every version of Windows for many years, just like the .NET framework 2 is included in Vista.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi there Pedram
Pedram Behroozi wrote: And my problem is speed!
Well, I think you have to use just C++
Pedram Behroozi wrote: C#: about 5seconds
VB6: less than a second!!!
I thought C# is faster
Pedram Behroozi wrote: Besides I have to insert approximately 100MB .Net Framework package in my installation package while I really don't need all of
You're right. It's very bad , because if we want to run our programs on the other systems , we have to install .Net framework
|
|
|
|
|
And if you want to run C++ applications, you have to install the C++ runtime. Hey, even VB has a runtime.
|
|
|
|
|
|
VB6 runtime is about 1.31 MB
|
|
|
|
|
But when I was working C++, I wasn't installing anything for running it on the destination system.
|
|
|
|
|
That's because, in a lot of cases, the runtime will already have been installed. Take a look at the msvcrt - that's the Microsoft Visual C++ RunTime. It's the same with .NET - over time, more and more systems will have .NET installed on them by default.
|
|
|
|