public static bool IsDeprecated( this EnumValueDefinition definition, out string?reason) { if (definition.Directives is null) { reason = null; return(false); } if (definition.TryGetDirective("deprecated", out var directive)) { if (directive.Arguments?.TryGet("reason", out var reasonArg) == true && reasonArg.Value is StringValue stringValue) { reason = stringValue; } else { reason = null; } return(true); } reason = null; return(false); }
public static void AreEqual(EnumValueDefinition expected, EnumValueDefinition actual, string message) { Assert.AreEqual(expected.MetadataItemID, actual.MetadataItemID, message); Assert.AreEqual(expected.Name, actual.Name, message); Assert.AreEqual(expected.Index, actual.Index, message); Assert.AreEqual(expected.Value, actual.Value, message); }
private bool ValidateEnumValueDefinition(EnumValueDefinition valueDefinition) { if (!(valueDefinition is FieldAwareEnumValueDefinition fieldDefinition)) { return(true); } if (typeof(ListGraphType).IsAssignableFrom(fieldDefinition.FieldType.Type)) { return(false); } else { var originalName = fieldDefinition.FieldType.GetOriginalName(); var sourceType = fieldDefinition.FieldType.GetSourceType(); if (sourceType == null) { return(true); //TODO or false, not sure, need more brain to evaluate } var requiredProperty = sourceType.GetProperty(originalName, comparisonType: StringComparison.OrdinalIgnoreCase); if (requiredProperty == null) { return(false); } } return(true); }
internal void ParseEnumValues(EnumDefinition def, string[] lines, int startIndex, string line) { int fieldIndex = startIndex + 1; // set to first property string fieldDef = lines[fieldIndex]; while (!fieldDef.StartsWith("}")) { if (!string.IsNullOrEmpty(fieldDef)) { fieldDef = fieldDef.Trim(); fieldDef = fieldDef.RemoveSpaces(); string[] parts = fieldDef.Split("="); EnumValueDefinition enumValue = new EnumValueDefinition { Name = parts[0], Value = parts[1] }; def.Values.Add(enumValue); } fieldIndex++; fieldDef = lines[fieldIndex]; } if (fieldDef.StartsWith("}")) { fieldDef = fieldDef.RemoveSpaces(); fieldDef = fieldDef.Substring(1, fieldDef.Length - 2); def.Name = fieldDef; } }
public EnumValue(EnumValueDefinition enumValueDefinition) { if (enumValueDefinition == null) { throw new ArgumentNullException(nameof(enumValueDefinition)); } if (enumValueDefinition.Value == null) { throw new ArgumentException( TypeResources.EnumValue_ValueIsNull, nameof(enumValueDefinition)); } _definition = enumValueDefinition; SyntaxNode = enumValueDefinition.SyntaxNode; Name = enumValueDefinition.Name.HasValue ? enumValueDefinition.Name : (NameString)enumValueDefinition.Value.ToString(); Description = enumValueDefinition.Description; DeprecationReason = enumValueDefinition.DeprecationReason; IsDeprecated = !string.IsNullOrEmpty( enumValueDefinition.DeprecationReason); Value = enumValueDefinition.Value; }
public EnumValue( ITypeCompletionContext completionContext, EnumValueDefinition enumValueDefinition) { if (completionContext == null) { throw new ArgumentNullException(nameof(completionContext)); } if (enumValueDefinition is null) { throw new ArgumentNullException(nameof(enumValueDefinition)); } if (enumValueDefinition.RuntimeValue is null) { throw new ArgumentException( TypeResources.EnumValue_ValueIsNull, nameof(enumValueDefinition)); } SyntaxNode = enumValueDefinition.SyntaxNode; Name = enumValueDefinition.Name.HasValue ? enumValueDefinition.Name : (NameString)enumValueDefinition.RuntimeValue.ToString() !; Description = enumValueDefinition.Description; DeprecationReason = enumValueDefinition.DeprecationReason; IsDeprecated = !string.IsNullOrEmpty(enumValueDefinition.DeprecationReason); Value = enumValueDefinition.RuntimeValue; ContextData = enumValueDefinition.GetContextData(); _directives = DirectiveCollection .CreateAndComplete(completionContext, this, enumValueDefinition !.GetDirectives()); }
public EnumValueContext(EnumValueDefinition entry, GraphQLGenerationOptions options, Document document, string propertyName) { this.Name = propertyName; this.entry = entry; this.options = options; this.document = document; }
public EnumValue(EnumValueDefinition enumValueDefinition) { if (enumValueDefinition == null) { throw new ArgumentNullException(nameof(enumValueDefinition)); } if (enumValueDefinition.Value == null) { // TODO : resources throw new ArgumentException( "The inner value of enum value cannot be null or empty.", nameof(enumValueDefinition)); } SyntaxNode = enumValueDefinition.SyntaxNode; Name = enumValueDefinition.Name.HasValue ? enumValueDefinition.Name : (NameString)enumValueDefinition.Value.ToString(); Description = enumValueDefinition.Description; DeprecationReason = enumValueDefinition.DeprecationReason; IsDeprecated = !string.IsNullOrEmpty( enumValueDefinition.DeprecationReason); Value = enumValueDefinition.Value; }
private static void DeclareValues( EnumTypeDefinition parent, IReadOnlyCollection <EnumValueDefinitionNode> values, bool preserveSyntaxNodes) { foreach (EnumValueDefinitionNode value in values) { var valueDefinition = new EnumValueDefinition( value.Name.Value, value.Description?.Value, value.Name.Value); valueDefinition.BindTo = value.GetBindingValue(); if (preserveSyntaxNodes) { valueDefinition.SyntaxNode = value; } SdlToTypeSystemHelper.AddDirectives(valueDefinition, value); if (value.DeprecationReason() is { Length: > 0 } reason) { valueDefinition.DeprecationReason = reason; } parent.Values.Add(valueDefinition); } }
public EnumValueDefinitionEditor(EnumValueDefinition def) { this.def = def; InitializeComponent(); Location = new Point(99, 53); elementsTextBox.Text = string.Join("\r\n", def.Elements, 0, def.Elements.Length); }
private EnumValueDefinition ToEnumValue(GraphQLEnumValueDefinition valDef) { var val = new EnumValueDefinition(); val.Value = valDef.Name.Value; val.Name = valDef.Name.Value; return(val); }
protected virtual bool TryCreateEnumValue( ITypeCompletionContext context, EnumValueDefinition definition, [NotNullWhen(true)] out IEnumValue?enumValue) { enumValue = new EnumValue(context, definition); return(true); }
public void FromString() { /* Given */ /* When */ EnumValueDefinition original = "V1"; /* Then */ Assert.Equal("V1", original.Value.Name); }
public EnumValueBindingDescriptor( IDescriptorContext context, IEnumTypeBindingDescriptor typeBindingDescriptor, EnumValueDefinition definition) { _context = context; _typeBindingDescriptor = typeBindingDescriptor; _definition = definition; }
internal EnumValueAdded(EnumerationGraphType enumType, EnumValueDefinition enumValue) : base(Criticality.Dangerous) { this.enumType = enumType; this.enumValue = enumValue; //TODO: Reason /* reason: "Adding an enum value may break existing clients that were not " \ * "programming defensively against an added case when querying an enum." */ }
public override void VisitEnumValue(EnumValueDefinition value) { // if a value has already been set, prefer that if (!string.IsNullOrWhiteSpace(value.DeprecationReason)) { return; } value.DeprecationReason = GetArgument <string>("reason") ?? DeprecatedDefaultValue; }
public void FromBytes() { /* Given */ /* When */ EnumValueDefinition original = Encoding.UTF8.GetBytes("V1") .AsReadOnlySpan(); /* Then */ Assert.Equal("V1", original.Value.Name); }
private void VisitEnumValueDefinition(EnumValueDefinition node) { EnterNode(node); Visit(node.Value); Visit(node.Directives); ExitNode(node); }
public static bool TryGetDirective( this EnumValueDefinition definition, Name directiveName, [NotNullWhen(true)] out Directive?directive) { if (definition.Directives is null) { directive = null; return(false); } return(definition.Directives.TryGet(directiveName, out directive)); }
private EnumValueDefinition ToEnumValue(GraphQLEnumValueDefinition valDef) { var val = new EnumValueDefinition { Value = valDef.Name.Value, Name = valDef.Name.Value, Description = valDef.Comment?.Text }.SetAstType(valDef); VisitNode(val, v => v.VisitEnumValue(val)); return(val); }
private EnumValueDefinition ToEnumValue(GraphQLEnumValueDefinition valDef) { var val = new EnumValueDefinition { Value = valDef.Name.Value, Name = valDef.Name.Value, Description = valDef.Comment?.Text }; ApplyDeprecatedDirective(valDef.Directives, reason => val.DeprecationReason = reason); return(val); }
public void WithValue() { /* Given */ EnumValueDefinition original = @"V1"; /* When */ var modified = original .WithValue(new EnumValue("RENAMED")); /* Then */ Assert.Equal("V1", original.Value.Name); Assert.Equal("RENAMED", modified.Value.Name); }
public void WithDescription() { /* Given */ EnumValueDefinition original = @"V1"; /* When */ var modified = original .WithDescription("Description"); /* Then */ Assert.Null(original.Description); Assert.Equal("Description", modified.Description); }
private string PrintEnumValueDefinition(EnumValueDefinition node) { var name = PrintName(node.Value.Name); var directives = node.Directives? .Select(PrintDirective) ?? Array.Empty <string>(); return(Join(new[] { name, Join(directives, " ") }, " ")); }
protected override bool TryCreateEnumValue( ITypeCompletionContext context, EnumValueDefinition definition, [NotNullWhen(true)] out IEnumValue?enumValue) { if (definition is SortEnumValueDefinition sortDefiniton) { enumValue = new SortEnumValue(context, sortDefiniton); return(true); } enumValue = null; return(false); }
private EnumValueDefinition ToEnumValue(GraphQLEnumValueDefinition valDef) { var val = new EnumValueDefinition(); val.Value = valDef.Name.Value; val.Name = valDef.Name.Value; ApplyDeprecatedDirective(valDef.Directives, reason => { val.DeprecationReason = reason; }); return(val); }
internal void CompleteValue(ITypeCompletionContext context) { var directives = new DirectiveCollection( this, _definition.Directives); directives.CompleteCollection(context); Directives = directives; OnCompleteValue(context, _definition); _contextData = new Dictionary <string, object>( _definition.ContextData); _definition = null; }
private void ConfigureEnumValue( EnumValueDefinition definition, ISortingNamingConvention convention) { switch (definition.Value) { case SortOperationKind.Asc: definition.Name = convention.SortKindAscName; break; case SortOperationKind.Desc: definition.Name = convention.SortKindDescName; break; } }
/// <summary> /// Initializes a new instance of the <see cref="EnumerationGraphType"/> class. /// </summary> public EnumerationGraphType() { var type = typeof(TEnum); var names = Enum.GetNames(type); var enumMembers = names.Select(n => (name: n, member: type .GetMember(n, BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly) .First())); var enumGraphData = enumMembers.Select(e => ( name: ChangeEnumCase(e.name), value: Enum.Parse(type, e.name), description: e.member.Description(), deprecation: e.member.ObsoleteMessage(), member: e.member )); Name = type.Name.ToPascalCase(); Description ??= typeof(TEnum).Description(); DeprecationReason ??= typeof(TEnum).ObsoleteMessage(); foreach (var(name, value, description, deprecation, member) in enumGraphData) { var enumValue = new EnumValueDefinition(name, value) { Description = description, DeprecationReason = deprecation, }; bool ignore = false; foreach (var attr in member.GetCustomAttributes <GraphQLAttribute>()) { if (!attr.ShouldInclude(member, null)) { ignore = true; break; } attr.Modify(enumValue); } if (ignore) { continue; } Add(enumValue); } foreach (var attr in type.GetCustomAttributes <GraphQLAttribute>()) { attr.Modify(this); } }
public EnumValueEditor(Value value, int x, int y) : base(value, x, y) { Definition = (EnumValueDefinition)value.Definition; InitializeComponent(); nameLabel.Text = Definition.Name; //Init the combo box for (int i = 0; i < Definition.Elements.Length; i++) { valueComboBox.Items.Add(Definition.Elements[i]); if (Value.Content == Definition.Elements[i]) { valueComboBox.SelectedIndex = i; } } }