Пример #1
0
        private static bool TryGetOpCode(short code, out OpCode opCode)
        {
            if (_opCodes != null)
            {
                return(_opCodes.TryGetValue(code, out opCode));
            }
            var dict = new SafeDictionary <short, OpCode>();

            foreach (var fi in typeof(OpCodes).GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                if (!typeof(OpCode).IsAssignableFrom(fi.FieldType))
                {
                    continue;
                }
                var innerOpCode = (OpCode)fi.GetValue(null);
                if (innerOpCode.OpCodeType != OpCodeType.Nternal)
                {
                    dict.Add(innerOpCode.Value, innerOpCode);
                }
            }
            _opCodes = dict;
            return(_opCodes.TryGetValue(code, out opCode));
        }
Пример #2
0
        internal Type GetTypeFromCache(string typename)
        {
            Type val = null;

            if (_typecache.TryGetValue(typename, out val))
            {
                return(val);
            }
            else
            {
                Type t = Type.GetType(typename);
                if (t == null) // RaptorDB : loading runtime assemblies
                {
#if net4
                    t = Type.GetType(typename, (name) => {
                        return(AppDomain.CurrentDomain.GetAssemblies().Where(z => z.FullName == name.FullName).FirstOrDefault());
                    }, null, true);
#endif
                }
                _typecache.Add(typename, t);
                return(t);
            }
        }
