Answered by:
Actionscript to C#
Question
-
Hi Could anyone give me any pointers on how I would convert this Actionscript to C#, I'm particularly confused with the return Object Array
Thanks
Ade.
final internal class PropertyInfo { public var propertyParent:Object = null; public var propertyName:String = null; final public function getValue():* { try { if(propertyName) return propertyParent[propertyName]; else return propertyParent; } catch(e:Error) { return null; } } final public function setValue(value:*):void { propertyParent[propertyName] = value; } final public function clear():void { propertyParent = null; propertyName = null; } }Wednesday, March 24, 2010 4:24 PM
Answers
-
You could base the class on a dictionary I suppose, but C# does not support on the fly attributes like ActionScript.
Does this help?
class PropertyInfo { private Dictionary<String, Object> bucket = new Dictionary<string, object>(); public String propertyName = null; public object getValue() { return String.IsNullOrEmpty(propertyName) ? bucket : bucket[propertyName]; } public void setValue(Object value) { if (!String.IsNullOrEmpty(propertyName)) { bucket[propertyName] = value; } } public void clear() { bucket = new Dictionary<string, object>(); propertyName = null; } }
jon.stromer.galleyWednesday, March 24, 2010 5:46 PM
All replies
-
You shouldn't use names that are already in use by the FCL. I suppose this is something in the neighborhood of what you are trying to do (I guess)
sealed internal class MyPropertyInfo { public Object PropertyParent {get; set;} public String PropertyName { get; set; } public void Clear() { PropertyName = null; PropertyParent = null; } }
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comWednesday, March 24, 2010 5:17 PM -
You could base the class on a dictionary I suppose, but C# does not support on the fly attributes like ActionScript.
Does this help?
class PropertyInfo { private Dictionary<String, Object> bucket = new Dictionary<string, object>(); public String propertyName = null; public object getValue() { return String.IsNullOrEmpty(propertyName) ? bucket : bucket[propertyName]; } public void setValue(Object value) { if (!String.IsNullOrEmpty(propertyName)) { bucket[propertyName] = value; } } public void clear() { bucket = new Dictionary<string, object>(); propertyName = null; } }
jon.stromer.galleyWednesday, March 24, 2010 5:46 PM -
final is equivalent to "sealed"
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comWednesday, March 24, 2010 5:49 PM -
If C# 4 is an option, you might want to just use ExpandoObject instead. This will provide you with the same level of flexibility you're trying to create via this custom class, by using the dynamic type.
Reed Copsey, Jr. - http://reedcopsey.comWednesday, March 24, 2010 5:53 PM -
Is VS 2010 even out yet?
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comWednesday, March 24, 2010 5:59 PM -
Is VS 2010 even out yet?
No, but VS 2010 RC works fantastically. All of my current development is targetting .NET 4 using the RC right now...
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
Reed Copsey, Jr. - http://reedcopsey.comWednesday, March 24, 2010 6:37 PM -
Is VS 2010 even out yet?
No, but VS 2010 RC works fantastically. All of my current development is targetting .NET 4 using the RC right now...
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
Reed Copsey, Jr. - http://reedcopsey.com
Probably still not a good idea to tell users in development to use RC just yet. We should target current releases.If you want to mention upcoming releases, you should mention that but caveat the response that it is not released yet. RC = Release Candidate.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comWednesday, March 24, 2010 6:44 PM -
Bah! It has a GoLive license at this point - but that's why I did say "if C# 4 is an option...". Point taken, though - this would work well if you are willing to migrate to a non-released (<3 weeks from release, though) release candidate.Probably still not a good idea to tell users in development to use RC just yet. We should target current releases.
If you want to mention upcoming releases, you should mention that but caveat the response that it is not released yet. RC = Release Candidate.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
Reed Copsey, Jr. - http://reedcopsey.comWednesday, March 24, 2010 7:31 PM -
Not everybody immediately jumps on the bandwagon for upcoming releases since they are busy in their paradigms. I am still on Windows XP. By the time I get to Windows 7, I will have missed the whole Vista thing. (But, hearing the rant for the last few years, I know I didn't miss much).
Also, when users ask questions, it just seems wise to give them "current" responses, not "future" ones. I doubt in three weeks everyone will have VS 2010 either.
I was one of the first in my company to use LINQ and 2008 features. (Except WPF, for what I do it offers little).
Thanks for the "Bah". Reminds me of the attitude, it is new, its gotta be good..If you say so....
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comWednesday, March 24, 2010 7:56 PM -
Thanks for the "Bah". Reminds me of the attitude, it is new, its gotta be good..If you say so....
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comHeh. The "Bah!" was meant to be a joke - but that never comes through well online :(
I'm perfectly aware of the delays in upgrading. It's a normal part of business. (I wish it weren't the case - I'd love to be able to target Vista+ only for my new development, or even W7 only, but it's not practical).
Reed Copsey, Jr. - http://reedcopsey.comWednesday, March 24, 2010 8:14 PM -
Thanks for the "Bah". Reminds me of the attitude, it is new, its gotta be good..If you say so....
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comHeh. The "Bah!" was meant to be a joke - but that never comes through well online :(
I'm perfectly aware of the delays in upgrading. It's a normal part of business. (I wish it weren't the case - I'd love to be able to target Vista+ only for my new development, or even W7 only, but it's not practical).
Reed Copsey, Jr. - http://reedcopsey.com
I work with the military Reed, they are still on Windows 2000, so "slowly" we must move..
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.comWednesday, March 24, 2010 9:30 PM -
Yeah, I know the feeling. We've got quite a few military and national labs as customers - and quite a few Windows 2000 (and even NT4) systems we have to support on occasion. It's a pain.
I work with the military Reed, they are still on Windows 2000, so "slowly" we must move..
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
Reed Copsey, Jr. - http://reedcopsey.comWednesday, March 24, 2010 10:46 PM -
Thanks for all the help, Could someone tell me how this would work with an ExpandoObject
Once again thanks for all your help.
Best
Ade.
Thursday, April 1, 2010 10:24 AM -
Thanks for all the help, Could someone tell me how this would work with an ExpandoObject
Well, this class seems to be used to store a "property bag", where you can add a property with a name to any object.
ExpandoObject does the same thing:
dynamic myObj = new ExpandoObject();
myObj.SomeProperty = 3.14;
myObj.SecondProperty = "Something else";
You basically just create it, and shove anything into it you want, with any property name you wish, and it automatically "expands" to hold that property.
Reed Copsey, Jr. - http://reedcopsey.comThursday, April 1, 2010 6:42 PM