|
It is code analysis that tells to return collections in stead of List. You can make use of a global suppression file in your code to get rid of it.
For dictionary, it would be suggesting a read only collection. Suppress that too if you do not want another object to be returned.
It is up to you to decide till when you are going to follow MS code analysis. I personally follow everything it tells.
|
|
|
|
|
Regarding Geneneric list as return type :
If you send/return the generic list outside, your collection can be very easily changed
from outside of your class without your permission and you lose total control on the same.
that is why , one should not expose or return generic list and use ReadOnlyCollection instead.
Dot net does not force you to do so but generally its not good programming practice!
Regarding point 2 :
Here also, A ReadOnlyCollection is recommanded.
Regarding point 3 :
You can create your customDictionary in which you can maintain and return the colelction of keys and/or
collection of values as per request.
|
|
|
|
|
Hi,
I have a web app that talks to a web service using binary remoting. I've been asked to change the solution so that the objects are transported in XML format to allow the data to be audited more easily and to prevent firewall problems.
I have read this article .NET Remoting with an easy example[^] which is great but I'm not clear on how to change my current binary implementation which use TcpClientChannels to a XML Marshal by Value solution.
Is this simple? If so, I would appreciate a work example if possible. Also is it going to provide the customer with what they want? How would you trace the XML objects while the application is running
Many Thanks for your time,
Andy
|
|
|
|
|
Hi,
You should be using an IChannel, rendering the channel type meaningless (use the HttpChannel instead of a TcpChannel).
Note!
The xml serializer is different than the binary one and it blindly places values for all public members and properties.
One more thing that may be causing you problems is that there are no back channel tricks like in tcp for passing events or data back to the client.
I am the developer of a bingo card software named The Bingo Maker
I have been developing in .NET since 2003
|
|
|
|
|
I started with a generic class which has a delegate. The consumer of this class could set a method callback which requires invoking but they may not also. To address this I check if the callback is ISyncronizeInvoke, if it is then I will call BeginInvoke. This works great as long as the class is a generic class:
public class TestClassGeneric<T>
{
public delegate void GetMe();
private GetMe _call;
public TestClassGeneric(GetMe theCall)
{
_call = theCall;
System.ComponentModel.ISynchronizeInvoke si =
_call as System.ComponentModel.ISynchronizeInvoke;
}
}
Since I don't need the class to be generic I want to make it just a standard class:
public class TestClassGeneric
{
public delegate void GetMe();
private GetMe _call;
public TestClassGeneric(GetMe theCall)
{
_call = theCall;
System.ComponentModel.ISynchronizeInvoke si =
_call as System.ComponentModel.ISynchronizeInvoke;
}
}
But then I get a compile error:
"Cannot convert type 'PureLibrary.TestClassGeneric.GetMe' to 'System.ComponentModel.ISynchronizeInvoke' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion"
Could someone please help me understand why this makes such a difference? Since the delegate signature didn't change it seems the casting would be the same.
Thank you.
- Kalvin
|
|
|
|
|
Very interesting question.
I have an idea why this might happen.
1. Generic class: TestClassGeneric<T> .
GetMe is unknown during the compile-time, because it's defined inside a generic class and the typeparam T may vary at run-time (actually, GetMe in this case will be TestClassGeneric<T>.GetMe ).
2. Non-ceneric class: TestClassGeneric .
GetMe is non-generic too, and the compiler may "guess" that the conversion will fail.
Some facts:
System.Action is built-in delegate, it's defined as
public delegate void Action()
If you replace GetMe with Action , you will get an error in two cases.
- At the run-time, the conversion will fail, and
si will be null .
- If you replace
si = _call as System.ComponentModel.ISynchronizeInvoke;
with
si = (System.ComponentModel.ISynchronizeInvoke)_call; ,
both generic and non-generic will fail.
Thanks! I'll remember this - it's a very good task and needs understanding of generics in .NET Framework
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
modified on Wednesday, June 9, 2010 2:13 PM
|
|
|
|
|
Hi ,
Might be a simple fix, but struggling for a long time.
I have built a new site and configured that in IIS, whenever I login to the server I get the "Connect to" windows login dialog. However on pressing cancel in this dialog, te screen loads without any issues.
Any idea how i can get rid of this?
Jack Sparrow
--------------------------------------
Defeat is not the worst of failures. Not to have tried is the true failure.
|
|
|
|
|
Hi,
I have a datagridview with 8 Cells. and now i wanna to do this:
When i am in cell[2] and i finished editing leaving cell with {Tab} I want cell[4] be selected and i be able to enter the data in it.
so please help.
|
|
|
|
|
I am not 100% sure that this will work, since I have not tried it but if cell[3] will never ever ever be editable, set it to readonly.
dataGridView1.Columns[3].ReadOnly = true;
You should be aware that, even if this works for your situation, there are reports of problems with the DataGridViewColumn/Cell Readonly property. It seems from some reading that it does not prevent pasting of data. Once again I cannot confirm this as I have not tried it.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
No, You didnt understand my Question
you have to choose :you should enter data in Cell[2] Or Cell[3] (I mean the user will select and when one has data the onther one will be filled with data Automatically)
Thanks for reply
Please HELP !
|
|
|
|
|
I have been looking at your problem since I got your message. I now understand what you require but unfortunately I cannot find a way to do it.
d@nish was quite right in saying that all you have to do is set CurrentCell to the value you want. Just put a Button on your Form and in its' Click event handler put the following:
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.CurrentCell = dataGridView1[3, 0];
}
and regardless of where you select in the DGV, each time you click the button the [3, 0] cell is selected. No problem.
The problem is in finding an event to handle where you can both check the values for the two cells (that bit is relatively easy) and also set the CurrentCell without throwing an exception (that is where the problems occur).
It is now time for my cocoa and bed but I will keep thinking about this and will get back to you if I find an answer.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
I have a (sort of) solution. It is not perfect and that bothers me but I cannot spend any more time on this.
I hope that it will at least give you a starting point for a solution of your own.
I tested this using a DataGridView with four text columns. The second column (columnIndex 1) should contain "Home" to be considered valid and cause a jump to the fourth column, and the third (columnIndex 2) should when editing reaches there should contain "Business" to be valid.
private bool IsValidColumn1Response(DataGridViewCell dgvCell)
{
return (dgvCell.Value == null) ? false : dgvCell.Value.ToString() == "Home";
}
private bool IsValidColumn2Response(DataGridViewCell dgvCell)
{
return (dgvCell.Value == null) ? false : dgvCell.Value.ToString() == "Business";
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
DataGridView dgv = sender as DataGridView;
if (dgv != null)
{
DataGridViewCell currentCell = dgv.CurrentCell;
if ((currentCell != null) && (currentCell.ColumnIndex == 1))
{
int nextRow = currentCell.RowIndex;
int nextCol = currentCell.ColumnIndex;
if (this.IsValidColumn1Response(currentCell))
{
dgv[nextCol + 1, nextRow].Value = "N/A";
nextCol += 2;
}
DataGridViewCell nextCell = dgv.Rows[nextRow].Cells[nextCol];
if (nextCell != null && nextCell.Visible)
{
dgv.CurrentCell = nextCell;
}
}
else if ((currentCell != null) && (currentCell.ColumnIndex == 0))
{
int nextRow = currentCell.RowIndex;
int nextCol = currentCell.ColumnIndex;
if (this.IsValidColumn2Response(dgv[currentCell.ColumnIndex + 2, currentCell.RowIndex]))
{
nextCol++;
dgv[nextCol, nextRow].Value = "N/A";
}
DataGridViewCell nextCell = dgv.Rows[nextRow].Cells[nextCol];
if (nextCell != null && nextCell.Visible)
{
dgv.CurrentCell = nextCell;
}
}
}
}
As you will see, if you try this out, there are some problems particularly with going back and changing already entered text. It is, however, a start.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Handle CellLeave event and set the active/current cell in the event handler.
|
|
|
|
|
Hi, thanks for reply
Is it possible to give a short example.
Thanks
I need it very much.
Thanks
Regards,
Jojoba
|
|
|
|
|
That is exactly what I have been playing with since my previous message to the OP.
Problem is CellLeave fires before the data has actually reached the cell you either get null (for new cell) or the old cell content so there is no value to test against to tell if a jump should be made or not. CellValuePushed is only fired if VirtualMode is true. You cannot set CurrentCell in CellValidating or CellValidated because you get a StackOverflowException. I'm still playing around but this ain't easy.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Have you tried using the CellValidating event? That's where I've usually done those sort of things after checking to make sure the cell value is valid.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
I've tried to do this in CellValidating , CellValidated and CellParsing . All three throw a StackOverflowException on the line that sets CurrentCell .
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Yes, I see what you mean. It acts as if changing the value of CurrentCell triggers the events all over again.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
i am taking the system date as
DateTime.Now.Date
its giving diffetent values for diferent culture
6/5/2010 12:00:00 AM : for English(United State)
05/06/2010 00:00:00 : for English(United Kingdom)
I want my dates in '6/5/2010 12:00:00 AM' how to get date independent of regional settings
|
|
|
|
|
DateTime is just a long counting ticks IIRC - what you are seeing is just the string representation for the culture in question. Specify your own string format, culture or InvariantCulture.
PiebaldConsult will be here shortly with his ISO comments!
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
As Davey says, DateTime.Now just returns a time - it has no format. When you specify the output format, then you can use the current culture, specify a culture, or fix the format so that it is culture invariant.
Have a look here[^] - it shows all the various parts you can use to format your date.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
As others have pointed out, a DateTime is a region independent structure already. What you are talking about is using a format converter to control how it is displayed.
Before you look at setting the output of the date to be a particular format, I must ask you to consider how your application is going to be used; people have a specific local regional setting in place and generally expect their dates to be displayed in those formats - this can be critical because it has an effect on the understanding of the date. When I looked at your example, my first thought was that you were talking about the 6th of May because I am based in the UK, by displaying a different regional setting you have skewed my understanding of your data.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Ah, DateTime, a perfect source of confusion around the globe. You might want to read this[^]. It holds some cues, including a reference to the infamous ISO 8601.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thank you for your response. I have found out the solution .
I am setting my Application Culture at startup
Application.CurrentCulture = new CultureInfo("en-US");
|
|
|
|
|
I want to find the handle of parent window containing windowless content. Example of web page containing windowless content is http://www.metacafe.com. On this site video files is getting played in windowless mode i.e. the player is not a window but just an content embedded in some other window (host/parent window). I want to determine handle of this parent window. contrary to this on youtube, the area on which video runs, is in itself a window.
Using spy++, I can determine the hierarchy of window in the IE window and If i will follow this hierarchy I can reach to the host/parent window on metacafe. But I believe it would only be applicable to metacafe. There must be some site which will host windowless content in different windows hierarchy.
So, please let me know if anyone knows how to get window handle of parent/host window containing/hosting windowless content.
Regards
f
|
|
|
|