|
You also might want to look at the NumericUpDown control if you are trying to manage a numeric value. You can set the minimum value to zero and the data type must be numeric so characters are invalid.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }
}
public int EntityId { get; set; }
}
Is this possible ?
|
|
|
|
|
No - you can't define a property within a method or constructor, only within the class body.
What exactly are you trying to do? Why do you think you need this?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
An optional property is the same as any other property; the optional bit depends on how you use it. Maybe you should consider a nullable type[^].
|
|
|
|
|
I would suggest that what you are asking about is going to violate the S in SOLID.
This space for rent
|
|
|
|
|
It depends on what you mean with "optional Property".
Do you mean something like this :
You have a Property "BorderStyle" and a Property "BorderSize".
If you select BoderStyle = None then you want that BorderSize isn't to be seen (invisible).
|
|
|
|
|
Check out the "ExpandoObject".
ExpandoObject Class (System.Dynamic)
(Always makes me think of "Plastic Man" for some reason).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
5 
|
|
|
|
|
I would add the optional property in an Interface. Then you inherit the Interface you want to apply optional methods or properties.
For example;
public interface IExtraProperty
{
public int ExtraPoperty { get; set; }
}
public class MyClass : IExtraProperty
Ben Scharbach
Temporalwars.Com
YouTube:Ben Scharbach
|
|
|
|
|
Getting errors in this code on 'ToXml':
public class EventCode
{
public static string ToXml(Soap.EventCode.EvCodes value)
{
switch (value)
{
case Soap.EventCode.EvCodes.DispatchedForDelivery:
case Soap.EventCode.EvCodes.Delivered:
return "OD";
case Soap.EventCode.EvCodes.DepartedFromTerminal:
return "L1";
}
}
}
What am I doing incorrectly so I can fix this error:
|
|
|
|
|
If nothing matches the case statements, what value do you want to return? Add a return with this value at the end of the method or use the default keyword inside tour switch and return the value there.
This space for rent
|
|
|
|
|
I agree with adding the Default keyword in the Case block.
Ben Scharbach
Temporalwars.Com
YouTube:Ben Scharbach
|
|
|
|
|
public static string ToXml(Soap.EventCode.EvCodes value)
{
string returnValue = null;
switch (value)
{
case Soap.EventCode.EvCodes.DispatchedForDelivery:
case Soap.EventCode.EvCodes.Delivered:
returnValue ="OD"; break;
case Soap.EventCode.EvCodes.DepartedFromTerminal:
returnValue ="L1"; break;
}
return returnValue;
}
modified 26-Sep-17 7:17am.
|
|
|
|
|
You'll need some break s in there.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
corrected 
|
|
|
|
|
Are you sure? It's showing as "modified", but I still don't see any break s.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
oh my!!
earlier "= " sign was missing, initially i thought that and corrected, after adding the code in visual studio code editor i realized that "break " is missing.
Now its finally corrected
this is the problem when writing the code without using code editor software
|
|
|
|
|
In your example there would be nothing to return if value where not one of the handled cases. You need to specify a return value for ALL cases or throw an exception for invalid values. One way to do this is by using the default case in your switch statement.
Here is an example:
public class EventCode
{
public static string ToXml(Soap.EventCode.EvCodes value)
{
switch (value)
{
case Soap.EventCode.EvCodes.DispatchedForDelivery:
case Soap.EventCode.EvCodes.Delivered:
return "OD";
case Soap.EventCode.EvCodes.DepartedFromTerminal:
return "L1";
default: throw new ArgumentOutOfRangeException(nameof(value), "Unsupported Evcode: " + value);
}
}
}
modified 19-Oct-17 11:32am.
|
|
|
|
|
Anyone know if it's possible to extract or read the contents of VBA BAS files from MS Access using C#?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Certainly possible. Doesn't mean it is cost effective though.
You would of course first need to figure out the format of the file.
Although you might want to consider whether all you want to do is read it. If you want to execute it then reading it is probably pointless unless you intended to replicate functionality that probably exists somewhere.
|
|
|
|
|
I don't want to execute it.
Do you know HOW to extract the code from VBA?>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Well, I'm thoroughly confused by your response.
enhzflep wrote: Mate, there's no need to SHOUT. Your question is perfectly clear without it. It merely gives the impression of someone too inarticulate to ask for the information they require who then becomes frustrated and raises their voice at the person that perfectly answered their ill-formed question. Not generally seen as a desirable personal attribute... Where did you get "shouting" or "raising their voices" from? Where did this little tirade come from? You'll have to clarify that for me.
enhzflep wrote: Typing "c# extract vba from access" into google
I DID look at Google. I ALWAYS go to Google. I also always come here because I know CP to be a treasure trove of experienced developers. More than once I've gotten answers or code from other devs here without spending hours sifting through half baked or off topic Google code samples.
enhzflep wrote: Since I've got 20 seconds to kill that I can donate to someone clearly to busy to expend it themselves, here's the first couple.
How did you come to a point where you felt it necessary to insult me? Again, I'm going on the assumption here that I somehow offended you, which I can't for the life of me see how or where.
Look, I asked a simple question. You clearly don't have an answer. I'm not interested in continuing a discussion with someone who has no substantive contribution to the problem other than redirect me to Google.
Save your replies.. I don't feed trolls.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: I DID look at Google. I ALWAYS go to Google
You should specifically mention that in your first post. Given that there are so many google results you might also want to point out why those are inadequate in your post (first one.)
|
|
|
|
|
enhzflep wrote: Mate, there's no need to SHOUT
I think he was emphasizing rather than shouting.
|
|
|
|