Exemplo n.º 1
0
        private void Init(Type serviceType)
        {
            _serviceContract = serviceType.GetCustomAttribute <ServiceContractAttribute>();
            if (_serviceContract == null)
            {
                throw new ArgumentException("serviceType not exists ServiceContractAttribute");
            }

            _kvListener  = new ConcurrentDictionary <Guid, IClientSessionListener>();
            _appListener = new AppListenerImpl();
            _appListener.Initialize();
        }
Exemplo n.º 2
0
        private void BuildTypeAttribute()
        {
            var srvAttType  = typeof(ServiceContractAttribute);
            var constructor = srvAttType.GetConstructor(Type.EmptyTypes);

            object[] atts = _targetType.GetCustomAttributes(srvAttType, false);
            CustomAttributeBuilder customeAttributeBuilder = null;

            if (atts.Length == 0)
            {
                customeAttributeBuilder = new CustomAttributeBuilder(constructor, new object[0]);
            }
            else
            {
                ServiceContractAttribute att = atts.Length == 0 ? null : atts[0] as ServiceContractAttribute;
                var      bindAttr            = BindingFlags.Instance | BindingFlags.Public;
                var      attFieldInfos       = srvAttType.GetFields(bindAttr);
                var      attPropertyInfos    = srvAttType.GetProperties(bindAttr).Where(p => p.CanWrite).ToArray();
                object[] attFieldValues      = new object[attFieldInfos.Length];
                object[] attPropertyValues   = new object[attPropertyInfos.Length];

                for (int i = 0; i < attFieldInfos.Length; i++)
                {
                    attFieldValues[i] = attFieldInfos[i].GetValue(att);
                }

                for (int i = 0; i < attPropertyInfos.Length; i++)
                {
                    attPropertyValues[i] = attPropertyInfos[i].GetValue(att, null);
                }

                customeAttributeBuilder = new CustomAttributeBuilder(constructor, new object[0],
                                                                     attPropertyInfos, attPropertyValues, attFieldInfos, attFieldValues);
            }
            _typeBuilder.SetCustomAttribute(customeAttributeBuilder);
        }