Microsoft.JScript.GlobalScope.AddField C# (CSharp) Method

AddField() public method

public AddField ( String name ) : FieldInfo
name String
return System.Reflection.FieldInfo
      public FieldInfo AddField(String name){
        if (this.fast)
          return null;
        if (this.isComponentScope)
          return ((GlobalScope)this.parent).AddField(name);
        FieldInfo field = (FieldInfo)this.name_table[name];
        if (field == null){
          field = new JSExpandoField(name);
          this.name_table[name] = field;
          this.field_table.Add(field);
        }
        return field;
      }

Usage Example

            public PartialTrustEvaluationStrategy(string expression, VsaEngine engine)
                : base(engine)
            {
                //
                // Following is equivalent to declaring a "var" in JScript
                // at the level of the Global object.
                //

                _scope = (GlobalScope)engine.GetGlobalScope().GetObject();
                _contextField = _scope.AddField("$context");
                _expression = expression;
            }