Giving value to a ListToken is it possible?

0

I get this error: Use of the local variable not assigned enumerator

Code that gives error:

private void offertoro_Load(object sender, EventArgs e)
{
  List<JToken> list = JObject.Parse(System.IO.File.ReadAllText("offerids_offertoro.json")).Children().ToList<JToken>();
  List<JToken>.Enumerator enumerator1;
  try
  {
    enumerator1 = list.GetEnumerator();
    while (enumerator1.MoveNext())
    {
      JProperty source = (JProperty) enumerator1.Current;
      source.CreateReader();
      IEnumerator<JToken> enumerator2;
      if (Operators.CompareString(source.Name, "offers", false) == 0)
      {
        try
        {
          enumerator2 = source.Values().GetEnumerator();
          while (enumerator2.MoveNext())
            this.TextBox1.Text = this.TextBox1.Text + ((JObject) enumerator2.Current)["oid"].ToString() + "\r\n";
        }
        finally
        {
         // EL ENUMERATOR 2 TAMBIEN ME DA ERROR
          if (enumerator2 != null)
            enumerator2.Dispose();
        }
      }
    }
  }
  finally
  {
     // me da error AQUI <------------------------
    enumerator1.Dispose();
  }
  this.WebBrowser2.Document.Cookie = "1";
  this.c_url = "1";
  this.finallink = "1";
  this.LabelProces.Text = this.LabelProces_OpeningOT;
  this.LabelCompleted.Text = this.LabelCompletedd;
  if (MyProject.Forms.Form4.GroupBoxSpeedAverage.Checked)
    this.CompleteOffer.Interval = 7000;
  else if (MyProject.Forms.Form4.GroupBoxSpeedSlow.Checked)
    this.CompleteOffer.Interval = 9000;
  else if (MyProject.Forms.Form4.GroupBoxSpeedFast.Checked)
    this.CompleteOffer.Interval = 5000;
  this.GetAvailableOffers.Start();
}

Another mistake very often, is a new virtual member in a sealed class

Código:

internal virtual Label LabelCompanyName
{
    [DebuggerNonUserCode] get
    {
        return this._LabelCompanyName;
    }
    [DebuggerNonUserCode, MethodImpl(MethodImplOptions.Synchronized)] set
    {
        this._LabelCompanyName = value;
    }
}

It's the get mainly.

One last mistake I get is this: The name of type 'RemoveNamespaceAttributesClosure' does not exist in the type 'InternalXmlHelper'

Code:

return (IEnumerable) obj.Cast<object>().Select<object, object>(new Func<object, object>(new InternalXmlHelper.RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject));

The List<token> can not be null, how do I solve it?

    
asked by Perl 22.06.2016 в 23:25
source

1 answer

1

Let's start at the top ...

List<JToken>.Enumerator enumerator1;

It does not have a default value, so try the following:

List<JToken>.Enumerator enumerator1 = null;

Since you assign its value from a try block, the compiler understands that your variable does not really have a value and that it is being used when its instance equals null .

So it's the same with:

IEnumerator<JToken> enumerator2;

You define it without a value and assign it that value after you enter the block try , try the above (Assign null when defining it).

The finally block is executed regardless of whether the try block fails, try to leave a% empty% co (Personally: bad practice) but do not have the variable, since at the end of the loop, the GC will get rid of it.

  

Another error very often, is a new virtual member in a sealed class : To solve that, remove the word catch or virtual that you have in a class abstract

In addition and to finish, I leave this version of your code with the modifications that I have explained above:

private void offertoro_Load(object sender, EventArgs e)
{
    List<JToken> list = JObject.Parse(System.IO.File.ReadAllText("offerids_offertoro.json")).Children().ToList<JToken>();
    List<JToken>.Enumerator enumerator1 = null;
    try
    {
        enumerator1 = list.GetEnumerator();
        while (enumerator1.MoveNext())
        {
            JProperty source = (JProperty)enumerator1.Current;
            source.CreateReader();
            IEnumerator<JToken> enumerator2 = null;
            if (Operators.CompareString(source.Name, "offers", false) == 0)
            {
                try
                {
                    enumerator2 = source.Values().GetEnumerator();
                    while (enumerator2.MoveNext())
                        this.TextBox1.Text = this.TextBox1.Text + ((JObject)enumerator2.Current)["oid"].ToString() + "\r\n";
                }
                catch {}
            }
        }
    }
    catch {}

    this.WebBrowser2.Document.Cookie = "1";
    this.c_url = "1";
    this.finallink = "1";
    this.LabelProces.Text = this.LabelProces_OpeningOT;
    this.LabelCompleted.Text = this.LabelCompletedd;
    if (MyProject.Forms.Form4.GroupBoxSpeedAverage.Checked)
        this.CompleteOffer.Interval = 7000;
    else if (MyProject.Forms.Form4.GroupBoxSpeedSlow.Checked)
        this.CompleteOffer.Interval = 9000;
    else if (MyProject.Forms.Form4.GroupBoxSpeedFast.Checked)
        this.CompleteOffer.Interval = 5000;
    this.GetAvailableOffers.Start();
}

EDIT :

  

Finally: The name of type sealed does not exist in the type 'InternalXmlHelper' : The detail of the error says it clearly, you are calling created an instance of something that is not a member.

When you use keyword RemoveNamespaceAttributesClosure it is usually referred to a data type, such as new , string or object . I do not know the parameter that requires a new instance of the xml helper, but you must change only that fragment of code.

I hope it has helped you!

    
answered by 23.06.2016 в 02:35