Esempio n. 1
0
        static void GetMQEvent(Assembly assembly)
        {
            var types = assembly.GetTypes();

            foreach (var type in types)
            {
                if (!(type.GetInterfaces().Where(x => x == typeof(IMQEvent)).Count() > 0))
                {
                    continue;
                }
                var props = type.GetProperties();
                var hash  = new HashSet <int>();
                foreach (var p in props)
                {
                    var att = p.GetCustomAttribute <KeyIndex>();
                    if (att != null)
                    {
                        if (hash.Contains(att.Index))
                        {
                            throw new ArgumentException("repeat set KeyIndexAttribute index");
                        }
                        hash.Add(att.Index);
                        AddKeyIndex(type, new EventAttrMeta()
                        {
                            Index = att.Index, Property = FastInvoke.EmitGetter(p), Name = p.Name
                        });
                    }
                }
            }
        }
Esempio n. 2
0
        public static ConcurrentDictionary <string, Tuple <Func <object, object>, SetValueDelegate> > GetTypeGetterSetter(Type type)
        {
            ConcurrentDictionary <string, Tuple <Func <object, object>, SetValueDelegate> > value = null;

            if (!metas.ContainsKey(type))
            {
                lock (metas)
                {
                    if (metas.ContainsKey(type))
                    {
                        value = metas[type];
                    }
                    else
                    {
                        value = new ConcurrentDictionary <string, Tuple <Func <object, object>, SetValueDelegate> >();
                        metas.TryAdd(type, value);
                    }
                }
            }
            else
            {
                value = metas[type];
            }
            if (value.Count > 0)
            {
                return(value);
            }
            lock (value)
            {
                if (value.Count > 0)
                {
                    return(value);
                }
                type.GetProperties().ToList().ForEach(e =>
                {
                    var setter = FastInvoke.CreatePropertySetter(e);
                    var getter = FastInvoke.EmitGetter(e);
                    value.TryAdd(e.Name, new Tuple <Func <object, object>, SetValueDelegate>(getter, setter));
                });
            }
            return(value);
        }