예제 #1
0
        public void SetFieldValue(string name, object obj, string field, string value)
        {
            string    realField = GetFieldRealName(name, obj, field);
            FieldInfo fi        = ReflectionCache.GetField(obj, realField);

            try
            {
                fi.SetValue(obj, ReflectionCache.GetValue(fi, value));
            }
            catch (Exception e)
            {
                Debug.LogError(obj.GetType().Name + "'s field '" + realField + " ' can not be set value '" + value + "'");
            }
        }
예제 #2
0
        public void SetField(string parentName, object parent, object child, string field)
        {
            string realField = GetFieldRealName(parentName, parent, field);

            try
            {
                FieldInfo fi = ReflectionCache.GetField(parent, realField);
                if (fi.FieldType.Name != "IList")
                {
                    fi.SetValue(parent, child);
                }
                else
                {
                    throw new RuntimeException();
                }
            }
            catch (Exception)
            {
                foreach (string f in ReflectionCache.GetFieldNames(parent))
                {
                    FieldInfo fi = ReflectionCache.GetField(parent, f);
                    if (fi.FieldType.Name == "IList`1" || fi.FieldType.Name == "List`1")
                    {
                        Type t = fi.FieldType.GetGenericArguments()[0];
                        if (t.IsAssignableFrom(child.GetType()))
                        {
                            if (fi.GetValue(parent) == null)
                            {
                                fi.SetValue(parent, MakeList(t, child));
                            }
                            else
                            {
                                System.Collections.IList ilist = fi.GetValue(parent) as System.Collections.IList;
                                ilist.Add(child);
                            }

                            break;
                        }
                    }
                }
            }
        }
예제 #3
0
        // 会把父类的字段也会加入,需要注意当以前的代码中父类的字段没有按照这样的命名规范时会有问题
        private static void aliasOne(XmlAlias alias, IRule obj)
        {
            string classAlias = ToXmlName(obj.GetType().Name);

            alias.AddClass(classAlias, obj);

            string[] fields = ReflectionCache.GetFieldNames(obj);
            foreach (string field in fields)
            {
                FieldInfo fi   = ReflectionCache.GetField(obj, field);
                string    type = fi.FieldType.Name.ToLower();
                if (ReflectionCache.IsSimpleField(type))
                {
                    alias.AddAttribue(classAlias, fi.Name, ToXmlName(fi.Name));
                }
                else
                {
                    alias.AddField(classAlias, fi.Name, ToXmlName(fi.Name));
                }
            }
        }
예제 #4
0
 public virtual IPara Get(string field)
 {
     return(new FieldPara(obj, field, ReflectionCache.GetField(obj, field)));
 }