//// TODO: we need to refactor this to comply with FxCop private CodeTypeDeclaration GenEntityContainerInnerClass(CodeTypeDeclaration proxyClass, IEnumerable <Type> entityTypes, DomainServiceDescription domainServiceDescription) { // ---------------------------------------------------------------- // class xxxEntityContainer : EntityContainer // ---------------------------------------------------------------- string containingNamespace = this.ClientProxyGenerator.GetNamespace(proxyClass).Name; var innerClass = CodeGenUtilities.CreateTypeDeclaration(proxyClass.Name + "EntityContainer", containingNamespace); innerClass.BaseTypes.Add(CodeGenUtilities.GetTypeReference(TypeConstants.EntityContainerTypeFullName, containingNamespace, false)); innerClass.TypeAttributes = TypeAttributes.NotPublic | TypeAttributes.Sealed; proxyClass.Members.Add(innerClass); // ---------------------------------------------------------------- // ctor // ---------------------------------------------------------------- var ctor = new CodeConstructor(); ctor.Attributes = MemberAttributes.Public; innerClass.Members.Add(ctor); // Convert to a set for faster lookups. HashSet <Type> entityTypesToUse = new HashSet <Type>(); foreach (Type entityType in entityTypes) { entityTypesToUse.Add(entityType); } // ---------------------------------------------------------------- // each entity type gets 'CreateEntitySet<entityType>()' statement in ctor // ---------------------------------------------------------------- foreach (Type entityType in entityTypes.OrderBy(t => t.FullName)) { // Skip entity types which have base classes. if (entityTypesToUse.Any(t => t != entityType && t.IsAssignableFrom(entityType))) { continue; } // ---------------------------------------------------------------- // Build EntitySetOperations enum value // ---------------------------------------------------------------- var enumTypeReference = CodeGenUtilities.GetTypeReference(TypeConstants.EntitySetOperationsTypeFullName, containingNamespace, false); CodeExpression entitySetOperations = null; // Check to see what update operations are supported, and build up the EntitySetOperations flags expression bool canInsert = domainServiceDescription.IsOperationSupported(entityType, DomainOperation.Insert); bool canEdit = domainServiceDescription.IsOperationSupported(entityType, DomainOperation.Update); bool canDelete = domainServiceDescription.IsOperationSupported(entityType, DomainOperation.Delete); CodeTypeReferenceExpression enumTypeReferenceExp = new CodeTypeReferenceExpression(enumTypeReference); if (!canInsert && !canEdit && !canDelete) { // if no update operations are supported, set to 'None' entitySetOperations = new CodeFieldReferenceExpression(enumTypeReferenceExp, "None"); } else if (canInsert && canEdit && canDelete) { // if all operations are supported, set to 'All' entitySetOperations = new CodeFieldReferenceExpression(enumTypeReferenceExp, "All"); } else { if (canInsert) { entitySetOperations = new CodeFieldReferenceExpression(enumTypeReferenceExp, "Add"); } if (canEdit) { CodeFieldReferenceExpression setOp = new CodeFieldReferenceExpression(enumTypeReferenceExp, "Edit"); if (entitySetOperations == null) { entitySetOperations = setOp; } else { entitySetOperations = new CodeBinaryOperatorExpression(entitySetOperations, CodeBinaryOperatorType.BitwiseOr, setOp); } } if (canDelete) { CodeFieldReferenceExpression setOp = new CodeFieldReferenceExpression(enumTypeReferenceExp, "Remove"); if (entitySetOperations == null) { entitySetOperations = setOp; } else { entitySetOperations = new CodeBinaryOperatorExpression(entitySetOperations, CodeBinaryOperatorType.BitwiseOr, setOp); } } } // ---------------------------------------------------------------- // method call: this.CreateEntitySet<entityType> // ---------------------------------------------------------------- var entityTypeReference = CodeGenUtilities.GetTypeReference(entityType, this.ClientProxyGenerator, proxyClass); var methodRef = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "CreateEntitySet", entityTypeReference); var methodCall = new CodeMethodInvokeExpression(methodRef, entitySetOperations); ctor.Statements.Add(methodCall); } return(innerClass); }