Exemple #1
0
        public static imbHelpContent getHelpContent(this imbAttributeCollection attribs)
        {
            imbHelpContent output = new imbHelpContent();

            foreach (Object k in attribs.Keys)
            {
                if (k is imbAttributeName)
                {
                    imbAttribute att = attribs[k];

                    switch (att.nameEnum)
                    {
                    case imbAttributeName.menuCommandTitle:
                    case imbAttributeName.helpTitle:
                        output.title = att.getMessage().toStringSafe();
                        break;

                    case imbAttributeName.helpTips:
                        output.hints = att.msg.toStringSafe();
                        break;

                    case imbAttributeName.helpPurpose:
                        output.purpose = att.msg.toStringSafe();
                        break;

                    case imbAttributeName.menuHelp:
                    case imbAttributeName.helpDescription:
                        output.description = att.msg.toStringSafe();
                        break;
                    }
                }
            }

            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);
                    }
                }
            }
        }
Exemple #3
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);
        }
Exemple #4
0
        /// <summary>
        /// Prebacuje vrednost iz atributa u propertije - u skladu sa podesenim mapiranjem (imbAttributeName.metaValueFromAttribute)
        /// </summary>
        /// <param name="target">Objekat ciji se propertiji podesavaju</param>
        /// <param name="attribs">Atributi iz kojih izvlaci vrednost</param>
        /// <param name="onlyDeclared">Da li samo propertije target klase ili i nasledjene propertije</param>
        /// <param name="avoidOverWrite">Da li da preskoci ako Property vec ima vrednost</param>
        public static void imbAttributeToProperties(this Object target, imbAttributeCollection attribs,
                                                    Boolean onlyDeclared = false, Boolean avoidOverWrite = false)
        {
            if (target == null)
            {
                //  logSystem.log("Target object not supplied", logType.FatalError);
                return;
            }

            if (attribs == null)
            {
                //logSystem.log("Attributes to write values not supplied", logType.FatalError);
                return;
            }

            imbAttributeToPropertyMap map = getImbAttributeMap(target.GetType());

            map.writeToObject(target, attribs, onlyDeclared, avoidOverWrite);
        }
        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);
                    }
                }
            }
        }