private void AddAllowedChildren(INamedTypeSymbol type, TagHelperDescriptorBuilder builder)
    {
        var restrictChildrenAttribute = type.GetAttributes().Where(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, _restrictChildrenAttributeSymbol)).FirstOrDefault();

        if (restrictChildrenAttribute == null)
        {
            return;
        }

        builder.AllowChildTag(childTagBuilder => childTagBuilder.Name = (string)restrictChildrenAttribute.ConstructorArguments[0].Value);

        if (restrictChildrenAttribute.ConstructorArguments.Length == 2)
        {
            foreach (var value in restrictChildrenAttribute.ConstructorArguments[1].Values)
            {
                builder.AllowChildTag(childTagBuilder => childTagBuilder.Name = (string)value.Value);
            }
        }
    }
Exemplo n.º 2
0
    public static TagHelperDescriptorBuilder AllowChildTag(this TagHelperDescriptorBuilder builder, string allowedChild)
    {
        if (builder == null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        builder.AllowChildTag(childTagBuilder => childTagBuilder.Name = allowedChild);

        return(builder);
    }
        private static void ReadAllowedChildTag(JsonReader reader, TagHelperDescriptorBuilder builder)
        {
            if (!reader.Read())
            {
                return;
            }

            if (reader.TokenType != JsonToken.StartObject)
            {
                return;
            }

            builder.AllowChildTag(childTag =>
            {
                reader.ReadProperties(propertyName =>
                {
                    switch (propertyName)
                    {
                    case nameof(AllowedChildTagDescriptor.Name):
                        if (reader.Read())
                        {
                            var name      = (string)reader.Value;
                            childTag.Name = name;
                        }
                        break;

                    case nameof(AllowedChildTagDescriptor.DisplayName):
                        if (reader.Read())
                        {
                            var displayName      = (string)reader.Value;
                            childTag.DisplayName = displayName;
                        }
                        break;

                    case nameof(AllowedChildTagDescriptor.Diagnostics):
                        ReadDiagnostics(reader, childTag.Diagnostics);
                        break;
                    }
                });
            });
        }
Exemplo n.º 4
0
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        if (reader.TokenType != JsonToken.StartObject)
        {
            return(null);
        }
        JObject jObject       = JObject.Load(reader);
        string  kind          = jObject["Kind"].Value <string>();
        string  name          = jObject["Name"].Value <string>();
        string  assemblyName  = jObject["AssemblyName"].Value <string>();
        JArray  jArray        = jObject["TagMatchingRules"].Value <JArray>();
        JArray  jArray2       = jObject["BoundAttributes"].Value <JArray>();
        JArray  jArray3       = jObject["AllowedChildTags"].Value <JArray>();
        string  documentation = jObject["Documentation"].Value <string>();
        string  tagOutputHint = jObject["TagOutputHint"].Value <string>();
        bool    caseSensitive = jObject["CaseSensitive"].Value <bool>();
        JArray  jArray4       = jObject["Diagnostics"].Value <JArray>();
        JObject jObject2      = jObject["Metadata"].Value <JObject>();
        TagHelperDescriptorBuilder tagHelperDescriptorBuilder = TagHelperDescriptorBuilder.Create(kind, name, assemblyName);

        tagHelperDescriptorBuilder.Documentation = documentation;
        tagHelperDescriptorBuilder.TagOutputHint = tagOutputHint;
        tagHelperDescriptorBuilder.CaseSensitive = caseSensitive;
        foreach (JToken item2 in jArray)
        {
            JObject rule = item2.Value <JObject>();
            tagHelperDescriptorBuilder.TagMatchingRule(delegate(TagMatchingRuleDescriptorBuilder b)
            {
                ReadTagMatchingRule(b, rule, serializer);
            });
        }
        foreach (JToken item3 in jArray2)
        {
            JObject attribute = item3.Value <JObject>();
            tagHelperDescriptorBuilder.BindAttribute(delegate(BoundAttributeDescriptorBuilder b)
            {
                ReadBoundAttribute(b, attribute, serializer);
            });
        }
        foreach (JToken item4 in jArray3)
        {
            JObject tag = item4.Value <JObject>();
            tagHelperDescriptorBuilder.AllowChildTag(delegate(AllowedChildTagDescriptorBuilder childTagBuilder)
            {
                ReadAllowedChildTag(childTagBuilder, tag, serializer);
            });
        }
        foreach (JToken item5 in jArray4)
        {
            JsonReader      reader2 = item5.CreateReader();
            RazorDiagnostic item    = serializer.Deserialize <RazorDiagnostic>(reader2);
            tagHelperDescriptorBuilder.Diagnostics.Add(item);
        }
        JsonReader reader3 = jObject2.CreateReader();

        foreach (KeyValuePair <string, string> item6 in serializer.Deserialize <Dictionary <string, string> >(reader3))
        {
            tagHelperDescriptorBuilder.Metadata[item6.Key] = item6.Value;
        }
        return(tagHelperDescriptorBuilder.Build());
    }