Пример #3
0
        internal Getters[] GetGetters(Type type, bool ShowReadOnlyProperties, List <Type> IgnoreAttributes)
        {
            Getters[] val = null;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }
            //bool isAnonymous = IsAnonymousType(type);

            var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;

            //if (ShowReadOnlyProperties)
            //    bf |= BindingFlags.NonPublic;
            PropertyInfo[] props   = type.GetProperties(bf);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                if (p.GetIndexParameters().Length > 0)
                {// Property is an indexer
                    continue;
                }
                if (!p.CanWrite && (ShowReadOnlyProperties == false))//|| isAnonymous == false))
                {
                    continue;
                }
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                string mName = null;
                #if net4
                var att = p.GetCustomAttributes(true);
                foreach (var at in att)
                {
                    if (at is DataMemberAttribute)
                    {
                        var dm = (DataMemberAttribute)at;
                        if (dm.Name != "")
                        {
                            mName = dm.Name;
                        }
                    }
                }
                #endif
                GenericGetter g = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name, lcName = p.Name.ToLower(), memberName = mName, member = p
                    });
                }
            }

            FieldInfo[] fi = type.GetFields(bf);
            foreach (var f in fi)
            {
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                string mName = null;
#if net4
                var att = f.GetCustomAttributes(true);
                foreach (var at in att)
                {
                    if (at is DataMemberAttribute)
                    {
                        var dm = (DataMemberAttribute)at;
                        if (dm.Name != "")
                        {
                            mName = dm.Name;
                        }
                    }
                }
#endif
                if (f.IsLiteral == false)
                {
                    GenericGetter g = CreateGetField(type, f);
                    if (g != null)
                    {
                        getters.Add(new Getters {
                            Getter = g, Name = f.Name, lcName = f.Name.ToLower(), memberName = mName, member = f
                        });
                    }
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
Пример #4
0
        public Dictionary <string, myPropInfo> Getproperties(Type type, string typename)
        {
            Dictionary <string, myPropInfo> sd = null;

            if (_propertycache.TryGetValue(typename, out sd))
            {
                return(sd);
            }
            else
            {
                sd = new Dictionary <string, myPropInfo>();
                var            bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
                PropertyInfo[] pr = type.GetProperties(bf);
                foreach (PropertyInfo p in pr)
                {
                    if (p.GetIndexParameters().Length > 0)// Property is an indexer
                    {
                        continue;
                    }

                    myPropInfo d = CreateMyProp(p.PropertyType, p.Name);
                    d.setter = Reflection.CreateSetMethod(type, p);
                    if (d.setter != null)
                    {
                        d.CanWrite = true;
                    }
                    d.getter = Reflection.CreateGetMethod(type, p);
#if net4
                    var att = p.GetCustomAttributes(true);
                    foreach (var at in att)
                    {
                        if (at is DataMemberAttribute)
                        {
                            var dm = (DataMemberAttribute)at;
                            if (dm.Name != "")
                            {
                                d.memberName = dm.Name;
                            }
                        }
                    }
                    if (d.memberName != null)
                    {
                        sd.Add(d.memberName, d);
                    }
                    else
#endif
                    sd.Add(p.Name.ToLower(), d);
                }
                FieldInfo[] fi = type.GetFields(bf);
                foreach (FieldInfo f in fi)
                {
                    myPropInfo d = CreateMyProp(f.FieldType, f.Name);
                    if (f.IsLiteral == false)
                    {
                        d.setter = Reflection.CreateSetField(type, f);
                        if (d.setter != null)
                        {
                            d.CanWrite = true;
                        }
                        d.getter = Reflection.CreateGetField(type, f);
#if net4
                        var att = f.GetCustomAttributes(true);
                        foreach (var at in att)
                        {
                            if (at is DataMemberAttribute)
                            {
                                var dm = (DataMemberAttribute)at;
                                if (dm.Name != "")
                                {
                                    d.memberName = dm.Name;
                                }
                            }
                        }
                        if (d.memberName != null)
                        {
                            sd.Add(d.memberName, d);
                        }
                        else
#endif
                        sd.Add(f.Name.ToLower(), d);
                    }
                }

                _propertycache.Add(typename, sd);
                return(sd);
            }
        }
Пример #5
0
        public Getters[] GetGetters(Type type, bool ShowReadOnlyProperties, List <Type> IgnoreAttributes)//   JSONParameters param)
        {
            Getters[] val = null;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            PropertyInfo[] props   = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                if (p.GetIndexParameters().Length > 0)
                {// Property is an indexer
                    continue;
                }
                if (!p.CanWrite && ShowReadOnlyProperties == false)
                {
                    continue;
                }
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                GenericGetter g = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name, lcName = p.Name.ToLower()
                    });
                }
            }

            FieldInfo[] fi = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static);
            foreach (var f in fi)
            {
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                if (f.IsLiteral == false)
                {
                    GenericGetter g = CreateGetField(type, f);
                    if (g != null)
                    {
                        getters.Add(new Getters {
                            Getter = g, Name = f.Name, lcName = f.Name.ToLower()
                        });
                    }
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
Пример #6
0
        private void BuildLookup(Type objtype)
        {
            // build lookup
            if (objtype == null)
            {
                return;
            }

            if (objtype == typeof(NameValueCollection) || objtype == typeof(StringDictionary))
            {
                return;
            }

            //if (objtype == typeof(DataSet) || objtype == typeof(DataTable))
            //    return;

            if (typeof(IDictionary).IsAssignableFrom(objtype))
            {
                return;
            }

            if (_seen.TryGetValue(objtype, out bool _))
            {
                return;
            }

            if (objtype.IsGenericType)
            {
                BuildGenericTypeLookup(objtype);
            }

            else if (objtype.IsArray)
            {
                Type t = objtype;
                BuildArrayTypeLookup(objtype);
            }
            else
            {
                _seen.Add(objtype, true);

                foreach (var m in Reflection.Instance.Getproperties(objtype, objtype.FullName, true))
                {
                    Type t = m.Value.pt;

                    _lookup.Add(m.Key, true);

                    if (t.IsArray)
                    {
                        BuildArrayTypeLookup(t);
                    }

                    if (t.IsGenericType)
                    {
                        // skip if dictionary
                        if (typeof(IDictionary).IsAssignableFrom(t))
                        {
                            _parseJsonType = false;
                            return;
                        }
                        BuildGenericTypeLookup(t);
                    }
                    if (t.FullName.IndexOf("System.") == -1)
                    {
                        BuildLookup(t);
                    }
                }
            }
        }
Пример #7
0
        internal Getters[] GetGetters(Type type, bool showReadOnlyProperties, List <Type> ignoreAttributes)
        {
            Getters[] val;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            //bool isAnonymous = IsAnonymousType(type);

            //if (ShowReadOnlyProperties)
            //    bf |= BindingFlags.NonPublic;
            var props   = type.GetProperties(Bf);
            var getters = new List <Getters>();

            foreach (var p in props)
            {
                if (p.GetIndexParameters().Length > 0)
                {// Property is an indexer
                    continue;
                }
                if (!p.CanWrite && (showReadOnlyProperties == false))//|| isAnonymous == false))
                {
                    continue;
                }
                if (ignoreAttributes != null)
                {
                    var found = false;
                    foreach (var ignoreAttr in ignoreAttributes)
                    {
                        if (!p.IsDefined(ignoreAttr, false))
                        {
                            continue;
                        }

                        found = true;
                        break;
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                var g = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name, LcName = p.Name.ToLower()
                    });
                }
            }

            var fi = type.GetFields(Bf);

            foreach (var f in fi)
            {
                if (ignoreAttributes != null)
                {
                    var found = false;
                    foreach (var ignoreAttr in ignoreAttributes)
                    {
                        if (!f.IsDefined(ignoreAttr, false))
                        {
                            continue;
                        }

                        found = true;
                        break;
                    }
                    if (found)
                    {
                        continue;
                    }
                }

                if (f.IsLiteral)
                {
                    continue;
                }

                var g = CreateGetField(type, f);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = f.Name, LcName = f.Name.ToLower()
                    });
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
Пример #8
0
        public Getters[] GetGetters(Type type, /*bool ShowReadOnlyProperties,*/ List <Type> IgnoreAttributes)
        {
            Getters[] val = null;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;

            //if (ShowReadOnlyProperties)
            //    bf |= BindingFlags.NonPublic;
            PropertyInfo[] props   = type.GetProperties(bf);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                bool read_only = false;
                if (p.GetIndexParameters().Length > 0)
                {// Property is an indexer
                    continue;
                }
                if (!p.CanWrite)      // && (ShowReadOnlyProperties == false))//|| isAnonymous == false))
                {
                    read_only = true; //continue;
                }
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                string mName = null;
                var    att   = p.GetCustomAttributes(true);
                foreach (var at in att)
                {
#if NET4
                    if (at is System.Runtime.Serialization.DataMemberAttribute)
                    {
                        var dm = (System.Runtime.Serialization.DataMemberAttribute)at;
                        if (dm.Name != "")
                        {
                            mName = dm.Name;
                        }
                    }
#endif
                    if (at is fastJSON.DataMemberAttribute)
                    {
                        var dm = (fastJSON.DataMemberAttribute)at;
                        if (dm.Name != "")
                        {
                            mName = dm.Name;
                        }
                    }
                }
                GenericGetter g = (object obj) => { return(p.GetValue(obj)); };
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name, lcName = p.Name.ToLowerInvariant(), memberName = mName, ReadOnly = read_only
                    });
                }
            }

            FieldInfo[] fi = type.GetFields(bf);
            foreach (var f in fi)
            {
                bool read_only = false;
                if (f.IsInitOnly)     // && (ShowReadOnlyProperties == false))//|| isAnonymous == false))
                {
                    read_only = true; //continue;
                }
                if (IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                string mName = null;
                var    att   = f.GetCustomAttributes(true);
                foreach (var at in att)
                {
#if NET4
                    if (at is System.Runtime.Serialization.DataMemberAttribute)
                    {
                        var dm = (System.Runtime.Serialization.DataMemberAttribute)at;
                        if (dm.Name != "")
                        {
                            mName = dm.Name;
                        }
                    }
#endif
                    if (at is fastJSON.DataMemberAttribute)
                    {
                        var dm = (fastJSON.DataMemberAttribute)at;
                        if (dm.Name != "")
                        {
                            mName = dm.Name;
                        }
                    }
                }
                if (f.IsLiteral == false)
                {
                    GenericGetter g = CreateGetField(type, f);
                    if (g != null)
                    {
                        getters.Add(new Getters {
                            Getter = g, Name = f.Name, lcName = f.Name.ToLowerInvariant(), memberName = mName, ReadOnly = read_only
                        });
                    }
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
Пример #9
0
        public Dictionary <string, myPropInfo> Getproperties(Type type, string typename, bool ShowReadOnlyProperties)
        {
            Dictionary <string, myPropInfo> sd = null;

            if (_propertycache.TryGetValue(typename, out sd))
            {
                return(sd);
            }
            else
            {
                sd = new Dictionary <string, myPropInfo>(10);
                var            bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
                PropertyInfo[] pr = type.GetProperties(bf);
                foreach (PropertyInfo p in pr)
                {
                    if (p.GetIndexParameters().Length > 0)// Property is an indexer
                    {
                        continue;
                    }

                    myPropInfo d = CreateMyProp(p.PropertyType, p.Name);

                    d.CanWrite = p.CanWrite;
                    if (p.CanWrite)
                    {
                        d.setter = (object target, object value) => { p.SetValue(target, value); return(target); }
                    }
                    ;

                    d.getter = (object obj) => { return(p.GetValue(obj)); };

                    var att = p.GetCustomAttributes(true);
                    foreach (var at in att)
                    {
#if NET4
                        if (at is System.Runtime.Serialization.DataMemberAttribute)
                        {
                            var dm = (System.Runtime.Serialization.DataMemberAttribute)at;
                            if (dm.Name != "")
                            {
                                d.memberName = dm.Name;
                            }
                        }
#endif
                        if (at is fastJSON.DataMemberAttribute)
                        {
                            var dm = (fastJSON.DataMemberAttribute)at;
                            if (dm.Name != "")
                            {
                                d.memberName = dm.Name;
                            }
                        }
                    }
                    if (d.memberName != null)
                    {
                        sd.Add(d.memberName, d);
                    }
                    else
                    {
                        sd.Add(p.Name.ToLowerInvariant(), d);
                    }
                }
                FieldInfo[] fi = type.GetFields(bf);
                foreach (FieldInfo f in fi)
                {
                    myPropInfo d = CreateMyProp(f.FieldType, f.Name);
                    if (f.IsLiteral == false)
                    {
                        if (f.IsInitOnly == false)
                        {
                            d.setter = (object target, object value) => { f.SetValue(target, value); return(target); }
                        }
                        ;                                                                                              //Reflection.CreateSetField(type, f);
                        if (d.setter != null)
                        {
                            d.CanWrite = true;
                        }

                        d.getter = (object obj) => { return(f.GetValue(obj)); };

                        var att = f.GetCustomAttributes(true);
                        foreach (var at in att)
                        {
#if NET4
                            if (at is System.Runtime.Serialization.DataMemberAttribute)
                            {
                                var dm = (System.Runtime.Serialization.DataMemberAttribute)at;
                                if (dm.Name != "")
                                {
                                    d.memberName = dm.Name;
                                }
                            }
#endif
                            if (at is fastJSON.DataMemberAttribute)
                            {
                                var dm = (fastJSON.DataMemberAttribute)at;
                                if (dm.Name != "")
                                {
                                    d.memberName = dm.Name;
                                }
                            }
                        }
                        if (d.memberName != null)
                        {
                            sd.Add(d.memberName, d);
                        }
                        else
                        {
                            sd.Add(f.Name.ToLowerInvariant(), d);
                        }
                    }
                }

                _propertycache.Add(typename, sd);
                return(sd);
            }
        }
Пример #10
0
 private void initTypeCache()
 {
     _typecache.Add("GOEngine.Implement.GOEActActivePosSceneEffect", typeof(GOEActActivePosSceneEffect));
     _typecache.Add("GOEngine.Implement.GOEActActorChangeShader", typeof(GOEActActorChangeShader));
     _typecache.Add("GOEngine.Implement.GOEActActorEffect", typeof(GOEActActorEffect));
     _typecache.Add("GOEngine.Implement.GOEActActorVisible", typeof(GOEActActorVisible));
     _typecache.Add("GOEngine.Implement.GOEActAnimation", typeof(GOEActAnimation));
     _typecache.Add("GOEngine.Implement.GOEActAttachVisible", typeof(GOEActAttachVisible));
     _typecache.Add("GOEngine.Implement.GOEActCameraCurve", typeof(GOEActCameraCurve));
     _typecache.Add("GOEngine.Implement.GOEActCameraShake", typeof(GOEActCameraShake));
     _typecache.Add("GOEngine.Implement.GOEActComponent", typeof(GOEActComponent));
     _typecache.Add("GOEngine.Implement.GOEActEffectRandomDirToTarget", typeof(GOEActEffectRandomDirToTarget));
     _typecache.Add("GOEngine.Implement.GOEActEffectToPos", typeof(GOEActEffectToPos));
     _typecache.Add("GOEngine.Implement.GOEActEffectToTarget", typeof(GOEActEffectToTarget));
     _typecache.Add("GOEngine.Implement.GOEActEvent", typeof(GOEActEvent));
     _typecache.Add("GOEngine.Implement.GOEActParaCurve", typeof(GOEActParaCurve));
     _typecache.Add("GOEngine.Implement.GOEActSceneEffect", typeof(GOEActSceneEffect));
     _typecache.Add("GOEngine.Implement.GOEActSound", typeof(GOEActSound));
     _typecache.Add("GOEngine.Implement.GOEActTurnToTarget", typeof(GOEActTurnToTarget));
     _typecache.Add("GOEngine.Implement.GOEEntityAct", typeof(GOEEntityAct));
     _typecache.Add("GOEngine.Implement.GOEActAttachTarget", typeof(GOEActAttachTarget));
     _typecache.Add("GOEngine.Implement.GOEActMoveTargetToPos", typeof(GOEActMoveTargetToPos));
 }
Пример #11
0
        internal Getters[] GetGetters(Type type, JSONParameters param)
        {
            Getters[] val = null;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            PropertyInfo[] props   = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <Getters> getters = new List <Getters>();

            foreach (PropertyInfo p in props)
            {
                if (!p.CanWrite && param.ShowReadOnlyProperties == false)
                {
                    continue;
                }
                if (param.IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in param.IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                GenericGetter g = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name
                    });
                }
            }

            FieldInfo[] fi = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (var f in fi)
            {
                if (param.IgnoreAttributes != null)
                {
                    bool found = false;
                    foreach (var ignoreAttr in param.IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }

                GenericGetter g = CreateGetField(type, f);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = f.Name
                    });
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
Пример #12
0
        public Getters[] GetGetters(Type type, bool ShowReadOnlyProperties, List <Type> IgnoreAttributes)
        {
            Getters[] val = null;
            if (_getterscache.TryGetValue(type, out val))
            {
                return(val);
            }

            var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
            //if (ShowReadOnlyProperties)
            //    bf |= BindingFlags.NonPublic;
            var props   = type.GetProperties(bf);
            var getters = new List <Getters>();

            foreach (var p in props)
            {
                if (p.GetIndexParameters().Length > 0)
                {                // Property is an indexer
                    continue;
                }
                if (!p.CanWrite && (ShowReadOnlyProperties == false))                //|| isAnonymous == false))
                {
                    continue;
                }
                if (IgnoreAttributes != null)
                {
                    var found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (p.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                string mName = null;
                var    g     = CreateGetMethod(type, p);
                if (g != null)
                {
                    getters.Add(new Getters {
                        Getter = g, Name = p.Name, lcName = p.Name.ToLowerInvariant(), memberName = mName
                    });
                }
            }

            var fi = type.GetFields(bf);

            foreach (var f in fi)
            {
                if (IgnoreAttributes != null)
                {
                    var found = false;
                    foreach (var ignoreAttr in IgnoreAttributes)
                    {
                        if (f.IsDefined(ignoreAttr, false))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }
                string mName = null;
                if (f.IsLiteral == false)
                {
                    var g = CreateGetField(type, f);
                    if (g != null)
                    {
                        getters.Add(new Getters {
                            Getter = g, Name = f.Name, lcName = f.Name.ToLowerInvariant(), memberName = mName
                        });
                    }
                }
            }
            val = getters.ToArray();
            _getterscache.Add(type, val);
            return(val);
        }
Пример #13
0
        public Dictionary <string, myPropInfo> Getproperties(Type type, string typename, bool customType)
        {
            Dictionary <string, myPropInfo> sd = null;

            if (_propertycache.TryGetValue(typename, out sd))
            {
                return(sd);
            }
            else
            {
                sd = new Dictionary <string, myPropInfo>();
                PropertyInfo[] pr = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
                foreach (PropertyInfo p in pr)
                {
                    bool pass = false;
                    foreach (var attrtype in JSON.Parameters.IgnoreAttributes)
                    {
                        if (p.IsDefined(attrtype, true))
                        {
                            pass = true;
                            break;
                        }
                    }

                    if (pass)
                    {
                        continue;
                    }

                    if (p.GetIndexParameters().Length > 0)
                    {// Property is an indexer
                        continue;
                    }
                    myPropInfo d = CreateMyProp(p.PropertyType, p.Name, customType);

                    d.setter = Reflection.CreateSetMethod(type, p);
                    if (d.setter != null && p.CanWrite)
                    {
                        d.CanWrite = true;
                    }
                    d.getter = Reflection.CreateGetMethod(type, p);
                    sd.Add(p.Name.ToLower(), d);
                }
                FieldInfo[] fi = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
                foreach (FieldInfo f in fi)
                {
                    myPropInfo d = CreateMyProp(f.FieldType, f.Name, customType);
                    if (f.IsLiteral == false)
                    {
                        d.setter = Reflection.CreateSetField(type, f);
                        if (d.setter != null)
                        {
                            d.CanWrite = true;
                        }
                        d.getter = Reflection.CreateGetField(type, f);
                        sd.Add(f.Name.ToLower(), d);
                    }
                }

                _propertycache.Add(typename, sd);
                return(sd);
            }
        }