コード例 #1
0
        /// <summary>
        /// Emit the attributes for the new navigation property
        /// </summary>
        /// <param name="generator">The ClientApiGenerator instance</param>
        /// <param name="targetRelationshipEnd">The relationship end that is being targeted</param>
        /// <param name="propertyDecl">The property declaration to attach the attribute to.</param>
        /// <param name="additionalAttributes">Additional attributes</param>
        public void EmitNavigationPropertyAttributes(ClientApiGenerator generator,
                                                     RelationshipEndMember targetRelationshipEnd,
                                                     CodeMemberProperty propertyDecl,
                                                     List <CodeAttributeDeclaration> additionalAttributes)
        {
            CodeAttributeDeclaration attribute = EmitSimpleAttribute(FQAdoFrameworkDataClassesName("EdmRelationshipNavigationPropertyAttribute"),
                                                                     targetRelationshipEnd.DeclaringType.NamespaceName,
                                                                     targetRelationshipEnd.DeclaringType.Name,
                                                                     targetRelationshipEnd.Name);

            propertyDecl.CustomAttributes.Add(attribute);
            EmitGeneratedCodeAttribute(propertyDecl);
            if (additionalAttributes != null && additionalAttributes.Count > 0)
            {
                try
                {
                    propertyDecl.CustomAttributes.AddRange(additionalAttributes.ToArray());
                }
                catch (ArgumentNullException e)
                {
                    generator.AddError(Strings.InvalidAttributeSuppliedForProperty(propertyDecl.Name),
                                       ModelBuilderErrorCode.InvalidAttributeSuppliedForProperty,
                                       EdmSchemaErrorSeverity.Error,
                                       e);
                }
            }
        }
コード例 #2
0
 private void EmitKnownTypeAttributes(EdmType baseType, ClientApiGenerator generator, CodeTypeDeclaration typeDecl)
 {
     foreach (EdmType edmType in generator.GetDirectSubTypes(baseType))
     {
         Debug.Assert(edmType.BaseType == baseType, "The types must be directly derived from basetype");
         
         CodeTypeReference subTypeRef;
         if (generator.Language == LanguageOption.GenerateCSharpCode)
         {
             bool useGlobalPrefix = true;
             subTypeRef = generator.GetFullyQualifiedTypeReference(edmType, useGlobalPrefix);
         }
         else
         {
             Debug.Assert(generator.Language == LanguageOption.GenerateVBCode, "Did you add a new language?");
             subTypeRef = generator.GetLeastPossibleQualifiedTypeReference(edmType);
         }
         CodeAttributeDeclaration attribute = EmitSimpleAttribute("System.Runtime.Serialization.KnownTypeAttribute", new CodeTypeOfExpression(subTypeRef));
         typeDecl.CustomAttributes.Add(attribute);
     }
 }
コード例 #3
0
        private void EmitKnownTypeAttributes(EdmType baseType, ClientApiGenerator generator, CodeTypeDeclaration typeDecl)
        {
            foreach (EdmType edmType in generator.GetDirectSubTypes(baseType))
            {
                Debug.Assert(edmType.BaseType == baseType, "The types must be directly derived from basetype");

                CodeTypeReference subTypeRef;
                if (generator.Language == LanguageOption.GenerateCSharpCode)
                {
                    bool useGlobalPrefix = true;
                    subTypeRef = generator.GetFullyQualifiedTypeReference(edmType, useGlobalPrefix);
                }
                else
                {
                    Debug.Assert(generator.Language == LanguageOption.GenerateVBCode, "Did you add a new language?");
                    subTypeRef = generator.GetLeastPossibleQualifiedTypeReference(edmType);
                }
                CodeAttributeDeclaration attribute = EmitSimpleAttribute("System.Runtime.Serialization.KnownTypeAttribute", new CodeTypeOfExpression(subTypeRef));
                typeDecl.CustomAttributes.Add(attribute);
            }
        }
