Пример #1
0
        void AddServiceBehaviors(string configurationName, bool throwIfNotFound)
        {
            if (configurationName == null)
            {
                return;
            }
            ServiceBehaviorElement behavior = ConfigUtil.BehaviorsSection.ServiceBehaviors [configurationName];

            if (behavior == null)
            {
                if (throwIfNotFound)
                {
                    throw new ArgumentException(String.Format("Service behavior configuration '{0}' was not found", configurationName));
                }
                return;
            }

            KeyedByTypeCollection <IServiceBehavior> behaviors = Description.Behaviors;

            foreach (var bxe in behavior)
            {
                IServiceBehavior b = (IServiceBehavior)bxe.CreateBehavior();
                if (behaviors.Contains(b.GetType()))
                {
                    continue;
                }
                behaviors.Add(b);
            }
        }
Пример #2
0
 public void AddBehaviorContractsToResolver(KeyedByTypeCollection <IServiceBehavior> behaviors)
 {
     if ((behaviors != null) && behaviors.Contains(typeof(ServiceMetadataBehavior)))
     {
         behaviors.Find <ServiceMetadataBehavior>().AddImplementedContracts(this);
     }
 }
Пример #3
0
            public static ItemModule AddModule(ItemTemplate template, Type type, KeyedByTypeCollection <ItemModule> keyedModules = null)
            {
                if (template == null || type == null)
                {
                    return(null);
                }
                if (keyedModules == null)
                {
                    keyedModules = new KeyedByTypeCollection <ItemModule>(template.modules.Where(x => x is not CommonModule));
                }
                if (!CommonModule.IsCommon(type) && keyedModules.Contains(type))
                {
                    return(null);
                }
                var attr = type.GetCustomAttribute <ItemModule.RequireAttribute>();

                if (attr != null)
                {
                    foreach (var m in attr.modules)
                    {
                        if (m != type)
                        {
                            AddModule(template, m, keyedModules);
                        }
                    }
                }
                ItemModule module = Activator.CreateInstance(type) as ItemModule;

                template.modules.Add(module);
                if (!CommonModule.IsCommon(type))
                {
                    keyedModules.Add(module);
                }
                return(module);
            }
Пример #4
0
 /// <summary>
 /// Returns a list of key value pairs. Key -> Enum Value; Value -> Attribute
 /// Example:
 /// <code>
 /// var attr = PickWaveHelpers.GetEnumMemberAttributes&lt;PickslipDimension, DisplayAttribute&gt;()[PickslipDimenstion.DcCancelDate];
 /// </code>
 /// </summary>
 /// <typeparam name="TEnum"></typeparam>
 /// <typeparam name="TAttr">Type of the attribute needed</typeparam>
 /// <returns></returns>
 public static IDictionary <TEnum, TAttr> GetEnumMemberAttributes <TEnum, TAttr>()
 {
     if (!__coll.Contains(typeof(Dictionary <TEnum, TAttr>)))
     {
         var query = from MemberInfo member in typeof(TEnum).GetMembers()
                     from TAttr attr in member.GetCustomAttributes(typeof(TAttr), false)
                     let dim = (TEnum)Enum.Parse(typeof(TEnum), member.Name)
                               select new KeyValuePair <TEnum, TAttr>(dim, attr);
         __coll.Add(query.ToDictionary(p => p.Key, p => p.Value));
     }
     return((IDictionary <TEnum, TAttr>)__coll[typeof(Dictionary <TEnum, TAttr>)]);
 }
Пример #5
0
        /// <summary>
        /// 在Behavior集合中查找指定类型的Behavior,如果没有,则创建一个。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="behaviors"></param>
        /// <returns></returns>
        public static T GetBehavior <T>(this KeyedByTypeCollection <IServiceBehavior> behaviors) where T : IServiceBehavior, new()
        {
            T behavior = default(T);

            if (behaviors.Contains(typeof(T)))
            {
                behavior = (T)behaviors[typeof(T)];
            }
            else
            {
                behavior = new T();
                behaviors.Add(behavior);
            }

            return(behavior);
        }
Пример #6
0
 protected static IDictionary <T, DisplayAttribute> GetEnumDisplayAttributes <T>()
 {
     if (__listEnumMeta == null)
     {
         __listEnumMeta = new KeyedByTypeCollection <object>();
     }
     if (!__listEnumMeta.Contains(typeof(Dictionary <T, DisplayAttribute>)))
     {
         IDictionary <T, DisplayAttribute> query = (from T item in Enum.GetValues(typeof(T))
                                                    select new
         {
             Value = item.GetType().GetMember(item.ToString())
                     .Cast <MemberInfo>().Single().GetCustomAttributes(typeof(DisplayAttribute), false)
                     .Cast <DisplayAttribute>()
                     .SingleOrDefault(),
             Key = item
         }).Where(p => p.Value != null).ToDictionary(p => p.Key, p => p.Value);
         __listEnumMeta.Add(query);
     }
     return((IDictionary <T, DisplayAttribute>)__listEnumMeta[typeof(Dictionary <T, DisplayAttribute>)]);
 }
Пример #7
0
 public bool Contains(TServiceModelExtensionElement element)
 {
     return(_list.Contains(element));
 }