示例#1
0
        private List <Teaser> GetTeaserListFromSemantics(EntityModel entity)
        {
            Type type   = entity.GetType();
            bool isList = false;

            foreach (object attr in type.GetCustomAttributes(true))
            {
                if (attr is SemanticEntityAttribute)
                {
                    SemanticEntityAttribute semantics = (SemanticEntityAttribute)attr;
                    isList = semantics.Vocab == ViewModel.SchemaOrgVocabulary && semantics.EntityName == "ItemList";
                    if (isList)
                    {
                        break;
                    }
                }
            }
            if (isList)
            {
                foreach (PropertyInfo pi in type.GetProperties())
                {
                    if (pi.PropertyType == typeof(List <Teaser>))
                    {
                        return(pi.GetValue(entity) as List <Teaser>);
                    }
                }
            }
            return(null);
        }
示例#2
0
        protected virtual Dictionary <string, KeyValuePair <string, string> > GetEntityDataFromType(Type type)
        {
            Dictionary <string, KeyValuePair <string, string> > res = new Dictionary <string, KeyValuePair <string, string> >();

            foreach (Attribute attr in type.GetCustomAttributes())
            {
                if (attr is SemanticEntityAttribute)
                {
                    SemanticEntityAttribute semantics = (SemanticEntityAttribute)attr;
                    // we can only support mapping to a single semantic entity, the derived type is set first, so that is what we use
                    if (!res.ContainsKey(semantics.Prefix))
                    {
                        res.Add(semantics.Prefix, new KeyValuePair <string, string>(semantics.Vocab, semantics.EntityName));
                    }
                }
                if (attr is SemanticDefaultsAttribute)
                {
                    SemanticDefaultsAttribute semantics = (SemanticDefaultsAttribute)attr;
                    res.Add(semantics.Prefix, new KeyValuePair <string, string>(semantics.Vocab, String.Empty));
                }
            }

            //Add default mapping if none was specified on entity
            if (!res.ContainsKey(string.Empty))
            {
                res.Add(string.Empty, new KeyValuePair <string, string>(ViewModel.CoreVocabulary, string.Empty));
            }

            return(res);
        }
示例#3
0
        protected virtual Dictionary <string, string> GetEntitiesFromType(Type type)
        {
            Dictionary <string, string> res = new Dictionary <string, string>();

            foreach (Attribute attr in type.GetCustomAttributes())
            {
                if (attr is SemanticEntityAttribute)
                {
                    SemanticEntityAttribute semantics = (SemanticEntityAttribute)attr;
                    res.Add(semantics.Prefix, semantics.EntityName);
                }
            }
            return(res);
        }