コード例 #4
0
ファイル: EntityClassGenerator.cs プロジェクト: ash2005/z
        private IList <EdmSchemaError> GenerateCode(XmlReader sourceReader, LazyTextWriterCreator target, string namespacePrefix)
        {
            List <XmlReader>      readers        = CreateReaders(sourceReader);
            List <EdmSchemaError> errors         = new List <EdmSchemaError>();
            EdmItemCollection     itemCollection = new EdmItemCollection(readers);

#if QFE_ENV
            _version = _versionExplicitlySet ? _version : GetDataServiceCodeVersionFromEnvironment();
            _useDataServiceCollection = _useDataServiceCollectionExplicitlySet ? _useDataServiceCollection : GetUseDataServiceCollectionFromEnvironment();
#endif
            if (_useDataServiceCollection && _version == DataServiceCodeVersion.V1)
            {
                throw new InvalidOperationException(Strings.VersionV1RequiresUseDataServiceCollectionFalse);
            }

            // generate code
            using (ClientApiGenerator generator = new ClientApiGenerator(null, itemCollection, this, errors, namespacePrefix))
            {
                generator.GenerateCode(target);
            }

            return(errors);
        }
コード例 #5
0
ファイル: NamespaceEmitter.cs プロジェクト: dox0/DotNet471RS3
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 public NamespaceEmitter(ClientApiGenerator generator, string namespacePrefix, string targetFilePath)
     : base(generator)
 {
     _targetFilePath  = targetFilePath != null ? targetFilePath : string.Empty;
     _namespacePrefix = namespacePrefix;
 }
コード例 #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="schemaType"></param>
 protected SchemaTypeEmitter(ClientApiGenerator generator, MetadataItem item)
 : base(generator, item)
 {
 }
コード例 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="navigationProperty"></param>
 public NavigationPropertyEmitter(ClientApiGenerator generator, NavigationProperty navigationProperty, bool declaringTypeUsesStandardBaseType)
     : base(generator, navigationProperty, declaringTypeUsesStandardBaseType)
 {
 }
コード例 #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="nestedType"></param>
 public ComplexTypeEmitter(ClientApiGenerator generator, ComplexType complexType)
     : base(generator, complexType)
 {
 }
コード例 #9
0
 protected PropertyEmitterBase(ClientApiGenerator generator, MetadataItem item, bool declaringTypeUsesStandardBaseType)
     : base(generator, item)
 {
     Debug.Assert(item != null, "item is null");
     _declaringTypeUsesStandardBaseType = declaringTypeUsesStandardBaseType;
 }
コード例 #10
0
 protected MetadataItemEmitter(ClientApiGenerator generator, MetadataItem item)
     :base(generator)
 {
     Debug.Assert(item != null, "item is null");
     _item = item;
 }
コード例 #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="navigationProperty"></param>
 public NavigationPropertyEmitter(ClientApiGenerator generator, NavigationProperty navigationProperty, bool declaringTypeUsesStandardBaseType)
     : base(generator, navigationProperty, declaringTypeUsesStandardBaseType)
 {
 }
コード例 #12
0
ファイル: PropertyEmitter.cs プロジェクト: dox0/DotNet471RS3
 public PropertyTypeReferences(TypeReference typeReference, ComplexType complexType, ClientApiGenerator generator)
     : this(typeReference, complexType, CollectionKind.None, generator)
 {
 }
コード例 #13
0
ファイル: PropertyEmitter.cs プロジェクト: dox0/DotNet471RS3
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="property"></param>
 public PropertyEmitter(ClientApiGenerator generator, EdmProperty property, bool declaringTypeUsesStandardBaseType)
     : base(generator, property, declaringTypeUsesStandardBaseType)
 {
 }
