Пример #1
0
        /// <summary>
        /// GLAVNI attribute dictionary konstruktor - koristiti ga sto vise
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static imbAttributeCollection getImbAttributeDictionary(this MemberInfo input, Boolean allowOverWrite,
                                                                       Boolean includeInheritedForType = false,
                                                                       Boolean forceNewCollection      = false)
        {
            imbAttributeCollection output = new imbAttributeCollection();

            try
            {
                if (imbAttributeProfileEngine.attributeCollectionByMemberInfo.ContainsKey(input) && !forceNewCollection)
                {
                    //if (logNotificationsHere)
                    //    logSystem.log("Attribute collection for :: " + input.Name + " found in cache",
                    //                  logType.Notification);
                    return(imbAttributeProfileEngine.attributeCollectionByMemberInfo[input]);
                }

                if (input is Type)
                {
                    Type        inputType = input as Type;
                    List <Type> bl        = inputType.GetBaseTypeList(true, true);
                    bl.Reverse();
                    foreach (Type b in bl)
                    {
                        List <imbAttribute> tl = b.getAttributes <imbAttribute>(includeInheritedForType);
                        foreach (imbAttribute tli in tl)
                        {
                            if (!output.ContainsKey(tli.nameEnum) || allowOverWrite)
                            {
                                output.Add(tli.nameEnum, tli);
                                if (b == inputType)
                                {
                                    output.selfDeclaredAttributes.Add(tli.nameEnum, tli);
                                }
                            }
                        }
                    }
                }
                else
                {
                    List <imbAttribute> attributes = input.getAttributes <imbAttribute>(true);
                    foreach (imbAttribute at in attributes)
                    {
                        if (!output.ContainsKey(at.nameEnum) || allowOverWrite)
                        {
                            output.Add(at.nameEnum, at);
                        }
                    }
                }
                if (!forceNewCollection)
                {
                    imbAttributeProfileEngine.attributeCollectionByMemberInfo.Add(input, output);
                }
            }
            catch (Exception ex)
            {
                //devNoteManager.note("GRESNA U STVARANU ATRIBUTA", ex, devNoteType.addAttributes);
            }
            return(output);
        }
        public void writeToObject(Object target, imbAttributeCollection attributes, Boolean onlyDeclared = false,
                                  Boolean avoidOverwrite = false)
        {
            foreach (KeyValuePair <PropertyInfo, imbAttributeName> pair in this)
            {
                Boolean go = true;
                if (avoidOverwrite)
                {
                    if (pair.Key.GetValue(target, null) != null)
                    {
                        go = false;
                    }
                }
                if (onlyDeclared)
                {
                    go = (pair.Key.DeclaringType == targetType);
                }

                if (go)
                {
                    if (attributes.ContainsKey(pair.Value))
                    {
                        target.imbSetPropertyConvertSafe(pair.Key, attributes[pair.Value].getMessage());
                        //pair.Key.SetValue(target, attributes[pair.Value].getMessage(), null);
                    }
                }
            }
        }
        public imbAttributeToPropertyMap(Type __targetType)
        {
            PropertyInfo[] pi = new PropertyInfo[] { };
            targetType = __targetType;

            pi = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo p in pi)
            {
                if (p.CanWrite)
                {
                    imbAttributeCollection attributes = imbAttributeTools.getImbAttributeDictionary(p);
                    if (attributes.ContainsKey(imbAttributeName.metaValueFromAttribute))
                    {
                        imbAttribute att = attributes[imbAttributeName.metaValueFromAttribute];
                        Add(p, (imbAttributeName)att.objMsg);
                    }
                }
            }
        }