private static ICollection <SCIMRepresentationAttribute> ExtractRepresentationAttributesFromJSON(
            ICollection <SCIMSchema> schemas,
            ICollection <SCIMSchemaAttribute> schemaAttributes,
            object obj,
            bool ignoreUnsupportedCanonicalValues)
        {
            var result = new List <SCIMRepresentationAttribute>();
            var jArr   = obj as JArray;
            var jObj   = obj as JObject;

            if (jObj != null && schemaAttributes != null &&
                schemaAttributes.Any() &&
                schemaAttributes.Count() == 1 &&
                schemaAttributes.First().Type == SCIMSchemaAttributeTypes.COMPLEX)
            {
                jArr = new JArray();
                jArr.Add(jObj);
            }

            var mainSchema       = schemas.First(s => s.IsRootSchema);
            var extensionSchemas = schemas.Where(s => !s.IsRootSchema).ToList();

            if (jArr != null)
            {
                var schemaAttr = schemaAttributes.First();
                var schema     = schemas.FirstOrDefault(s => s.HasAttribute(schemaAttr));
                result.AddRange(SCIMRepresentationHelper.BuildAttributes(jArr, schemaAttr, schema, ignoreUnsupportedCanonicalValues));
            }
            else if (jObj != null)
            {
                var resolutionResult = SCIMRepresentationHelper.Resolve(jObj, mainSchema, extensionSchemas);
                result.AddRange(SCIMRepresentationHelper.BuildRepresentationAttributes(resolutionResult, resolutionResult.AllSchemaAttributes, ignoreUnsupportedCanonicalValues, true));
            }
            else if (schemaAttributes.Any() && schemaAttributes.Count() == 1)
            {
                var schemaAttribute = schemaAttributes.First();
                switch (schemaAttribute.Type)
                {
                case SCIMSchemaAttributeTypes.BOOLEAN:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schemaAttribute, schemaAttribute.SchemaId, valueBoolean: bool.Parse(obj.ToString())));
                    break;

                case SCIMSchemaAttributeTypes.STRING:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schemaAttribute, schemaAttribute.SchemaId, valueString: obj.ToString()));
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schemaAttribute, schemaAttribute.SchemaId, valueInteger: int.Parse(obj.ToString())));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), schemaAttribute, schemaAttribute.SchemaId, valueDateTime: DateTime.Parse(obj.ToString())));
                    break;
                }
            }

            return(result);
        }
        private static ICollection <SCIMRepresentationAttribute> ExtractRepresentationAttributesFromJSON(ICollection <SCIMSchemaAttribute> schemaAttributes, object obj, bool ignoreUnsupportedCanonicalValues)
        {
            var result = new List <SCIMRepresentationAttribute>();
            var jArr   = obj as JArray;
            var jObj   = obj as JObject;

            if (jObj != null && schemaAttributes != null &&
                schemaAttributes.Any() &&
                schemaAttributes.Count() == 1 &&
                schemaAttributes.First().Type == SCIMSchemaAttributeTypes.COMPLEX &&
                schemaAttributes.First().MultiValued)
            {
                jArr = new JArray();
                jArr.Add(jObj);
            }

            if (jArr != null)
            {
                result.AddRange(SCIMRepresentationHelper.BuildAttributes(jArr, schemaAttributes.First(), ignoreUnsupportedCanonicalValues));
            }
            else if (jObj != null)
            {
                result.AddRange(SCIMRepresentationHelper.BuildRepresentationAttributes(jObj, schemaAttributes, ignoreUnsupportedCanonicalValues, true));
            }
            else if (schemaAttributes.Any() && schemaAttributes.Count() == 1)
            {
                var schemaAttribute = schemaAttributes.First();
                switch (schemaAttribute.Type)
                {
                case SCIMSchemaAttributeTypes.BOOLEAN:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesBoolean: new List <bool> {
                        bool.Parse(obj.ToString())
                    }));
                    break;

                case SCIMSchemaAttributeTypes.STRING:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesString: new List <string> {
                        obj.ToString()
                    }));
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesInteger: new List <int> {
                        int.Parse(obj.ToString())
                    }));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesDateTime: new List <DateTime> {
                        DateTime.Parse(obj.ToString())
                    }));
                    break;
                }
            }

            return(result);
        }
        private static ICollection <SCIMRepresentationAttribute> ExtractRepresentationAttributesFromJSON(SCIMSchemaAttribute schemaAttribute, object jObj)
        {
            var jArr = jObj as JArray;
            var parsedRepresentationAttributes = new List <SCIMRepresentationAttribute>();

            if (schemaAttribute.Type == SCIMSchemaAttributeTypes.COMPLEX)
            {
                if (jArr != null)
                {
                    foreach (JObject record in jArr)
                    {
                        var attribute = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute);
                        foreach (var attr in SCIMRepresentationHelper.BuildRepresentationAttributes(record, schemaAttribute.SubAttributes))
                        {
                            attribute.Add(attr);
                        }

                        parsedRepresentationAttributes.Add(attribute);
                    }
                }
                else
                {
                    var attribute = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute);
                    foreach (var attr in SCIMRepresentationHelper.BuildRepresentationAttributes(jObj as JObject, schemaAttribute.SubAttributes))
                    {
                        attribute.Add(attr);
                    }

                    parsedRepresentationAttributes.Add(attribute);
                }
            }
            else
            {
                switch (schemaAttribute.Type)
                {
                case SCIMSchemaAttributeTypes.BOOLEAN:
                    parsedRepresentationAttributes.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesBoolean: new List <bool> {
                        bool.Parse(jObj.ToString())
                    }));
                    break;

                case SCIMSchemaAttributeTypes.STRING:
                    parsedRepresentationAttributes.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesString: new List <string> {
                        jObj.ToString()
                    }));
                    break;

                case SCIMSchemaAttributeTypes.INTEGER:
                    parsedRepresentationAttributes.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesInteger: new List <int> {
                        int.Parse(jObj.ToString())
                    }));
                    break;

                case SCIMSchemaAttributeTypes.DATETIME:
                    parsedRepresentationAttributes.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), schemaAttribute, valuesDateTime: new List <DateTime> {
                        DateTime.Parse(jObj.ToString())
                    }));
                    break;
                }
            }

            return(parsedRepresentationAttributes);
        }