Пример #1
0
 internal PolicyAssignment(string id, string type, string name, PolicySku sku, string location, IdentityAutoGenerated identity, string displayName, string policyDefinitionId, string scope, IList <string> notScopes, IDictionary <string, ParameterValuesValue> parameters, string description, object metadata, EnforcementMode?enforcementMode)
 {
     Id                 = id;
     Type               = type;
     Name               = name;
     Sku                = sku;
     Location           = location;
     Identity           = identity;
     DisplayName        = displayName;
     PolicyDefinitionId = policyDefinitionId;
     Scope              = scope;
     NotScopes          = notScopes;
     Parameters         = parameters;
     Description        = description;
     Metadata           = metadata;
     EnforcementMode    = enforcementMode;
 }
        internal static PolicyAssignment DeserializePolicyAssignment(JsonElement element)
        {
            string                id                 = default;
            string                type               = default;
            string                name               = default;
            PolicySku             sku                = default;
            string                location           = default;
            IdentityAutoGenerated identity           = default;
            string                displayName        = default;
            string                policyDefinitionId = default;
            string                scope              = default;
            IList <string>        notScopes          = default;
            IDictionary <string, ParameterValuesValue> parameters = default;
            string          description     = default;
            object          metadata        = default;
            EnforcementMode?enforcementMode = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("sku"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    sku = PolicySku.DeserializePolicySku(property.Value);
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    identity = IdentityAutoGenerated.DeserializeIdentityAutoGenerated(property.Value);
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("displayName"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            displayName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("policyDefinitionId"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            policyDefinitionId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("scope"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            scope = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("notScopes"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            List <string> array = new List <string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                if (item.ValueKind == JsonValueKind.Null)
                                {
                                    array.Add(null);
                                }
                                else
                                {
                                    array.Add(item.GetString());
                                }
                            }
                            notScopes = array;
                            continue;
                        }
                        if (property0.NameEquals("parameters"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            Dictionary <string, ParameterValuesValue> dictionary = new Dictionary <string, ParameterValuesValue>();
                            foreach (var property1 in property0.Value.EnumerateObject())
                            {
                                if (property1.Value.ValueKind == JsonValueKind.Null)
                                {
                                    dictionary.Add(property1.Name, null);
                                }
                                else
                                {
                                    dictionary.Add(property1.Name, ParameterValuesValue.DeserializeParameterValuesValue(property1.Value));
                                }
                            }
                            parameters = dictionary;
                            continue;
                        }
                        if (property0.NameEquals("description"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            description = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("metadata"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            metadata = property0.Value.GetObject();
                            continue;
                        }
                        if (property0.NameEquals("enforcementMode"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                continue;
                            }
                            enforcementMode = new EnforcementMode(property0.Value.GetString());
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new PolicyAssignment(id, type, name, sku, location, identity, displayName, policyDefinitionId, scope, notScopes, parameters, description, metadata, enforcementMode));
        }