当前位置: 首页>>代码示例>>C#>>正文


C# CodeGenerationContext.GetPrefixedFullName方法代码示例

本文整理汇总了C#中CodeGenerationContext.GetPrefixedFullName方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerationContext.GetPrefixedFullName方法的具体用法?C# CodeGenerationContext.GetPrefixedFullName怎么用?C# CodeGenerationContext.GetPrefixedFullName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeGenerationContext的用法示例。


在下文中一共展示了CodeGenerationContext.GetPrefixedFullName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClrTypeName

        /// <summary>
        /// Gets the clr type name from the give type reference.
        /// </summary>
        /// <param name="edmTypeReference">The type reference in question.</param>
        /// <param name="useDataServiceCollection">true to use the DataServicCollection type for entity collections and the ObservableCollection type for non-entity collections,
        /// false to use Collection for collections.</param>
        /// <param name="clientTemplate">ODataClientTemplate instance that call this method.</param>
        /// <param name="context">CodeGenerationContext instance in the clientTemplate.</param>
        /// <param name="addNullableTemplate">This flag indicates whether to return the type name in nullable format</param>
        /// <param name="needGlobalPrefix">The flag indicates whether the namespace need to be added by global prefix</param>
        /// <param name="isOperationParameter">This flag indicates whether the edmTypeReference is for an operation parameter</param>
        /// <returns>The clr type name of the type reference.</returns>
        internal static string GetClrTypeName(IEdmTypeReference edmTypeReference, bool useDataServiceCollection, ODataClientTemplate clientTemplate, CodeGenerationContext context, bool addNullableTemplate = true, bool needGlobalPrefix = true, bool isOperationParameter = false)
        {
            string clrTypeName;
            var edmType = edmTypeReference.Definition;
            var edmPrimitiveType = edmType as IEdmPrimitiveType;
            if (edmPrimitiveType != null)
            {
                clrTypeName = GetClrTypeName(edmPrimitiveType, clientTemplate);
                if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(edmPrimitiveType.PrimitiveKind) && addNullableTemplate)
                {
                    clrTypeName = string.Format(clientTemplate.SystemNullableStructureTemplate, clrTypeName);
                }
            }
            else
            {
                var edmComplexType = edmType as IEdmComplexType;
                if (edmComplexType != null)
                {
                    clrTypeName = context.GetPrefixedFullName(edmComplexType,
                        context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmComplexType.Name)) : clientTemplate.GetFixedName(edmComplexType.Name), clientTemplate);
                }
                else
                {
                    var edmEnumType = edmType as IEdmEnumType;
                    if (edmEnumType != null)
                    {
                        clrTypeName = context.GetPrefixedFullName(edmEnumType,
                            context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEnumType.Name)) : clientTemplate.GetFixedName(edmEnumType.Name), clientTemplate, needGlobalPrefix);
                        if (edmTypeReference.IsNullable && addNullableTemplate)
                        {
                            clrTypeName = string.Format(clientTemplate.SystemNullableStructureTemplate, clrTypeName);
                        }
                    }
                    else
                    {
                        var edmEntityType = edmType as IEdmEntityType;
                        if (edmEntityType != null)
                        {
                            clrTypeName = context.GetPrefixedFullName(edmEntityType,
                                context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate);
                        }
                        else
                        {
                            var edmCollectionType = (IEdmCollectionType)edmType;
                            var elementTypeReference = edmCollectionType.ElementType;
                            var primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType;
                            if (primitiveElementType != null)
                            {
                                clrTypeName = GetClrTypeName(primitiveElementType, clientTemplate);
                            }
                            else
                            {
                                var schemaElement = (IEdmSchemaElement)elementTypeReference.Definition;
                                clrTypeName = context.GetPrefixedFullName(schemaElement,
                                    context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(schemaElement.Name)) : clientTemplate.GetFixedName(schemaElement.Name), clientTemplate);
                            }

                            var collectionTypeName = isOperationParameter
                                ? clientTemplate.CollectionOfTStructureTemplate
                                : (useDataServiceCollection
                                    ? (elementTypeReference.TypeKind() == EdmTypeKind.Entity
                                        ? clientTemplate.DataServiceCollectionStructureTemplate
                                        : clientTemplate.ObservableCollectionStructureTemplate)
                                    : clientTemplate.ObjectModelCollectionStructureTemplate);

                            clrTypeName = string.Format(collectionTypeName, clrTypeName);
                        }
                    }
                }
            }

            return clrTypeName;
        }
开发者ID:meancrazy,项目名称:LINQPadOData4,代码行数:85,代码来源:Utils.cs


注:本文中的CodeGenerationContext.GetPrefixedFullName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。