When to not use dynamic in C#
I'm making a class similar to the following:
public class KeyValue
public readonly string key;
public readonly object value;
Value could be of any object type as a result of this design.
Alternatively, I could just use dynamic for value and it'll make my life easier, because it would mean no type-casting, and also because, as far as I understand, I could use value types without needing to box/unbox.
Is there any reason not to use dynamic and to use object instead? Because I can't think of any.
Note: I realize generics are much more suited for this, but it doesn't work for my needs. The above is really a simplification just for the purposes of this question.
Hi
StrikeBT,
>>Is there any reason not to use dynamic and to use object instead? Because I can't think of any.
The compiler ignores the variables
defined by dynamic. So it will brings some errors in runtime.
For example:dynamic typing is that it often hides bugs that would be otherwise revealed during compilation. Such bug then only manifests on run-time, which of course makes it much harder to detect.
Please take a look at the example in the following articles. Note the samples it would be helpful to understand more.
What is the difference between “dynamic” and “object” keywords?
dynamic type in C#.4.0 Where and how to use? How does it differ from var and object?
>>Note: I realize generics are much more suited for this, but it doesn't work for my needs.
Yes, for example code as below
public interface IXRefData
// TODO: add definition here
public class XRefComponent<TData>
where TData : IXRefData
public void Update() { }
public class XRefPickData : IXRefData { }
public class XRefPackData : IXRefData { }
public class XRefUpdator
private List<dynamic> components = new List<dynamic>();
public List<dynamic> Components
get { return components; }
set { components = value; }
class Program
static void Main(string[] args)
XRefUpdator updator = new XRefUpdator();
// Now we can add two different classes to list Components
updator.Components.Add(
new XRefComponent<XRefPickData>());
updator.Components.Add(
new XRefComponent<XRefPackData>());
Thanks,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
List of values failure error when trying to use dynamic data values
Hi there,
I have a user who is experiencing problems when trying to use dynamic values in a report. Whenever he tries to insert dynamic parameters he gets the following error message:
Prompting failed with the following message: 'List of Values failure: Failed to get values. [Cause of error: Access is denied.] Error Source: prompt.dll Error Code: 0x8004380D
He even opened the sample report - prompting.rpt - that is included with CR and gets the same error.
We are using Crystal Reports XI Release 2 ver. 11.5.11.1470.
Any help would be appreciated.Please excuse my ignorance of the product. I've had this problem dropped in my lap and I know practically nothing about Crystal Reports. In doing some digging it appears to me as if the BusinessObjects Enterprise software may not be installed properly, if at all. In the programs menu under the BusinessObjects XI Release 2 folder I see a BusinessObjects Enterprise folder, but the only icon listed in that folder is Software Inventory Tool.
Is the BusinessObjects Enterprise software a separate install from Crystal Reports or is it bundled together? I talked with the tech that did the install and he said that all he had was the Crystal Reports install media. -
I just updated to ios 7 on my iPhone 4 how do you turn the apps off when your not using them? The old way of double clicking and then pressing the app until a red minus button comes doesn't work it opens it back up!?
Double click home button, then swipe up on app picture (not the icon itself)
-
Ipod loses battery when im not useing it! 40 ha more like 2
ok my 160gig ipod dies when im not useing it i went to school today full charge at school used it for an hour and a half and on the bus home it dies. i dont get it. this has happend a few times now and i know somethings up PLEASE HELP. i didn't pay 350$ for a 2 hour battery life.
There a several posts about the battery dying quickly with firmware 1.0.2. Check here (http://discussions.apple.com/thread.jspa?messageID=5610235�) for a fairly succinct explanation and workaround until Apple hopefully fixes the issue with the next firmware update.
-
Generating SOAP Envelope when DO NOT USE ENVELOPE option is marked
My scenario: SPROXY => XI => 3rdParty WebService. Communication is synchronous. I've a problem with soap envelope. It is required by webservice, but when I use standard soap envelope generated by SAP I've a problem with receiving response from webservice.
So I want to create my own envelope. For this reason I've used DO NOT USE SOAP ENVELOPE option. Now the challenge comes. How can I create my own soap envelope?
Do you have any working example? Soap envelope should be added to message send from XI to 3rdParty WebService.
Helping answers => a lot of pointsI'm talking about HTTP header.
When I'm sending SOAP request from SAP my whole message looks like when I use soap envelope
POST / HTTP/1.0
Accept: */*
Host: 192.168.132.179:54000
User-Agent: SAP-Messaging-com.sap.aii.messaging/1.0505
Content-ID: <soap-02cce7702b1a11dd9902000c29ee261e[at]sap.com>
Content-Type: text/xml; charset=utf-8
Content-Disposition: attachment;filename="soap-02cce7702b1a11dd9902000c29ee261e[at]sap.com.xml"
Content-Description: SOAP
Content-Length: 259
SOAPACTION:
<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'><SOAP:Header/><SOAP:Body><ns0:Sd2Ids_SzfExport xmlns:ns0='http://www.dat.de/sdii/ids/Sd2SOAP.wsdl'><arg1>1234567899-0</arg1><arg2>1</arg2></ns0:Sd2Ids_SzfExport></SOAP:Body></SOAP:Envelope>
Always after such request I got and HTTP 411 error.
In opposite, when I'm sending request from e.g. Altova or SoapUI, my message looks:
POST / HTTP/1.1
Content-Type: text/xml; Charset=UTF-8
User-Agent: XML Spy
Host: 192.168.132.179:54000
Content-Length: 489
Connection: Keep-Alive
Cache-Control: no-cache
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:Sd2Ids_SzfExport xmlns:m="http://www.dat.de/sdii/ids/Sd2SOAP.wsdl">
<arg1 xsi:type="xsd:string">1234567899-0</arg1>
<arg2 xsi:type="xsd:string">1</arg2>
</m:Sd2Ids_SzfExport>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
After that request WebService response is correct.
You can find such differences (except Content-length which is a result of XML message formatting) in those two headers:
- for first is used HTTP 1.0 protocol for later 1.1
- in SAP header an info about attachment is added
After a lot of test I thing that those attachment info in header of HTTP is causing a problem. So I want to use DO NOT USE SOAP ENVELOPE option to generate HTTP header without Content-Disposition and generate SOAP Envelope manually. -
How to make VM to suspend when it not use , VDI3.0 with SGD 4.5
Hi All,
We are using SunVDI3.0 with VBox 2.0.10 and connecting via SGD 4.5.
i konw that we can do suspending vm on vmware esx, however i couldn't find it in VirtualBox provider.
how to make VM to suspend when vm is not using for some period time.
thanks in advance
-kevin-
Edited by: kevin on Sep 27, 2009 5:44 PMHi All,
We are using SunVDI3.0 with VBox 2.0.10 and connecting via SGD 4.5.
i konw that we can do suspending vm on vmware esx, however i couldn't find it in VirtualBox provider.
how to make VM to suspend when vm is not using for some period time.
thanks in advance
-kevin-
Edited by: kevin on Sep 27, 2009 5:44 PM -
Error when applying Note using SNOTE and Manually
Hi Gurus,
I get the following message when i try to download a note using SNOTE
Error: Format of correction Instructions 0120061532 1 0000771620 0002; unable to read corr.instruct
I tried downloading the note to my local machine and then uploading it locally but got the same result.
Any thoughts on how to procede?Hi ,
Are you trying to download directly on to server? then you need to connect your server to SAP router and connected to Service market place. If you want to do it off line? get the note by Download manager and apply from Snote.
Regards,
Hari.
PS: Points are welcome. -
My ipod touch only charges when its not in use and doesn't come up with the charging symbol. Please help cheers
First try another charging source. Maybe the source yo are using is not putting out enough pwere when the screen is on.
Next try:
- Reset the iOS device. Nothing will be lost
Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
least ten seconds, until the Apple logo appears.
- Reset all settings
Go to Settings > General > Reset and tap Reset All Settings.
All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
- Restore from backup. See:
iOS: How to back up
- Restore to factory settings/new iOS device. -
Data charges when phone not used
Had problem with my Curve 8330. Roller ball stuck and phone froze. Was out of service until I got an exchange phone on Dec. 24. Didn't use the phone but was charged for data usage on Dec. 25. Replacement phone is the same in data usage charges. I'm older person so I have never used the web to surf but have been charged in excess of $197 for a month in data usage. Don't know how to watch tv, movie or listen to music. Why is this happening on days when I know I was not using the phone? I use the phone to text and sometimes check Facebook. My plan has 7 megabytes of data included but since I have had refurbished phones the data usage is skyrocketing.
These forums are dedicated to Residential products and services offered by Verizon.
For help on Verizon Wireless issues, please post your topic on the Verizon Wireless Community at http://community.verizonwireless.com/ -
Could someone explain on examples when do we use dynamic link?
I noticed hashmarks (#) around some MII expressions and I still don't understand when should I use them...
What was the intention to introduce dynamic link into MII?
thx
1. at certain places the hashmarks must be there
2. at certain places the hashmarks mustn't be there
3. at certain places the hashmarks could be thereHi Tibor,
basically, hashmarks are used when you want to subsitute some values dynamically.
Let's say you have a local variable named Temp whose value is section ID which changes depending on employee ID.
Now you want to pass this to a query, you cannot obviously pass the ID but assign it to Local.Temp and Pass '#Local.Temp#' to it to substitute the value dynamically.
So the query is called with different Temp values generated dynamically depending on some logic.
Hope this helps.
Best Regards,
Swaroop -
JTRee's not updating when your not using DefaultTreeNode
See topic @ http://forums.sun.com/thread.jspa?threadID=153854&start=0&tstart=0
I have very similar issue, I have a JTree (with CheckBoxes for it's leaves and branches), and I am using a custom TreeModel rather than DefaultTreeModel.
I can add nodes to my TreeModel correctly, but the tree has doesn't always display new nodes.
Any nodes added to a node/branch show correctly if, and only if I have not expanded the branch yet. Once I expand a branch new nodes never appear. They are being added to the model correctly, because I can select them(by selcting the parent) and print all selected nodes.
In the the thread listed above it looks like all I sould have to do is implement hashCode() and equals()..
But when looking @ http://java.sun.com/javase/6/docs/api/javax/swing/tree/DefaultTreeModel.html
I cann't find anything about equals() or hashCode()
Can anyone provide some insight on what they do, or if I'm barking up the wrong tree.
PS sorry for zombifying the previous thread, most MB I've been on preffered zombies to 30 threads regarding the same issue.so here's a severely condensed version of my code.
class CheckTreeModelSupport implements TreeModelListener {
List alistListeners = new ArrayList<TreeModelListener>;
//Above just struck me as odd... but I believe that's how Sun said to do it.
public void addTreeModelListener(TreeModelListener listener) {
if ((listener != null) && !alistListeners.contains(listener))
alistListeners.add(listener);
// Also defined removeTreeModelListener(TreeModelListener), fireTreeNodesChanged(TreeModelEvent),
// fireTreeNodesInserted(TreeModelEvent), fireTreeNodesRemoved(TreeModelEvent), fireTreeStructureChanged(TreeModelEvent)
// and the fireTreeNodesInserted(Object, Object[], int[] Object[]) as you reccomended above.
class CheckBoxNode extends TreeModelSupport implements TreeModel {
private String strText; // text for node
private boolean bState; // stores wether the CheckBox is Checked or not
private int iBranchCount; // strores number of children
private int iIndex; // stores index among siblings
static CheckBoxNode cbnodeLastSelected; // for keeping track of where to insert new nodes
. private List<CheckBoxNode> alistChildren; // ArrayList of childNodes
// skipping, a laundrylist of stuff that doesn't apply
public CheckBoxNode addChild(String strName) {
CheckBoxNode cbnodeNew= new CheckBoxNode(strName, this, iBranchCount);
//Constructor sets node text to strName, uses this to identify it's parent, for various initializing, and iBranchCount to set the iIndex
TreeModelEvent eventNodeAdded = null;
if (alistChildren == null)
alistChildren = new ArrayListCheckBoxNode();
alistChildren.add(cbnodeNew);
iBranch++;
eventNodeAdded = new TreeModelEvent(this,getPathToRoot(this), new int[]{cbnodeNew.getIndex()}, new CheckBoxNode[]{cbnodeNew});
return cbnodeNew; } Let me know if any other code is of use, and if so what you need to see
Edited by: porpoisepower on Feb 1, 2010 10:19 PM -
Which is better when temporarily not using Mac - 'screensaver' or 'sleep'?
I manually invoke a screensaver when I won't be using my MacBook for a while (up to an hour or two) -- instead of putting it to sleep.
When I come back to use the computer again, with rare exceptions the hard drive doesn't rev up as it does when I return to use the Mac after putting it to sleep (either manually or by closing the case).
Is one of these better, in terms of wear and tear on the hard drive?
Also, does the fact that the computer's hard drive apparently does not rev up when use of the computer is resumed from the screensaver (rather than from 'sleep') mean that the hard drive has been spinning (idling) the whole time?
If so, is putting the computer to sleep preferable, since it essentially turns the hard drive 'off' rather than allowing it to spin the entire time that the computer isn't being used?
Thanks.When to choose sleep rather than screen saver.
When to choose sleep over shutdown.
I usually always let my display go to sleep and then my computer
go to sleep before my screen saver is set to start. I have it set this way for
both power adapter and battery. I have my screen saver setup with a
slideshow but seldom use it. I have it setup to require a passcode when
waking from sleep or screen saver. If I want to download a large update
that would take a couple of hours I choose never for computer sleep and
a couple of minutes for display sleep in both power adapter and battery.
I only shutdown my computer when I am done for the day. If I'm getting up
to make a fresh pot of coffee or something I close the lid eventhough I have
display sleep and computer sleep set.
These are my preferences and the way I like them. You should adjust these settings
on your MacBook so that it is comfortable for you to use.
I noticed that your MacBook is about 4 years old (early or late 2006 model). Are
you asking these "When To" questions to try to prolong the life of your computer's
hardware? If so, my best answer would be:
+Backup your important folders and media at least twice+. Hardware can fail at anytime.
I have read of 2 week old MacBook Pros being sent back to Apple for hardware
replacement. If you have Kernel Panics, questionmark, a blue or black screen; system
preferences set to what someone thinks will provide hardware longevity won't be as
useful as a good backup. I should have started this with an "in my humble opinion".
Limnos has already said that some will argue both ways on the wear and tear savings
in an earlier reply.
Set your preferences to where they are most comfortable for you and enjoy using your
computer.
Kind Regards,
A -
1043 error when trying to use dynamic events on RT system
Hello,
I am trying to define some dynamic events as specified it the LabView help for RT targets. But when trying to run the vi I get the 1043 error. What am I doing wrong?
Thank you,
Przemek
Attachments:
RT test.vi 17 KBDear Przemek,
to fully understand you problem and to be able to help you, I will have to ask you a few questions:
What version of LabVIEW are you using?
What RT target are you using?
What specific help file are you referring to?
Are you creating an executable? If yes, this document could be helpful:
http://digital.ni.com/public.nsf/allkb/1E180530E05E4DB28625731C006CCB5A?OpenDocument
Regards,
Mateusz Stokłosa
Applications Engineer
National Instruments -
When should one use Dynamic Triggers ?
I have a requirement where I want to send an email to HR whenever the supervisor of an employee changes.
I am on 11.5.10.2 and the options which I know are :
a) Business Events ( Not Possible as on 11i there are form handlers and not api on people/assignment form)
b) Database trigger ( I do not want to use custom trigger on database)
c) Alerts( I am currently using but its difficult to identify change in supervisor value only)
d) Dynamic Trigger ?
Thanks
AshishHi Ashish,
Why do not you try with form personalization.
1) using execute procedure call a procedure .
2) then from the procedure you can call the below standard procedure to send email.
l_mail_conn := UTL_SMTP.open_connection (l_mailhost, 25);
UTL_SMTP.helo (l_mail_conn, l_mailhost);
UTL_SMTP.mail (l_mail_conn, from_name);
UTL_SMTP.rcpt (l_mail_conn, to_name);
UTL_SMTP.open_data (l_mail_conn);
UTL_SMTP.write_data (l_mail_conn
, 'Date: '
|| TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS')
|| CHR (13)
UTL_SMTP.write_data (l_mail_conn, 'From: ' || from_name || CHR (13));
UTL_SMTP.write_data (l_mail_conn, 'Subject: ' || subject || CHR (13));
UTL_SMTP.write_data (l_mail_conn, 'To: ' || to_name || CHR (13));
UTL_SMTP.write_data (l_mail_conn, Message );
UTL_SMTP.close_data (l_mail_conn);
UTL_SMTP.quit (l_mail_conn);
3) Make sure that you enable the below setups .
The UTL_MAIL package is new enhancement in Oracle 10g. you have to run
{ORACLE_HOME}/rdbms/admin/utlmail.sql
{ORACLE_HOME}/rdbms/admin/prvtmail.plb
to install it and also run
ALTER SYSTEM SET smtp_out_server = 'ip_address:port' SCOPE=BOTH;
I hope it may help you ..
Thanks
Asif -
Well I'm a frequent Firefox user ad recently my cursor has started to dissapear when I'm not moving it. However when i press a key it flashes back for a second also, when I'm moving it flickers a lot (one moment its there one moment it isn't). How do i fix this?
== This happened ==
Every time Firefox opened
== Earlier today (july 20th 2010)Never saw this problem until today, first on Facebook, then on these Mozilla support pages. I had one Firefox window with multiple FB and Mozilla tabs open.
Here's my observations: On the FB and Mozilla pages, the cursor (arrow/hand) acted identical and as described here, would disappear after 2-3 seconds of inactivity or non-motion, then instantly reappear with mouse movement or key strike but only momentarily if no further motion/action occurred. Interestingly, I also had one FoxNews tab (actually FoxNewsInsider) open, and observed slightly different activity. The Cursor/hand would disappear as described above, but instead of staying invisible, it flashed on /off for what appeared to be <1 second on then <1 second off, until mouse movement or key strike. Now, here's the really interesting part ... When I opened a second FoxNewsInsider tab, the problem corrected itself with no direct action on my part to resolve the issue. I was going to close all tabs, then Firefox and perform the system reboot to correct this annoyance ... but, still have not seen the problem.
Okay, I'm not going to say viewing FoxNewsInsider webpages not only provides one perspective on news, and the added benefit of fixing cursor/hand problems .. but maybe there's some to being well informed ... Sorry folks, couldn't resist ... :) I will be watching for the disappearing cursor issue again, and will reply here with any updates or changes in my observations.
Maybe you are looking for
-
How to create a link to download a .psd or .eps file
I'm attempting to create a link to a .psd file for a user to download. Whenever I link to the .psd file, Dreamweaver wants to convert it to a JPEG. Is there a way to link to a .psd file to have the user download that file? I'm trying to have files th
-
Need for implementing Objects By Filter (OBF) method in ACE
Hi All, i wanted to understand the significance of the OBF method in ACE. Can i implement my logic only using Actor from User (AFU) and Actor from objects (AFO). Does it impact the performace if OBF is not implemented. Please provide you inputs on th
-
Unable to create a PO from a shopping cart in classic scenerio
Hi Experts, I tried creating a PO from the Shopping cart, but i am getting an error Number range 70 doesnt exist. Whereas when i tried creating a PO from Rfx, PO is getting created. Can somebody suggest what would have went wrong. Regards, Santhosh
-
I have an old version of photoshop and would like to install it on my new Laptop but I cant find the link or the serial number. can you help
-
Creating an additional email address
I already have an @me.com email address. I would like to create a new, additional one. How do I do this?