Ejemplo n.º 1
0
 public Tag(object myRuntimeObject, Chummer.HubTagAttribute hubTag)
 {
     Id = Guid.NewGuid();
     MyRuntimeObject = myRuntimeObject;
     MyRuntimeHubTag = hubTag;
     Tags            = new List <Tag>();
 }
Ejemplo n.º 2
0
        internal static IList <Tag> ExtractTagsFromAttributesForProperty(Tuple <PropertyInfo, Chummer.HubTagAttribute, Object> prop, Tag parenttag)
        {
            List <Tag> proptaglist = new List <Tag>();

            Chummer.HubTagAttribute attribute = prop.Item2 as Chummer.HubTagAttribute;
            Object       propValue;
            PropertyInfo property = prop.Item1 as PropertyInfo;

            if (property == null)
            {
                propValue = prop.Item3;
            }
            else
            {
                propValue = property.GetValue(prop.Item3);
                if (propValue.GetType().IsAssignableFrom(typeof(bool)))
                {
                    if (propValue as bool? == false)
                    { //dont save "false" values
                        return(proptaglist);
                    }
                }
                if (propValue.GetType().IsAssignableFrom(typeof(int)))
                {
                    if (propValue as int? == 0)
                    {   //dont save "0" values
                        return(proptaglist);
                    }
                }
            }


            var tag = new Tag(propValue, attribute);

            tag.SiNnerId    = parenttag?.SiNnerId;
            tag.Tags        = new List <Tag>();
            tag.MyParentTag = parenttag;
            if (tag.MyParentTag != null)
            {
                tag.MyParentTag.Tags.Add(tag);
            }
            tag.ParentTagId = parenttag?.Id;
            tag.Id          = Guid.NewGuid();
            if (!String.IsNullOrEmpty(attribute.TagName))
            {
                tag.TagName = attribute.TagName;
            }
            else if (prop.Item1 != null)
            {
                tag.TagName = prop.Item1.Name;
            }
            else
            {
                tag.TagName = prop.Item3.ToString();
            }

            Type t = prop.Item3.GetType();

            if (!String.IsNullOrEmpty(attribute.TagNameFromProperty))
            {
                var addObject = t.GetProperty(attribute.TagNameFromProperty).GetValue(prop.Item3, null);
                tag.TagName += String.Format("{0}", addObject);
            }
            tag.TagValue = String.Format("{0}", tag.MyRuntimeObject);
            Type typeValue = tag.MyRuntimeObject.GetType();

            SetTagTypeEnumFromCLRType(tag, typeValue);
            if (!String.IsNullOrEmpty(attribute.TagValueFromProperty))
            {
                var addObject = t.GetProperty(attribute.TagValueFromProperty).GetValue(prop.Item3, null);
                tag.TagValue = String.Format("{0}", addObject);
            }
            proptaglist.Add(tag);
            if (prop.Item1 != null)
            {
                var childlist = ExtractTagsFromAttributes(tag.MyRuntimeObject, tag);
                if (childlist != null)
                {
                    proptaglist.AddRange(childlist);
                }
            }
            if (attribute.DeleteIfEmpty)
            {
                if (!tag.Tags.Any() && String.IsNullOrEmpty(tag.TagValue))
                {
                    tag.MyParentTag.Tags.Remove(tag);
                }
            }
            return(proptaglist);
        }
Ejemplo n.º 3
0
        internal static IList <SearchTag> ExtractTagsFromAttributesForProperty(Tuple <PropertyInfo, Chummer.HubTagAttribute, Object> prop, SearchTag parenttag)
        {
            List <SearchTag> proptaglist = new List <SearchTag>();

            Chummer.HubTagAttribute attribute = prop.Item2 as Chummer.HubTagAttribute;
            Object       propValue;
            PropertyInfo property = prop.Item1 as PropertyInfo;

            if (property == null)
            {
                propValue = prop.Item3;
            }
            else
            {
                propValue = property.GetValue(prop.Item3);
                if (propValue.GetType().IsAssignableFrom(typeof(bool)))
                {
                    if (propValue as bool? == false)
                    { //dont save "false" values
                        return(proptaglist);
                    }
                }
                if (propValue.GetType().IsAssignableFrom(typeof(int)))
                {
                    if (propValue as int? == 0)
                    {   //dont save "0" values
                        return(proptaglist);
                    }
                }
            }


            var tag = new SearchTag(property, attribute);

            tag.MyRuntimePropertyValue = propValue;
            tag.SearchTags             = new List <SearchTag>();
            tag.MyParentTag            = parenttag;
            if (tag.MyParentTag != null)
            {
                tag.MyParentTag.SearchTags.Add(tag);
            }
            tag.ParentTagId = parenttag?.Id;
            tag.Id          = Guid.NewGuid();
            if (!String.IsNullOrEmpty(attribute.TagName))
            {
                tag.TagName = attribute.TagName;
            }
            else if (prop.Item1 != null)
            {
                tag.TagName = prop.Item1.Name;
            }
            else
            {
                tag.TagName = prop.Item3.ToString();
            }

            Type t = prop.Item3.GetType();

            if (!String.IsNullOrEmpty(attribute.TagNameFromProperty))
            {
                var addObject = t.GetProperty(attribute.TagNameFromProperty).GetValue(prop.Item3, null);
                tag.TagName += String.Format("{0}", addObject);
            }
            tag.TagValue = String.Format("{0}", tag.MyRuntimePropertyValue);
            Type typeValue = tag.MyRuntimePropertyValue.GetType();

            //if (typeof(int).IsAssignableFrom(typeValue))
            //{
            //    tag.TagType = "int";
            //}
            //else if (typeof(double).IsAssignableFrom(typeValue))
            //{
            //    tag.TagType = "double";
            //}
            //else if (typeof(bool).IsAssignableFrom(typeValue))
            //{
            //    tag.TagType = "bool";
            //}
            //else if (typeof(string).IsAssignableFrom(typeValue))
            //{
            //    tag.TagType = "string";
            //}
            //else if (typeof(Guid).IsAssignableFrom(typeValue))
            //{
            //    tag.TagType = "Guid";
            //}
            //else
            //{
            //    tag.TagType = "other";
            //}
            //if (tag.TagValue == typeValue.FullName)
            //    tag.TagValue = "";
            //if ((typeof(IEnumerable).IsAssignableFrom(typeValue)
            //    || typeof(ICollection).IsAssignableFrom(typeValue))
            //    && !typeof(string).IsAssignableFrom(typeValue))
            //{
            //    tag.TagType = "list";
            //    tag.TagValue = "";
            //}
            //if (!String.IsNullOrEmpty(attribute.TagValueFromProperty))
            //{
            //    var addObject = t.GetProperty(attribute.TagValueFromProperty).GetValue(prop.Item3, null);
            //    tag.TagValue = String.Format("{0}", addObject);
            //}
            proptaglist.Add(tag);
            if (prop.Item1 != null)
            {
                var childlist = ExtractTagsFromAttributes(tag.MyRuntimePropertyValue, tag);
                proptaglist.AddRange(childlist);
            }
            if (attribute.DeleteIfEmpty)
            {
                if (!tag.Tags.Any() && String.IsNullOrEmpty(tag.TagValue))
                {
                    tag.MyParentTag.SearchTags.Remove(tag);
                }
            }
            return(proptaglist);
        }
Ejemplo n.º 4
0
 public SearchTag(PropertyInfo myPropertyInfo, Chummer.HubTagAttribute hubTag)
 {
     MyPropertyInfo  = myPropertyInfo;
     MyRuntimeHubTag = hubTag;
     this.SearchTags = new List <SearchTag>();
 }