示例#1
0
        /// <summary>
        /// Add attributes, relationship and included relationship
        /// </summary>
        /// <param name="model"></param>
        /// <param name="type"></param>
        /// <param name="json"></param>
        private void CreateAttribute(object model, Type type, JsonApiData json, string pathRelation)
        {
            foreach (PropertyInfo prop in this.GetListProperties(type, json.type))
            {
                object value = this.ResolveData(prop, prop.GetValue(model));

                string propName = AttributeHandling.GetLabelProperty(prop);

                if (value != null)
                {
                    Type typeValue = value.GetType();
                    if (Utils.IsEnum(value))
                    {
                        if (Utils.HasGenericTypeSystem(typeValue))
                        {
                            json.AddAttribute(propName, this.SetListData(value, this._modeExtand).Select(m => m.toJsonFormat()).ToList());
                        }
                        else
                        {
                            this.CreateRelationship(json, propName, true, this.IsInclude(pathRelation + propName), (extand) => this.SetListData(value, extand, pathRelation + propName));
                        }
                    }
                    else if (Utils.IsTypeSystem(typeValue))
                    {
                        json.AddAttribute(propName, value);
                    }
                    else
                    {
                        this.CreateRelationship(json, propName, false, this.IsInclude(pathRelation + propName), (extand) => this.SetData(value, extand, pathRelation + propName));
                    }
                }
            }
        }
示例#2
0
        private IJsonApiObject CreateJsonApiListKeyValue(object model)
        {
            var returnObject = new JsonApiData();

            foreach (KeyValuePair <string, string> entry in (IEnumerable)model)
            {
                returnObject.AddAttribute(entry.Key, entry.Value);
            }
            return(returnObject);
        }