Exemple #1
0
        public FieldGetterSetter GenGetterSetter(string propName)
        {
            FieldGetterSetter objField = null;

            {
                var v = this.GetType().GetProperty(propName);
                if (v != null)
                {
                    objField = new FieldGetterSetter()
                    {
                        funcGetter = (string name) =>
                        {
                            return(v.GetValue(this, null));
                        },
                        funcSetter = (string name, object newv) =>
                        {
                            v.SetValue(this, newv);
                        }
                    };
                    m_dictName2Func[propName] = objField;
                    return(objField);
                }
            }
            {
                var v = this.GetType().GetField(propName);
                if (v != null)
                {
                    objField = new FieldGetterSetter()
                    {
                        funcGetter = (string name) =>
                        {
                            return(v.GetValue(this));
                        },
                        funcSetter = (string name, object newv) =>
                        {
                            v.SetValue(this, newv);
                        }
                    };
                    m_dictName2Func[propName] = objField;
                    return(objField);
                }
            }
            objField = GenVarGetterSetter(propName);
            if (objField != null)
            {
                m_dictName2Func[propName] = objField;
                return(objField);
            }
            return(objField);
        }
Exemple #2
0
        public object GetFieldObject(string propName)
        {
            FieldGetterSetter objField = null;

            if (!m_dictName2Func.ContainsKey(propName))
            {
                objField = GenGetterSetter(propName);
                if (objField == null)
                {
                    return(null);
                }
            }
            else
            {
                objField = m_dictName2Func[propName];
            }
            return(objField.funcGetter(propName));
        }
Exemple #3
0
        public Entity SetField(string propName, object newv)
        {
            FieldGetterSetter objField = null;

            if (!m_dictName2Func.ContainsKey(propName))
            {
                objField = GenGetterSetter(propName);
                if (objField == null)
                {
                    return(null);
                }
            }
            else
            {
                objField = m_dictName2Func[propName];
            }

            objField.funcSetter(propName, newv);
            return(this);
        }
Exemple #4
0
        public FieldGetterSetter GenVarGetterSetter(string propName)
        {
            FieldGetterSetter objField = null;
            var cfg = VarTypeCfg.Instance().GetCfgByKey(propName);

            if (cfg == null)
            {
                return(objField);
            }
            int nId = cfg.nID;

            if (cfg.nType == (int)EVarType.VarInt)
            {
                objField = new FieldGetterSetter()
                {
                    funcGetter = (string name) =>
                    {
                        if (m_varData.IntData.ContainsKey(nId))
                        {
                            return(m_varData.IntData[nId]);
                        }
                        return(null);
                    },
                    funcSetter = (string name, object newv) =>
                    {
                        m_varData.IntData[nId] = Convert.ToInt64(newv);
                    }
                };
            }
            else if (cfg.nType == (int)EVarType.VarInt)
            {
                objField = new FieldGetterSetter()
                {
                    funcGetter = (string name) =>
                    {
                        if (m_varData.StrData.ContainsKey(nId))
                        {
                            return(m_varData.StrData[nId]);
                        }
                        return(null);
                    },
                    funcSetter = (string name, object newv) =>
                    {
                        m_varData.StrData[nId] = (string)newv;
                    }
                };
            }
            else if (cfg.nType == (int)EVarType.VarMap)
            {
                objField = new FieldGetterSetter()
                {
                    funcGetter = (string name) =>
                    {
                        if (m_varData.MapData.ContainsKey(nId))
                        {
                            return(m_varData.MapData[nId]);
                        }
                        return(null);
                    },
                    funcSetter = (string name, object newv) =>
                    {
                        m_varData.MapData[nId] = (Dictionary <int, long>)newv;
                    }
                };
            }
            return(objField);
        }