Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DLinq / Dlinq / SqlClient / Query / SqlExpressionNullability.cs / 1 / SqlExpressionNullability.cs
using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Text; using System.Linq; using System.Linq.Expressions; using System.Data.Linq; using System.Data.Linq.Provider; using System.Diagnostics.CodeAnalysis; namespace System.Data.Linq.SqlClient { internal static class SqlExpressionNullability { ////// Determines whether the given expression may return a null result. /// /// The expression to check. ///null means that it couldn't be determined [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification="These issues are related to our use of if-then and case statements for node types, which adds to the complexity count however when reviewed they are easy to navigate and understand.")] internal static bool? CanBeNull(SqlExpression expr) { switch (expr.NodeType) { case SqlNodeType.ExprSet: SqlExprSet exprSet = (SqlExprSet)expr; return CanBeNull(exprSet.Expressions); case SqlNodeType.SimpleCase: SqlSimpleCase sc = (SqlSimpleCase)expr; return CanBeNull(sc.Whens.Select(w => w.Value)); case SqlNodeType.Column: SqlColumn col = (SqlColumn)expr; if (col.MetaMember != null) { return col.MetaMember.CanBeNull; } else if (col.Expression != null) { return CanBeNull(col.Expression); } return null; // Don't know. case SqlNodeType.ColumnRef: SqlColumnRef cref = (SqlColumnRef)expr; return CanBeNull(cref.Column); case SqlNodeType.Value: return ((SqlValue)expr).Value == null; case SqlNodeType.New: case SqlNodeType.Multiset: case SqlNodeType.Grouping: case SqlNodeType.ObjectType: case SqlNodeType.DiscriminatedType: case SqlNodeType.IsNotNull: // IsNull\IsNotNull always return true or false and can never return NULL. case SqlNodeType.IsNull: case SqlNodeType.Exists: return false; case SqlNodeType.Add: case SqlNodeType.Sub: case SqlNodeType.Mul: case SqlNodeType.Div: case SqlNodeType.Mod: case SqlNodeType.BitAnd: case SqlNodeType.BitOr: case SqlNodeType.BitXor: case SqlNodeType.Concat: { SqlBinary bop = (SqlBinary)expr; bool? left = CanBeNull(bop.Left); bool? right = CanBeNull(bop.Right); return (left != false) || (right != false); } case SqlNodeType.Negate: case SqlNodeType.BitNot: { SqlUnary uop = (SqlUnary)expr; return CanBeNull(uop.Operand); } case SqlNodeType.Lift: { SqlLift lift = (SqlLift)expr; return CanBeNull(lift.Expression); } case SqlNodeType.OuterJoinedValue: return true; default: return null; // Don't know. } } ////// Used to determine nullability for a collection of expressions. /// * If at least one of the expressions is nullable, the collection is nullable. /// * If no expressions are nullable, but at least one is 'don't know', the collection is 'don't know'. /// * Otherwise all expressions are non-nullable and the nullability is false. /// private static bool? CanBeNull(IEnumerableexprs) { bool hasAtleastOneUnknown = false; foreach(SqlExpression e in exprs) { bool? nullability = CanBeNull(e); // Even one expression that could return null means the // collection can return null. if (nullability == true) return true; // If there is one or more 'unknown' and no definitely nullable // results then the collection nullability is 'unknown'. if (nullability == null) hasAtleastOneUnknown = true; } if (hasAtleastOneUnknown) return null; return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Text; using System.Linq; using System.Linq.Expressions; using System.Data.Linq; using System.Data.Linq.Provider; using System.Diagnostics.CodeAnalysis; namespace System.Data.Linq.SqlClient { internal static class SqlExpressionNullability { /// /// Determines whether the given expression may return a null result. /// /// The expression to check. ///null means that it couldn't be determined [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification="These issues are related to our use of if-then and case statements for node types, which adds to the complexity count however when reviewed they are easy to navigate and understand.")] internal static bool? CanBeNull(SqlExpression expr) { switch (expr.NodeType) { case SqlNodeType.ExprSet: SqlExprSet exprSet = (SqlExprSet)expr; return CanBeNull(exprSet.Expressions); case SqlNodeType.SimpleCase: SqlSimpleCase sc = (SqlSimpleCase)expr; return CanBeNull(sc.Whens.Select(w => w.Value)); case SqlNodeType.Column: SqlColumn col = (SqlColumn)expr; if (col.MetaMember != null) { return col.MetaMember.CanBeNull; } else if (col.Expression != null) { return CanBeNull(col.Expression); } return null; // Don't know. case SqlNodeType.ColumnRef: SqlColumnRef cref = (SqlColumnRef)expr; return CanBeNull(cref.Column); case SqlNodeType.Value: return ((SqlValue)expr).Value == null; case SqlNodeType.New: case SqlNodeType.Multiset: case SqlNodeType.Grouping: case SqlNodeType.ObjectType: case SqlNodeType.DiscriminatedType: case SqlNodeType.IsNotNull: // IsNull\IsNotNull always return true or false and can never return NULL. case SqlNodeType.IsNull: case SqlNodeType.Exists: return false; case SqlNodeType.Add: case SqlNodeType.Sub: case SqlNodeType.Mul: case SqlNodeType.Div: case SqlNodeType.Mod: case SqlNodeType.BitAnd: case SqlNodeType.BitOr: case SqlNodeType.BitXor: case SqlNodeType.Concat: { SqlBinary bop = (SqlBinary)expr; bool? left = CanBeNull(bop.Left); bool? right = CanBeNull(bop.Right); return (left != false) || (right != false); } case SqlNodeType.Negate: case SqlNodeType.BitNot: { SqlUnary uop = (SqlUnary)expr; return CanBeNull(uop.Operand); } case SqlNodeType.Lift: { SqlLift lift = (SqlLift)expr; return CanBeNull(lift.Expression); } case SqlNodeType.OuterJoinedValue: return true; default: return null; // Don't know. } } ////// Used to determine nullability for a collection of expressions. /// * If at least one of the expressions is nullable, the collection is nullable. /// * If no expressions are nullable, but at least one is 'don't know', the collection is 'don't know'. /// * Otherwise all expressions are non-nullable and the nullability is false. /// private static bool? CanBeNull(IEnumerableexprs) { bool hasAtleastOneUnknown = false; foreach(SqlExpression e in exprs) { bool? nullability = CanBeNull(e); // Even one expression that could return null means the // collection can return null. if (nullability == true) return true; // If there is one or more 'unknown' and no definitely nullable // results then the collection nullability is 'unknown'. if (nullability == null) hasAtleastOneUnknown = true; } if (hasAtleastOneUnknown) return null; return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Highlights.cs
- ToolStripPanel.cs
- ManipulationPivot.cs
- ByeMessageApril2005.cs
- RefType.cs
- ToolStripScrollButton.cs
- KeyInfo.cs
- ADConnectionHelper.cs
- SmiXetterAccessMap.cs
- ExtensionWindowResizeGrip.cs
- EntityCommandDefinition.cs
- OledbConnectionStringbuilder.cs
- DbException.cs
- XmlElementAttributes.cs
- PrintPageEvent.cs
- FontWeightConverter.cs
- ADRoleFactoryConfiguration.cs
- OleDbEnumerator.cs
- TextEmbeddedObject.cs
- ComponentManagerBroker.cs
- ExpressionLexer.cs
- OneOfScalarConst.cs
- CatalogZone.cs
- RedBlackList.cs
- WebRequestModuleElement.cs
- DesignerActionUIStateChangeEventArgs.cs
- QueryPrefixOp.cs
- ElementMarkupObject.cs
- ProxyWebPartConnectionCollection.cs
- MailSettingsSection.cs
- RequiredFieldValidator.cs
- Clock.cs
- NumericUpDownAccelerationCollection.cs
- ImageInfo.cs
- WrappedIUnknown.cs
- RegexGroupCollection.cs
- XmlWrappingReader.cs
- WhitespaceRule.cs
- Zone.cs
- LocalBuilder.cs
- DataGridViewRowCancelEventArgs.cs
- CodeRegionDirective.cs
- StructuredTypeInfo.cs
- WebPartVerbCollection.cs
- MsmqUri.cs
- _Connection.cs
- PresentationAppDomainManager.cs
- ToolStripSeparatorRenderEventArgs.cs
- XhtmlBasicImageAdapter.cs
- ModuleElement.cs
- CodeMethodReturnStatement.cs
- XmlCustomFormatter.cs
- HtmlInputHidden.cs
- ActivityCodeDomReferenceService.cs
- SettingsPropertyNotFoundException.cs
- LiteralLink.cs
- AssociationSetMetadata.cs
- RunClient.cs
- CodeRemoveEventStatement.cs
- SelectionPatternIdentifiers.cs
- CompModSwitches.cs
- dsa.cs
- UserControlAutomationPeer.cs
- XmlQueryCardinality.cs
- FacetValueContainer.cs
- ProfileManager.cs
- SQLUtility.cs
- CopyAction.cs
- SessionStateSection.cs
- Effect.cs
- ThicknessConverter.cs
- XmlSchemaIdentityConstraint.cs
- DataGridPagingPage.cs
- NewItemsContextMenuStrip.cs
- SmiEventSink.cs
- HybridDictionary.cs
- BindToObject.cs
- GeneralTransform2DTo3DTo2D.cs
- InkCanvasAutomationPeer.cs
- remotingproxy.cs
- ReachSerializationCacheItems.cs
- WebRequestModuleElement.cs
- ExpressionCopier.cs
- UTF7Encoding.cs
- StylusPointPropertyInfo.cs
- TextRangeEdit.cs
- X509Utils.cs
- PointValueSerializer.cs
- CacheDependency.cs
- TransportContext.cs
- PropertyCollection.cs
- FixedTextView.cs
- OuterGlowBitmapEffect.cs
- UIElement3DAutomationPeer.cs
- ToolboxItemAttribute.cs
- ListControl.cs
- WindowsUserNameCachingSecurityTokenAuthenticator.cs
- CanExecuteRoutedEventArgs.cs
- ExpandableObjectConverter.cs
- Literal.cs