Пример #1
0
        internal static GroupListResult DeserializeGroupListResult(JsonElement element)
        {
            Optional <IReadOnlyList <ADGroup> > value = default;
            Optional <string> odataNextLink           = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ADGroup> array = new List <ADGroup>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ADGroup.DeserializeADGroup(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("odata.nextLink"))
                {
                    odataNextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new GroupListResult(Optional.ToList(value), odataNextLink.Value));
        }
        internal static DirectoryObject DeserializeDirectoryObject(JsonElement element)
        {
            if (element.TryGetProperty("objectType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "AppRoleAssignment": return(AppRoleAssignment.DeserializeAppRoleAssignment(element));

                case "Application": return(Application.DeserializeApplication(element));

                case "Group": return(ADGroup.DeserializeADGroup(element));

                case "ServicePrincipal": return(ServicePrincipal.DeserializeServicePrincipal(element));

                case "User": return(User.DeserializeUser(element));
                }
            }
            Optional <string>                    objectId                       = default;
            string                               objectType                     = default;
            Optional <DateTimeOffset?>           deletionTimestamp              = default;
            IReadOnlyDictionary <string, object> additionalProperties           = default;
            Dictionary <string, object>          additionalPropertiesDictionary = new Dictionary <string, object>();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("objectId"))
                {
                    objectId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("objectType"))
                {
                    objectType = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("deletionTimestamp"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        deletionTimestamp = null;
                        continue;
                    }
                    deletionTimestamp = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
            }
            additionalProperties = additionalPropertiesDictionary;
            return(new DirectoryObject(objectId.Value, objectType, Optional.ToNullable(deletionTimestamp), additionalProperties));
        }
Пример #3
0
        internal static GroupListResult DeserializeGroupListResult(JsonElement element)
        {
            IReadOnlyList <ADGroup> value = default;
            string odataNextLink          = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ADGroup> array = new List <ADGroup>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ADGroup.DeserializeADGroup(item));
                        }
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("odata.nextLink"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    odataNextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new GroupListResult(value, odataNextLink));
        }