Example #1
0
        private static IEnumerable <Tag> ExtractTagsFromPropertyWithSpecificAttribute(object objValue, PropertyInfo objProperty, HubTagAttribute attribute)
        {
            if (objProperty != null)
            {
                objValue = objProperty.GetValue(objValue);
                if (objValue == null)
                {
                    //don't save "null" values
                    yield break;
                }
                if (objValue.GetType().IsAssignableFrom(typeof(bool)) && objValue as bool? == false)
                {
                    //don't save "false" values
                    yield break;
                }
                if (objValue.GetType().IsAssignableFrom(typeof(int)) && objValue as int? == 0)
                {
                    //don't save "0" values
                    yield break;
                }
            }
            else if (objValue == null)
            {
                yield break;
            }
            Type objValueType = objValue.GetType();

            Tag tag = new Tag(objValue, attribute)
            {
                TagValue = !string.IsNullOrEmpty(attribute.TagValueFromProperty)
                    ? objValueType.GetProperty(attribute.TagValueFromProperty)?.GetValue(objValue, null)?.ToString() ?? string.Empty
                    : objValue.ToString(),
                TagName = !string.IsNullOrEmpty(attribute.TagName)
                    ? attribute.TagName
                    : !string.IsNullOrEmpty(objProperty?.Name)
                        ? objProperty.Name
                        : objValue.ToString()
            };

            tag.SetTagTypeEnumFromCLRType(objValueType);
            if (!string.IsNullOrEmpty(attribute.TagNameFromProperty))
            {
                try
                {
                    tag.TagName += objValueType.GetProperty(attribute.TagNameFromProperty)?.GetValue(objValue, null)?.ToString() ?? string.Empty;
                }
                catch (Exception)
                {
#if DEBUG
                    Debugger.Break();
#else
                    throw;
#endif
                }
            }

            if (objProperty != null)
            {
                tag.Tags = new List <Tag>(ExtractTagsFromAttributes(objValue));
            }
            yield return(tag);
        }
Example #2
0
 public Tag(object myRuntimeObject, HubTagAttribute hubTag)
 {
     Id = Guid.NewGuid();
     MyRuntimeObject = myRuntimeObject;
     MyRuntimeHubTag = hubTag;
 }
Example #3
0
 public SearchTag(PropertyInfo myPropertyInfo, HubTagAttribute hubTag)
 {
     MyPropertyInfo  = myPropertyInfo;
     MyRuntimeHubTag = hubTag;
     SearchTags      = new List <SearchTag>();
 }