コード例 #14
0
ファイル: EntityTypeEmitter.cs プロジェクト: JianwenSun/cc
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="itemType"></param>
 public EntityTypeEmitter(ClientApiGenerator generator, EntityType entity)
     : base(generator, entity)
 {
 }
コード例 #15
0
 public AssociationTypeEmitter(ClientApiGenerator generator, AssociationType associationType)
     : base(generator, associationType)
 {
 }
コード例 #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="structuredType"></param>
 protected StructuredTypeEmitter(ClientApiGenerator generator, StructuralType structuralType)
     : base(generator, structuralType)
 {
 }
コード例 #17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="structuredType"></param>
 protected StructuredTypeEmitter(ClientApiGenerator generator, StructuralType structuralType)
     : base(generator, structuralType)
 {
 }
コード例 #18
0
 protected MetadataItemEmitter(ClientApiGenerator generator, MetadataItem item)
     : base(generator)
 {
     Debug.Assert(item != null, "item is null");
     _item = item;
 }
コード例 #19
0
ファイル: Emitter.cs プロジェクト: uQr/referencesource
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 protected Emitter(ClientApiGenerator generator)
 {
     Generator = generator;
 }
コード例 #20
0
 public AssociationTypeEmitter(ClientApiGenerator generator, AssociationType associationType)
     : base(generator, associationType)
 {
 }
コード例 #21
0
ファイル: PropertyEmitter.cs プロジェクト: dox0/DotNet471RS3
            public PropertyTypeReferences(TypeReference typeReference, ComplexType complexType, CollectionKind collectionKind, ClientApiGenerator generator)
            {
                CodeTypeReference baseType = generator.GetLeastPossibleQualifiedTypeReference(complexType);

                baseType     = GetCollectionTypeReference(typeReference, baseType, collectionKind);
                _nonNullable = baseType;
                _nullable    = baseType;
            }
コード例 #22
0
ファイル: EntityTypeEmitter.cs プロジェクト: ash2005/z
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="itemType"></param>
 public EntityTypeEmitter(ClientApiGenerator generator, EntityType entity)
     : base(generator, entity)
 {
 }
コード例 #23
0
        private void GenerateCodeCommon(MetadataArtifactLoader sourceLoader,
                                        List <MetadataArtifactLoader> loaders,
                                        LazyTextWriterCreator target,
                                        string sourceEdmSchemaFilePath,
                                        string targetFilePath,
                                        bool closeReaders,
                                        List <EdmSchemaError> errors)
        {
            MetadataArtifactLoaderComposite composite = new MetadataArtifactLoaderComposite(loaders);

            // create the schema manager from the xml readers
            Dictionary <MetadataArtifactLoader, XmlReader> readerSourceMap = new Dictionary <MetadataArtifactLoader, XmlReader>();
            IList <Schema>   schemas;
            List <XmlReader> readers = composite.GetReaders(readerSourceMap);

            try
            {
                IList <EdmSchemaError> schemaManagerErrors =
                    SchemaManager.ParseAndValidate(readers,
                                                   composite.GetPaths(),
                                                   SchemaDataModelOption.EntityDataModel,
                                                   EdmProviderManifest.Instance,
                                                   out schemas);
                errors.AddRange(schemaManagerErrors);
            }
            finally
            {
                if (closeReaders)
                {
                    MetadataUtil.DisposeXmlReaders(readers);
                }
            }
            ThrowOnAnyNonWarningErrors(errors);
            Debug.Assert(readerSourceMap.ContainsKey(sourceLoader), "the source loader didn't produce any of the xml readers...");
            XmlReader sourceReader = readerSourceMap[sourceLoader];


            // use the index of the "source" xml reader as the index of the "source" schema
            Debug.Assert(readers.Contains(sourceReader), "the source reader is not in the list of readers");
            int index = readers.IndexOf(sourceReader);

            Debug.Assert(index >= 0, "couldn't find the source reader in the list of readers");

            Debug.Assert(readers.Count == schemas.Count, "We have a different number of readers than schemas");
            Schema sourceSchema = schemas[index];

            Debug.Assert(sourceSchema != null, "sourceSchema is null");

            // create the EdmItemCollection from the schemas
            EdmItemCollection itemCollection = new EdmItemCollection(schemas);

            if (EntityFrameworkVersionsUtil.ConvertToVersion(itemCollection.EdmVersion) >= EntityFrameworkVersions.Version2)
            {
                throw EDesignUtil.InvalidOperation(Strings.TargetEntityFrameworkVersionToNewForEntityClassGenerator);
            }

            // generate code
            ClientApiGenerator generator = new ClientApiGenerator(sourceSchema, itemCollection, this, errors);

            generator.GenerateCode(target, targetFilePath);
        }
