|
You put quotes around it, the paramaterised queries take care of that for you.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Is there a way to determine if a type is nullable, other than hitting it with a tryparse (somewhat like hitting something to see if it will break). IE is there a property on the type that indicates if it is nullable.
I have a generic convert from datarow to properties that is stumbling on nulls, I don't particularly want to do a switch on the type but would like to determine if the type property type will accept a null before attempting to load it.
I may need to do the switch eventually to support the hierarchy type
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you mean, is it able to be null like a string, and not like an int, I believe the answer is no. If you mean is it an instance of an INullable, then 'as' will do that for you.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
This thread on MSDN Forums has several methods that claim to be able to do this. Clickety[^].
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.”
|
|
|
|
|
Thanks Henry, thats what I was looking for. It's a bit weird when an MVP is asking the same question, there are a number of excellent responses.
|
|
|
|
|
Is it pointless to put a lock around a single line of code like this (e.g. in a 'get' accessor) regardless of how _memberString is set?
lock (_locker)<br />
{<br />
return _memberString;<br />
}
|
|
|
|
|
probably, because there's no changes happening to the string. However, I'd be cautious to give a definitive answer, it really depends on what else the code does. Is it multi threaded ? If not, then yes, it's a waste.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Better safe than not safe.
|
|
|
|
|
Given something like:
class c {
_locker;
_memberString;
f() {
...
lock(_locker) {
return _memberString;
}
}
}
caller() {
c v;
...
s = v.f();
}
In s = v.f() _memberString will need to be copied to a temp variable, or directly to s, before f returns. By locking the return you ensure that _memberString isn't modified in mid-copy ... or at least that's the way I would expect it to work in lieu of documentation to the contrary.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Then the issue is CAN _memberString be modified in mid-copy, under any circumstances? Consider that...
1) Strings are immutable, at least at the level of C# code.
2) _memberString is actually a reference to a string, not the string itself.
References are N bytes (can't remember what N is). Perhaps it is possible that while those N bytes are being copied, the copy could be interrupted and the N bytes overwritten by a new value, so that the reference copied to s is corrupted.
Like the other guy said, better safe than sorry.
|
|
|
|
|
I've probably just been sat in front of this monitor for far too long today (about 14 hours so far ) but I can't figure this out!
Consider this struct which is nothing more than an int wrapper:
public struct MyStruct
{
private int _Value;
private MyStruct(int value)
{
_Value = value;
}
public static implicit operator int(MyStruct instance)
{
return instance._Value;
}
public static implicit operator MyStruct(int value)
{
return new MyStruct(value);
}
public int Value
{
get { return _Value; }
}
} I can treat an instance as an int until trying to work with an array or list that expects an int[]:
MyStruct instance0 = 0;
MyStruct instance1 = 1;
MyStruct instance2 = 2;
MyStruct[] myStructArray = new MyStruct[] { instance1, instance2 };
List<int> intList = new List<int>();
intList.Add(instance0);
intList.AddRange(myStructArray);
int[] intArray = myStructArray; Is there any workaround for this (apart from sleep )?
[Addendum] I've just found this blog[^] that says it can be done, but only with reference types [/Addendum]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Monday, August 17, 2009 6:52 PM
|
|
|
|
|
workaround for first part:
foreach(MyStruct my in myStructArray)
{
intList.Add(my);
}
for the other part i don't know
|
|
|
|
|
Yeah, I can iterate through to do it - *Buffer.BlockCopy would probably do it without the iteration by me, but I figured there was some kind of interface I could implement at the struct level so I could keep the code as is and it would just work.
*[Edit] No it won't, it has to be an array of primitives [/Edit]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
IMO an array of something, say X[] myArray can only hold objects of type X or their derivatives; being implicitly convertible to X doesn't count as such conversion would need code execution to happen.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Wait for C# 4.0? (Covariance and contravariance?)
|
|
|
|
|
ok I am a little confused.
I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.
|
|
|
|
|
One whay is to make those values static. and then it will be shared among all instance of a form
|
|
|
|
|
If the other class has a reference to the form instance, you can either make the two control objects public members of the form class, or add two "get" methods to the form that just return the desired properties of the two control.
|
|
|
|
|
It depends on the relationship between the class and the form with those controls.
If the form instanciates the class then you can set properties in the class when the controls change.
If the class instanciates the form then the class can read any custom public properties you create on the form, or better still, the form can raise custom events which the class can subscribe to.
If they are only related by a common ancestor, the form can raise events that bubble up to the common ancestor, and that can in turn set a chain of property changes or method calls back down the line to the class.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Here is what I am trying to do...
This is the code I want to call by 1 procedure retruning a bool value
private void EnableDisableSaveChanges(String txtboxName, String txtValue)
{
if (ckbxUniqueName.Checked == true)
{
if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged & HasrbtnClientMachineControlValueChanged & HasrbtnClientUserControlValueChanged)
{
btnSaveChanges.Enabled = true;
}
else
{
btnSaveChanges.Enabled = false;
}
}
else
{
if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged)
{
btnSaveChanges.Enabled = true;
}
else
{
btnSaveChanges.Enabled = false;
}
}
This is the code I want in a seperate class with a main procedure I can call to return a bool value which is above...
#region Validate if a change has occured to any of the fields on tab 1.
private Boolean HastxtAppNameControlValueChanged()
{
if (txtAppName.Text == UnchangedAppNameField || txtAppName.Text == null || txtAppName.Text == "")
{
return false;
}
else
{
return true;
}
}
private Boolean HastxtVerNumberControlValueChanged()
{
if (txtVerNumber.Text == UnchangedAppVersionField || txtVerNumber.Text == null || txtVerNumber.Text == "")
{
return false;
}
else
{
return true;
}
}
private Boolean HastxtServerLocControlValueChanged()
{
if (txtServerLoc.Text == UnchangedServerPathLocField || txtServerLoc.Text == null || txtServerLoc.Text == "")
{
return false;
}
else
{
return true;
}
}
private Boolean HastxtServerFileNameControlValueChanged()
{
if (txtServerFileName.Text == UnchangedServerFileNameField || txtServerFileName.Text == null || txtServerFileName.Text == "")
{
return false;
}
else
{
return true;
}
}
private Boolean HastxtClientLocFileNameControlValueChanged()
{
if (txtClientLoc.Text == UnchangedClientPathLocField || txtClientLoc.Text == null || txtClientLoc.Text == "")
{
return false;
}
else
{
return true;
}
}
private Boolean HastxtClientFileNameControlValueChanged()
{
if (txtClientFileName.Text == UnchangedClientFileNameField || txtClientFileName.Text == null || txtClientFileName.Text == "")
{
return false;
}
else
{
return true;
}
}
private Boolean HasckbxMasterApplicationControlValueChanged()
{
if (ckbxMasterApplication.Checked == UnchangedMasterAppField)
{
return false;
}
else
{
return true;
}
}
private Boolean HasckbxCreateShortcutControlValueChanged()
{
if (ckbxCreateShortcut.Checked == UnchangedCreateShortcut)
{
return false;
}
else
{
return true;
}
}
private Boolean HasckbxUniqueNameControlValueChanged()
{
if (ckbxUniqueName.Checked == UnchangedUniqueName)
{
return false;
}
else
{
return true;
}
}
private Boolean HasrbtnClientMachineControlValueChanged()
{
if (rbtnClientMachine.Checked == UnchangedClientMachine)
{
return false;
}
else
{
return true;
}
}
private Boolean HasrbtnClientUserControlValueChanged()
{
if (rbtnClientUser.Checked == UnchangedClientUser)
{
return false;
}
else
{
return true;
}
}
#endregion
modified on Monday, August 17, 2009 6:03 PM
|
|
|
|
|
If i change the methods to static functions I can no longer access the form controls. Please help. I believe at least a static function is what I want but I need to be able to access the forms controls values...)
|
|
|
|
|
You almost never want a static function when dealing with an instance, for obvious reasons.
Strip out all that code and checking a million different properties/fields/controls/whatever - the same principle applies even if there is just one that needs to be checked. It will then be clearer to both us and you!
Unless I missed it somewhere way off screen to the right with all the scrolling, I don't see the relationship between the classes - what instanciates what here?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Here is what I am trying to do...
I want to be able to receive a response of true or false when these values change.
The Unchanged... is the variable with the current value.
without doing
if (txtAppName.Text == UnchangedAppNameField)
{something...}
I want to have something that says
if (btxtAppName)
{somehting...}
or say (This is the way I would like to do it.)
if (SomeClass.AreThereAnyChanges)
{something}
My main problem is I do not know how to access the forms controls from the class.
|
|
|
|
|
It is too late here for me to make any sense of your problem (my fault, not yours), but your code wouldbe a little shorter and therefore possibly easier to understand if you replace this (and all the ones like it):
private Boolean HasckbxMasterApplicationControlValueChanged()
{
if (ckbxMasterApplication.Checked == UnchangedMasterAppField)
{
return false;
}
else
{
return true;
}
}
with:
private Boolean HasckbxMasterApplicationControlValueChanged()
{
return !(ckbxMasterApplication.Checked == UnchangedMasterAppField);
}
or, of course:
private Boolean HasckbxMasterApplicationControlValueChanged()
{
return (ckbxMasterApplication.Checked != UnchangedMasterAppField);
}
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.”
|
|
|
|
|
I agree with Dave and Henry:
- static won't help
- more compact code could make it manageable.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|