{"record":{"id":"1ef5baeed23a1dc2","repo":"dotnet/maui","slug":"cannot-convert-self-to-nameof-effectiveflowdire","errorCode":null,"errorMessage":"Cannot convert {self} to {nameof(EffectiveFlowDirection)}.","messagePattern":"Cannot convert (.+?) to (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/EffectiveFlowDirectionExtensions.cs","lineNumber":38,"sourceCode":"\t\t\t\t\t\treturn EffectiveFlowDirection.Explicit;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\treturn default(EffectiveFlowDirection);\n\t\t\t\t\t}\n\n\t\t\t\tcase FlowDirection.RightToLeft:\n\t\t\t\t\tif (isExplicit)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn EffectiveFlowDirection.RightToLeft | EffectiveFlowDirection.Explicit;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\treturn EffectiveFlowDirection.RightToLeft;\n\t\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new InvalidOperationException($\"Cannot convert {self} to {nameof(EffectiveFlowDirection)}.\");\n\t\t\t}\n\t\t}\n\n\t\tinternal static FlowDirection ToFlowDirection(this EffectiveFlowDirection self)\n\t\t{\n\t\t\tif (self.IsLeftToRight())\n\t\t\t\treturn FlowDirection.LeftToRight;\n\t\t\telse\n\t\t\t\treturn FlowDirection.RightToLeft;\n\n\t\t\tthrow new InvalidOperationException($\"Cannot convert {self} to {nameof(FlowDirection)}.\");\n\t\t}\n\n\t\t/// <summary>Returns <see langword=\"true\"/> if the flow direction is right-to-left. Otherwise, returns <see langword=\"false\"/>.</summary>\n\t\t/// <param name=\"self\">The enumeration value on which this method operates.</param>\n\t\t/// <returns><see langword=\"true\"/> if the flow direction is right-to-left. Otherwise, <see langword=\"false\"/>.</returns>\n\t\tpublic static bool IsRightToLeft(this EffectiveFlowDirection self)\n\t\t{","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/EffectiveFlowDirectionExtensions.cs#L20-L56","documentation":"ToEffectiveFlowDirection switches over the FlowDirection enum (MatchParent, LeftToRight, RightToLeft) and maps each to an EffectiveFlowDirection. The default branch throws InvalidOperationException for any FlowDirection value not in that set — reachable only if the enum is cast from an invalid integer or a future/undefined member.","triggerScenarios":"Casting an arbitrary/invalid integer to FlowDirection (e.g. (FlowDirection)99) and converting it; reflection or deserialization producing an out-of-range enum value.","commonSituations":"Deserialization binding a numeric value to a FlowDirection property; (FlowDirection) casts from untrusted input; enum defined with [Flags] misuse.","solutions":["Validate the FlowDirection value with Enum.IsDefined before converting.","Ensure serialized/bound data only contains defined FlowDirection members.","Default unknown values to FlowDirection.MatchParent instead of casting raw integers."],"exampleFix":"// before\nvar efd = ((FlowDirection)99).ToEffectiveFlowDirection(); // default branch throws\n\n// after\nFlowDirection fd = (FlowDirection)99;\nif (!Enum.IsDefined(typeof(FlowDirection), fd)) fd = FlowDirection.MatchParent;\nvar efd = fd.ToEffectiveFlowDirection();","handlingStrategy":"validation","validationCode":"static bool IsValidFlowDirection(FlowDirection fd) => Enum.IsDefined(typeof(FlowDirection), fd);\n// usage:\nif (!IsValidFlowDirection(fd)) fd = FlowDirection.MatchParent;","typeGuard":"static bool IsDefinedFlowDirection(FlowDirection fd) => Enum.IsDefined(typeof(FlowDirection), fd);","tryCatchPattern":null,"preventionTips":["Never cast arbitrary integers to FlowDirection.","Validate deserialized enum values with Enum.IsDefined.","Default unknown values to FlowDirection.MatchParent."],"tags":["flowdirection","enum","invalidoperation","rtl"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}