title: C#: How can I access the fields of an object from implicit operator overloading code?
body: <p>I have a class that holds a bool, int and float value (plus the selected type and a name). </p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  [System.Serializable]
  public class AnimXVariable {
  
          public string name = "variable";
          public enum VariableType { Bool, Int, Float };
          public VariableType type = VariableType.Bool;
  
          public bool boolVal = false;
          public int intVal = 0;
          public float floatVal = 0f;
  
          public AnimXVariable() {
                  type = VariableType.Bool;
          }
          public AnimXVariable(VariableType newType) {
                  type = newType;
          }
          public AnimXVariable(string newName, VariableType newType, bool val) {
                  name = newName;
                  type = newType;
                  boolVal = val;
          }
          public AnimXVariable(string newName, VariableType newType, float val) {
                  name = newName;
                  type = newType;
                  floatVal = val;
          }
          public AnimXVariable(string newName, VariableType newType, int val) {
                  name = newName;
                  type = newType;
                  intVal = val;
          }       
          public AnimXVariable(bool newValue) {
                  if(type == VariableType.Bool) boolVal = newValue;
          }
          public AnimXVariable(float newValue) {
                  if(type == VariableType.Float) floatVal = newValue;
          }
          public AnimXVariable(int newValue) {
                  if(type == VariableType.Int) intVal = newValue;
          }
  
          public static implicit operator AnimXVariable(bool val) {
                  return new AnimXVariable(name, type, val); //The problem is I can't access the non-static members. If I simply return new AnimXVariable(val); it does work, but the name is gone...
          }
  
  }
  </code></pre>
  
  <p>I'm trying to use an implicit operator to make the following work:</p>
  
  <pre><code>AnimXVariable b = new AnimXVariable("jump", VariableType.Bool, false);
  b = true;
  </code></pre>
  
  <p>The problem is I can't access the non-static members. If I simply do 
      return new AnimXVariable(val); 
  it does work, but the name is gone... Is there any way to get information about the object inside the implicit operator code to make this work?</p>