コード例 #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="nestedType"></param>
 public ComplexTypeEmitter(ClientApiGenerator generator, ComplexType complexType)
     : base(generator, complexType)
 {
 }
コード例 #25
0
 protected PropertyEmitterBase(ClientApiGenerator generator, MetadataItem item, bool declaringTypeUsesStandardBaseType)
     : base(generator, item)
 {
     Debug.Assert(item != null, "item is null");
     _declaringTypeUsesStandardBaseType = declaringTypeUsesStandardBaseType;
 }
コード例 #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="schemaType"></param>
 protected SchemaTypeEmitter(ClientApiGenerator generator, MetadataItem item)
     : base(generator, item)
 {
 }
コード例 #27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="entityContainer"></param>
 public EntityContainerEmitter(ClientApiGenerator generator, EntityContainer entityContainer)
     : base(generator, entityContainer)
 {
 }
コード例 #28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="entityContainer"></param>
 public EntityContainerEmitter(ClientApiGenerator generator, EntityContainer entityContainer)
     : base(generator, entityContainer)
 {
 }
コード例 #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 public NamespaceEmitter(ClientApiGenerator generator, string codeNamespace, string targetFilePath)
     : base(generator)
 {
     _codeNamespace  = codeNamespace;
     _targetFilePath = targetFilePath != null ? targetFilePath : string.Empty;
 }
コード例 #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="generator"></param>
 protected Emitter(ClientApiGenerator generator)
 {
     Generator = generator;
 }
コード例 #31
0
        /// <summary>
        /// Emit the attributes for the new navigation property
        /// </summary>
        /// <param name="generator">The ClientApiGenerator instance</param>
        /// <param name="targetRelationshipEnd">The relationship end that is being targeted</param>
        /// <param name="propertyDecl">The property declaration to attach the attribute to.</param>
        /// <param name="additionalAttributes">Additional attributes</param>
        public void EmitNavigationPropertyAttributes(ClientApiGenerator generator,
                                                     RelationshipEndMember targetRelationshipEnd, 
                                                     CodeMemberProperty propertyDecl,
                                                     List<CodeAttributeDeclaration> additionalAttributes)
        {
            CodeAttributeDeclaration attribute = EmitSimpleAttribute(FQAdoFrameworkDataClassesName("EdmRelationshipNavigationPropertyAttribute"),
                targetRelationshipEnd.DeclaringType.NamespaceName,
                targetRelationshipEnd.DeclaringType.Name,
                targetRelationshipEnd.Name);

            propertyDecl.CustomAttributes.Add(attribute);
            EmitGeneratedCodeAttribute(propertyDecl);
            if (additionalAttributes != null && additionalAttributes.Count > 0)
            {
                try
                {
                    propertyDecl.CustomAttributes.AddRange(additionalAttributes.ToArray());
                }
                catch (ArgumentNullException e)
                {
                    generator.AddError(Strings.InvalidAttributeSuppliedForProperty(propertyDecl.Name),
                                       ModelBuilderErrorCode.InvalidAttributeSuppliedForProperty,
                                       EdmSchemaErrorSeverity.Error,
                                       e);
                }
            }
        }