Inheritance: UserdataVariable
        private UserdataVariable GetVariable(string name)
        {
            if (m_Variables.ContainsKey(name))
            {
                return(m_Variables[name]);
            }
            FieldInfo fInfo = m_Type.GetField(name);

            if (fInfo != null)
            {
                return(m_Variables[name] = new UserdataField(m_Script, fInfo));
            }
            PropertyInfo pInfo = m_Type.GetProperty(name, Script.BindingFlag);

            if (pInfo != null)
            {
                return(m_Variables[name] = new UserdataProperty(m_Script, pInfo));
            }
            EventInfo eInfo = m_Type.GetEvent(name);

            if (eInfo != null)
            {
                return(m_Variables[name] = new UserdataEvent(m_Script, eInfo));
            }
            return(null);
        }
        private UserdataVariable GetVariable(string name)
        {
            if (this.m_Variables.ContainsKey(name))
            {
                return(this.m_Variables[name]);
            }
            FieldInfo field = base.m_Type.GetTypeInfo().GetField(name);

            if (field != null)
            {
                UserdataVariable variable;
                this.m_Variables[name] = variable = new UserdataField(base.m_Script, field);
                return(variable);
            }
            PropertyInfo property = base.m_Type.GetTypeInfo().GetProperty(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);

            if (property != null)
            {
                UserdataVariable variable2;
                this.m_Variables[name] = variable2 = new UserdataProperty(base.m_Script, property);
                return(variable2);
            }
            EventInfo info = base.m_Type.GetTypeInfo().GetEvent(name);

            if (info != null)
            {
                UserdataVariable variable3;
                this.m_Variables[name] = variable3 = new UserdataEvent(base.m_Script, info);
                return(variable3);
            }
            return(null);
        }
        /// <summary> 设置一个类变量 </summary>
        public void SetValue(object obj, string name, ScriptObject value)
        {
            UserdataField field = GetField(name);

            if (field == null)
            {
                throw new ScriptException("SetValue Type[" + m_Type + "] 变量 [" + name + "] 不存在");
            }
            field.SetValue(obj, Util.ChangeType(value, field.FieldType));
        }
Beispiel #4
0
        /// <summary> 设置一个类变量 </summary>
        public void SetValue(object obj, string name, ScriptObject value)
        {
            UserdataField field = GetField(name);

            if (field == null)
            {
                throw new ExecutionException(m_Script, "SetValue Type[" + m_Type + "] 变量 [" + name + "] 不存在");
            }
            try {
                field.SetValue(obj, Util.ChangeType(m_Script, value, field.FieldType));
            } catch (System.Exception e) {
                throw new ExecutionException(m_Script, "SetValue 出错 源类型:" + (value == null || value.IsNull ? "null" : value.ObjectValue.GetType().Name) + " 目标类型:" + field.FieldType.Name + " : " + e.ToString());
            }
        }
Beispiel #5
0
        /// <summary> 设置一个类变量 </summary>
        public void SetValue(object obj, string name, ScriptObject value)
        {
            UserdataField field = GetField(name);

            if (field == null)
            {
                throw new ScriptException("SetValue Type[" + m_Type + "] 变量 [" + name + "] 不存在");
            }
            try {
                field.SetValue(obj, Util.ChangeType(value, field.FieldType));
            } catch (System.Exception) {
                throw new ScriptException("不能从源类型:" + (value == null || value.IsNull ? "null" : value.ObjectValue.GetType().Name) + " 转换成目标类型:" + field.FieldType.Name);
            }
        }
        //获取一个变量
        private UserdataVariable GetVariable(string name)
        {
            if (m_Variables.TryGetValue(name, out var value))
            {
                return(value);
            }
            FieldInfo fInfo = m_Type.GetField(name, Script.BindingFlag);

            if (fInfo != null)
            {
                return(m_Variables[name] = new UserdataField(fInfo));
            }
            PropertyInfo pInfo = m_Type.GetProperty(name, Script.BindingFlag);

            if (pInfo != null)
            {
                return(m_Variables[name] = new UserdataProperty(m_Type, pInfo));
            }
            //EventInfo eInfo = m_Type.GetTypeInfo().GetEvent(name, Script.BindingFlag);
            //if (eInfo != null) return m_Variables[name] = new UserdataEvent(m_Script, eInfo);
            return(null);
        }
Beispiel #7
0
        /// <summary> 获得一个类变量 </summary>
        public object GetValue(object obj, string name)
        {
            if (m_ScorpioMethods.ContainsKey(name))
            {
                return(m_ScorpioMethods[name]);
            }
            if (m_Functions.ContainsKey(name))
            {
                return(GetMethod(obj, name, m_Functions[name]));
            }
            if (m_NestedTypes.ContainsKey(name))
            {
                return(m_NestedTypes[name]);
            }
            UserdataField field = GetField(name);

            if (field != null)
            {
                return(field.GetValue(obj));
            }
            Type nestedType = m_Type.GetNestedType(name, Script.BindingFlag);

            if (nestedType != null)
            {
                ScriptUserdata ret = m_Script.CreateUserdata(nestedType);
                m_NestedTypes.Add(name, ret);
                return(ret);
            }
            UserdataMethod func = GetMethod(name);

            if (func != null)
            {
                return(GetMethod(obj, name, func));
            }
            throw new ExecutionException(m_Script, "GetValue Type[" + m_Type.ToString() + "] 变量 [" + name + "] 不存在");
        }
Beispiel #8
0
        private UserdataField GetField(string name)
        {
            if (m_FieldInfos.ContainsKey(name))
            {
                return(m_FieldInfos[name]);
            }
            FieldInfo fInfo = m_Type.GetField(name);

            if (fInfo != null)
            {
                UserdataField info = new UserdataField(fInfo);
                m_FieldInfos.Add(name, info);
                return(info);
            }
            PropertyInfo pInfo = m_Type.GetProperty(name, Script.BindingFlag);

            if (pInfo != null)
            {
                UserdataField info = new UserdataField(pInfo);
                m_FieldInfos.Add(name, info);
                return(info);
            }
            return(null);
        }
 private UserdataField GetField(string name)
 {
     if (m_FieldInfos.ContainsKey(name))
         return m_FieldInfos[name];
     FieldInfo fInfo = m_Type.GetField(name);
     if (fInfo != null) return m_FieldInfos[name] = new UserdataField(m_Script, fInfo);
     PropertyInfo pInfo = m_Type.GetProperty(name, Script.BindingFlag);
     if (pInfo != null) return m_FieldInfos[name] = new UserdataField(m_Script, pInfo);
     return null;
 }
 private UserdataVariable GetVariable(string name) {
     if (m_Variables.ContainsKey(name))
         return m_Variables[name];
     FieldInfo fInfo = m_Type.GetTypeInfo().GetField(name);
     if (fInfo != null) return m_Variables[name] = new UserdataField(m_Script, fInfo);
     PropertyInfo pInfo = m_Type.GetTypeInfo().GetProperty(name, Script.BindingFlag);
     if (pInfo != null) return m_Variables[name] = new UserdataProperty(m_Script, pInfo);
     EventInfo eInfo = m_Type.GetTypeInfo().GetEvent(name);
     if (eInfo != null) return m_Variables[name] = new UserdataEvent(m_Script, eInfo);
     return null;
 }