コード例 #1
0
        private void AddInclude(IJsonApiObject value)
        {
            if (this._modeExtand)
            {
                return;
            }

            if (value.id == null)
            {
                throw new ArgumentException($"Id missing in {value.type}, use attribute [IdJsonApi]");
            }

            string id = value.type + value.id;

            if (this._includedRelationship == null)
            {
                this._includedRelationship = new List <IJsonApiObject>();
            }

            if (!this._relationship_id.Contains(id))
            {
                this._includedRelationship.Add(value);
                this._relationship_id.Add(id);
            }
        }
コード例 #2
0
        /// <summary>
        /// Create base object (id, type)
        /// </summary>
        /// <param name="model"></param>
        /// <param name="type"></param>
        /// <param name="extandData"></param>
        /// <returns></returns>
        private IJsonApiObject CreateJsonApiOject(object model, Type type, bool extandData)
        {
            IJsonApiObject returnObject = extandData ? new JsonApiData() : new JsonApiDataBase();

            IEnumerable <PropertyInfo> idsProperties = AttributeHandling.GetIdsProperties(type);

            if (idsProperties.Any())
            {
                returnObject.id = string.Join(Constants.SEPERATOR_IDS, idsProperties.Select(p => p.GetValue(model).ToString()));
            }

            string labelType = AttributeHandling.GetLabelProperty(type);

            returnObject.type = (!type.Name.Contains("AnonymousType")) ? labelType : null;

            return(returnObject);
        }
コード例 #3
0
        /// <summary>
        /// Create base object (id, type) and add attributes
        /// </summary>
        /// <param name="model">instance</param>
        /// <param name="extandData">true return attributes in the object</param>
        /// <returns></returns>
        private IJsonApiObject SetData(object model, bool extandData, string pathRelation = null)
        {
            if (model == null)
            {
                return(null);
            }

            if (pathRelation != null)
            {
                pathRelation += ".";
            }

            Type type = model.GetType();

            if (model is IDictionary <string, string> )
            {
                return(this.CreateJsonApiListKeyValue(model));
            }

            if (model is List <KeyValuePair <string, string> > )
            {
                return(this.CreateJsonApiListKeyValue(model));
            }

            if (Utils.IsTypeSystem(type))
            {
                return(this.CreateJsonApiForSystemObject(model, type));
            }

            IJsonApiObject json = this.CreateJsonApiOject(model, type, extandData);

            if (extandData)
            {
                this.CreateAttribute(model, type, (JsonApiData)json, pathRelation);
            }

            return(json);
        }