It seems that 0.8 was the answer. Thanks to all who offered help.
Dictionary as private field in Script# class
سؤال
I have the following class in script# 0.7.5:
[ScriptNamespace("Scripts")]
public class MyClass
{
private Dictionary<string, string> stageMapping = new Dictionary<string, string>();
public PortfolioOptimisationOverlord()
{
stageMapping["first"] = "http://www.me.com/mike";
stageMapping["second"] = "http://www.me.com/terry";
stageMapping["third"] = "http://www.me.com/billy";
stageMapping["fourth"] = "http://www.me.com/bobby";
stageMapping["fifth"] = "http://www.me.com/richard";
}
}
unfortunately when compiled it doesn't produce a prototype class so fails saying that it can't access this
.
If I make a private field of type int
it seems to work, but not with dictionarys or lists.
--EDIT--
here's some more information:
The javascript produced by this is:
////////////////////////////////////////////////////////////////////////////////
// Scripts.PortfolioOptimisationOverlord
Scripts.PortfolioOptimisationOverlord = function Scripts_PortfolioOptimisationOverlord() {
/// <field name="_stageMapping" type="Object">
/// </field>
this._stageMapping = {};
this._stageMapping['first'] = 'http://www.me.com/mike';
this._stageMapping['second'] = 'http://www.me.com/terry';
this._stageMapping['third'] = 'http://www.me.com/billy';
this._stageMapping['fourth'] = 'http://www.me.com/bobby';
this._stageMapping['fifth'] = 'http://www.me.com/richard';
}
If I add an int
private field called intField
:
////////////////////////////////////////////////////////////////////////////////
// Scripts.PortfolioOptimisationOverlord
Scripts.PortfolioOptimisationOverlord = function Scripts_PortfolioOptimisationOverlord() {
/// <field name="_stageMapping" type="Object">
/// </field>
/// <field name="_intField" type="Number" integer="true">
/// </field>
this._stageMapping = {};
this._stageMapping['first'] = 'http://www.me.com/mike';
this._stageMapping['second'] = 'http://www.me.com/terry';
this._stageMapping['third'] = 'http://www.me.com/billy';
this._stageMapping['fourth'] = 'http://www.me.com/bobby';
this._stageMapping['fifth'] = 'http://www.me.com/richard';
}
Scripts.PortfolioOptimisationOverlord.prototype = {
_intField: 0
}
as you can see the only change is the addition of a type with .prototype
on the end.
it fails on construction.
المحلول
لا تنتمي إلى StackOverflow