Beispiel #1
0
        public Task AddExtensions(JsonSchema4 schema, ValueProviderArgs args)
        {
            var sources = GetSourcesSync(args);

            foreach (var source in sources)
            {
                schema.EnumerationNames.Add(source.Label);
                schema.Enumeration.Add(source.Value);
            }

            if (schema.ExtensionData == null)
            {
                schema.ExtensionData = new Dictionary <String, Object>();
            }

            return(Task.FromResult(0));
        }
        public async Task AddExtensions(JsonProperty schemaProp, ValueProviderArgs args)
        {
            var name = "x-values";

            if (args.ValueProviderAttr.PropertyName != null)
            {
                name = args.ValueProviderAttr.PropertyName;
            }

            var sources = GetNullSource(args).Concat(await GetSources());

            if (schemaProp.ExtensionData == null)
            {
                schemaProp.ExtensionData = new Dictionary <String, Object>();
            }

            schemaProp.ExtensionData.Add(name, sources);
        }
Beispiel #3
0
        protected virtual IEnumerable <LabelValuePair> GetSourcesSync(ValueProviderArgs args)
        {
            if (args.IsNullable)
            {
                NullValueLabelAttribute nullLabel = args.PropertyInfo.GetCustomAttribute <NullValueLabelAttribute>();

                if (nullLabel == null)
                {
                    nullLabel = enumType.GetTypeInfo().GetCustomAttribute <NullValueLabelAttribute>();
                }

                if (nullLabel == null)
                {
                    nullLabel = new NullValueLabelAttribute();
                }

                if (nullLabel.IncludeNullValueLabel)
                {
                    yield return(new LabelValuePair()
                    {
                        Label = nullLabel.Label,
                        Value = null
                    });
                }
            }

            foreach (var member in enumType.GetTypeInfo().DeclaredFields.Where(i => i.IsStatic)) //The static decalared fields are our enum values
            {
                var label   = member.Name;
                var display = member.GetCustomAttribute <DisplayAttribute>();
                if (display != null)
                {
                    label = display.Name;
                }
                yield return(new LabelValuePair()
                {
                    Label = label,
                    Value = member.Name
                });
            }
        }
        private IEnumerable <ILabelValuePair> GetNullSource(ValueProviderArgs args)
        {
            if (args.IsNullable)
            {
                //Include the null enum label since we can take null values
                NullValueLabelAttribute nullLabel = args.PropertyInfo.GetCustomAttribute <NullValueLabelAttribute>();

                if (nullLabel == null)
                {
                    nullLabel = new NullValueLabelAttribute();
                }

                if (nullLabel.IncludeNullValueLabel)
                {
                    yield return(new LabelValuePair()
                    {
                        Label = nullLabel.Label,
                        Value = null
                    });
                }
            }
        }