|
|
A good answer. It helps me to resolve my question.
|
|
|
|
|
Does any one know how much storage space a Type object requires? For example, an instance of a Type contains a multitude of properties. Are these properties stored in memory or retrieved when needed?
Also, does anyone know how fast the "is" function is evaluated? I've been using the "is" function a lot more frequently and I don't want to inadvertently be slowing down my code.
Example:
if (variable is ISomeInterface1)
{}
else if (variable is ISomeInterface2)
{}
else if (variable is ISomeInterface3)
{}
...
If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.
|
|
|
|
|
AFAIK there is no "Type" object - instead every object has a type, which defines what properties and methods the object has. As such, a "Type object" has no specific size - it depends on what kind of object it is!
As for the "how fast is "is ", why would it matter - how would your code work if you didn't check what type you are receiving, unless it is a single type of object? I.e. if your code is similar to a click event
void ClickIt(object sender, EventArgs e) then you have to use either
if (sender is MyClass)... or
MyClass mine = sender as MyClass in order to use the parameter.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I assume he means if you do System.Type t = o.GetType() ; , how much space will be used.
Thinking of it that way... do you just get a reference to the class in the loaded assembly?
|
|
|
|
|
Dunno - but this is making my brain hurt! (I had forgotten about the System.Type class; I try to avoid using reflection if I can.)
What is he doing that makes the size of a Type important, I wonder?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
OriginalGriff wrote: What is he doing
Waiting for Friday?
|
|
|
|
|
Hi,
There is a Type class, with a constructor. And object.GetType() returns a Type instance. So there are type objects, and they all must have the same size; not sure how to get its value, I expect it to be small. Furthermore an experiment shows the type objects are unique, i.e. there is at most one for each class.
FWIW: one should use the is/as keywords to perform type tests, and most certainly not compare Type.ToString() with some string literal.
is and as translate to a simple IL instruction, and are assumed to be very fast.
PS: if you frequently need dispatching based on type, as in your example, how about using a virtual method/property?
|
|
|
|
|
Luc Pattyn wrote: how about using a virtual method/property?
Due to lack of covariance and contravariance? I think I was just butting my head up against that... again.
|
|
|
|
|
Hey Luc!
Your answer seems to be the most intelligent of the three responses. (Sorry guys)
I have a fairly advanced knowledge of the .Net Framework but there are certain things that Microsoft doesn't explain clearly. For a general developer, I'm sure most of this is unnecessary.
Luc Pattyn wrote: PS: if you frequently need dispatching based on type, as in your example, how about using a virtual method/property?
Cool idea, but I don't think it's my best option for this app.
Cheers!
Richard
If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.
|
|
|
|
|
Hi Richard,
Richard Blythe wrote: there are certain things that Microsoft doesn't explain clearly
you know, you might be right about that
|
|
|
|
|
Lol, thanks again for the response.
If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.
|
|
|
|
|
You're welcome.
|
|
|
|
|
Richard Blythe wrote: how much storage space a Type object requires
Assume the worst. If you use Reflection to get such information, it's best to cache what you need.
Richard Blythe wrote: how fast the "is" function is evaluated
You could do a bunch of them and time them.
If you do a lot of that you might be interested in my TypeTransmogrifier[^].
modified on Tuesday, March 30, 2010 3:10 PM
|
|
|
|
|
Hi..
I want to create a line, polygon shapefile.. Pls can someone help...
|
|
|
|
|
Draw a line from A to B.
Draw another line from B to C.
.. repeat ad nauseam to X ...
Draw a line from X to A.
Voila! A polygon.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
U didnt get me actually.
I am using map control. I got this control from the mapwinGIS.
On the mapcontrol i create vector and raster layers...
Vector layer is basically opening shapefiles.
Now i need to create point shapefile, line shapefile.
|
|
|
|
|
I think this site[^] will have the best information.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Hello everybody,
I am using map control to add shapefiles in my project.
I want to add image to the map control and also drag and resize it.
Pls can someone help me...
I am able to place the image on the map control. But not able to drag and resize.
|
|
|
|
|
How are you placing the image? Are you drawing it yourself, or using a PictureBox? How you drag and re-size will be affected.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I'll have an image file say bitmap file. And am adding it as a lyer on the mapcontrol.. Now i need to edit it or like drag/move it from one position to another and resize it.
Am not using picturebox. Am using mapcontrol. and display my image on that mapcontrol only. u get the map control from mapwindowgis
|
|
|
|
|
How can I get the position of a certain cell of a datagridview. To be specific I don't want the mouse coordinates. Suppose I have a datagridview with Name (ReadOnly), ID and TransDate columns and I want to popup a tiny lookup form when the mouse is clicked or Enter button is pressed when the focus is upon the Name column. The lookup form should openup exactly upon the Name column of the selected row. Thanks.
|
|
|
|
|
You can use CellBeginEdit event for this. Check the current column index and if it is name, show the look up form. You can set the location for the form according to the current cell.
BTW, what EditMode have you set for the DataGridView?
|
|
|
|
|
Here's a solution I came up to.
I am opening a dialog form above the datagridview form. In Form1 I have a datagridview containing few columns among which is 'TransDate' column having index 8. When I click on it, frmDate opens up exactly on it. My revised code follows:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridview1.CellClick
If DataGridview1.CurrentCell.OwningColumn.Name = "TransDate" Then
Dim objPoint As Point
'Getting the exact location of the cell with respect to Form1.
'Note- Me.Location is added here alongwith DataGridView1.Location and
'DataGridView1.GetDisplayRectangle().Location.
'This is done because the form frmDate we are calling is external to Form1 and if we don't add
'Me.Location
'here, frmDate won't open exactly at the desired point if we move or resize Form1. Instead of
'frmDate if we use any control inside Form1 to place over 'TransDate' column then remove
'Me.Location here and the next two lines.
objPoint = (Me.Location + DataGridview1.Location + DataGridview1.GetCellDisplayRectangle(8,
DataGridview1.CurrentCellAddress.Y, True).Location)
'Setting the exact location where frmDate will be opened. The last digits may vary according to
'your requirement.
objPoint.X = objPoint.X - 158
objPoint.Y = objPoint.Y + 28
objFrmDate = New frmDate()
objFrmDate.Location = objPoint
objFrmDate.ShowDialog(Me)
objFrmDate = Nothing
End If
End Sub
Regards.
|
|
|
|
|
Hi,
How about enhance it, and make it general to benefit from it more, like this.
this code is in C#.
-------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace MyNamespace
{
public class ControlUtilityClass
{
public static Rectangle Get_DataGridCellLocationAndSize(DataGridViewCell cell)
{
Rectangle result;
Rectangle rec = cell.DataGridView.GetCellDisplayRectangle(cell.ColumnIndex,
cell.RowIndex, false);
Rectangle rec1 = cell.DataGridView.RectangleToScreen(rec);
result = cell.DataGridView.FindForm().RectangleToClient(rec1);
return result;
}
}
}
modified on Wednesday, June 30, 2010 2:09 AM
|
|
|
|