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


C# CodeTypeDeclaration.ThrowIfNull方法代码示例

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


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

示例1: DecorateClass

        public void DecorateClass(CodeTypeDeclaration typeDeclaration,
            ISchema schema,
            IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
            INestedClassProvider internalClassProvider)
        {
            typeDeclaration.ThrowIfNull("typeDeclaration");
            schema.ThrowIfNull("schema");
            implDetails.ThrowIfNull("implDetails");
            internalClassProvider.ThrowIfNull("internalClassProvider");

            JsonSchema details = schema.SchemaDetails;
            details.ThrowIfNull("schemaDetails");

            // Check if this decorator can be applied to the schema);
            if (details.Type != JsonSchemaType.Array)
            {
                return;
            }

            if (details.Items == null || details.Items.Count != 1)
            {
                logger.Warning("Found array scheme of unhandled type. {0}", details);
                return; // not supported
            }

            // Generate or find the nested type
            JsonSchema itemScheme = details.Items[0];
            SchemaImplementationDetails implDetail = implDetails[itemScheme];
            implDetail.ProposedName = "Entry"; // Change the name to a custom one.
            CodeTypeReference item = SchemaDecoratorUtil.GetCodeType(itemScheme, implDetail, internalClassProvider);

            // Insert the base type before any interface declaration
            var baseType = string.Format("List<{0}>", item.BaseType);
            typeDeclaration.BaseTypes.Insert(0, new CodeTypeReference(baseType));
        }
开发者ID:nick0816,项目名称:LoggenCSG,代码行数:35,代码来源:ArraySchemaDecorator.cs

示例2: DecorateClass

 public void DecorateClass(IService service, CodeTypeDeclaration serviceClass)
 {
     serviceClass.ThrowIfNull("serviceClass");
     serviceClass.Members.Add(CreateRegisterSerializer());
     serviceClass.Members.Add(CreateObjectToJson());
     serviceClass.Members.Add(CreateResponseToObject());
 }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:7,代码来源:JsonSerializationMethods.cs

示例3: DecorateClass

        public void DecorateClass(IResource resource,
                                  string className,
                                  CodeTypeDeclaration resourceClass,
                                  ResourceClassGenerator generator,
                                  string serviceClassName,
                                  IEnumerable<IResourceDecorator> allDecorators)
        {
            resource.ThrowIfNull("resource");
            className.ThrowIfNull("className");
            resourceClass.ThrowIfNull("resourceClass");
            generator.ThrowIfNull("generator");
            serviceClassName.ThrowIfNull("serviceClassName");
            allDecorators.ThrowIfNull("allDecorators");

            if (!resource.IsServiceResource) // Only add subresources of normal resources, not the root resource.
            {
                // Add all subresources.
                foreach (IResource subresource in resource.Resources.Values)
                {
                    // Consider all members in the current class as invalid names.
                    var forbiddenWords = from CodeTypeMember m in resourceClass.Members select m.Name;

                    // Generate and add the subresource.
                    CodeTypeDeclaration decl = GenerateSubresource(
                        subresource, serviceClassName, allDecorators, generator.RequestGenerator,
                        generator.ContainerGenerator, forbiddenWords);
                    resourceClass.Members.Add(decl);
                }
            }
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:30,代码来源:SubresourceClassDecorator.cs

示例4: DecorateClass

 public void DecorateClass(CodeTypeDeclaration typeDeclaration,
                           ISchema schema,
                           IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
                           INestedClassProvider internalClassProvider)
 {
     typeDeclaration.ThrowIfNull("typeDeclaration");
     schema.ThrowIfNull("schema");
     implDetails.ThrowIfNull("details");
     internalClassProvider.ThrowIfNull("internalClassProvider");
     typeDeclaration.Members.AddRange(
         GenerateAllFields(schema.Name, schema.SchemaDetails, implDetails, internalClassProvider).ToArray());
 }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:12,代码来源:StandardPropertyFieldDecorator.cs

示例5: DecorateInternalClass

        public void DecorateInternalClass(CodeTypeDeclaration typeDeclaration,
                                          string name,
                                          JsonSchema schema,
                                          IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
                                          INestedClassProvider internalClassProvider)
        {
            typeDeclaration.ThrowIfNull("typeDeclaration");
            schema.ThrowIfNull("schema");
            implDetails.ThrowIfNull("details");
            internalClassProvider.ThrowIfNull("internalClassProvider");

            typeDeclaration.Comments.AddRange(CreateComment(schema));
        }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:13,代码来源:StandardSchemaCommentDecorator.cs

示例6: DecorateClass

        public void DecorateClass(CodeTypeDeclaration typeDeclaration,
            ISchema schema,
            IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
            INestedClassProvider internalClassProvider)
        {
            typeDeclaration.ThrowIfNull("typeDeclaration");
            schema.ThrowIfNull("schema");
            implDetails.ThrowIfNull("implDetails");
            internalClassProvider.ThrowIfNull("internalClassProvider");
            schema.SchemaDetails.ThrowIfNull("schema.SchemaDetails");

            typeDeclaration.Comments.AddRange(CreateComment(schema.SchemaDetails));
            AddCommentsToAllProperties(schema.Name, schema.SchemaDetails, typeDeclaration);
        }
开发者ID:nick0816,项目名称:LoggenCSG,代码行数:14,代码来源:StandardSchemaCommentDecorator.cs

示例7: DecorateInternalClass

 public void DecorateInternalClass(CodeTypeDeclaration typeDeclaration,
     string name,
     JsonSchema schema,
     IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
     INestedClassProvider internalClassProvider)
 {
     typeDeclaration.ThrowIfNull("typeDeclatation");
     schema.ThrowIfNull("schema");
     implDetails.ThrowIfNull("details");
     internalClassProvider.ThrowIfNull("internalClassProvider");
     typeDeclaration.Members.AddRange(
         GenerateAllProperties(name, schema, implDetails, internalClassProvider, typeDeclaration.Name).ToArray(
             ));
 }
开发者ID:nick0816,项目名称:LoggenCSG,代码行数:14,代码来源:StandardPropertyDecorator.cs

示例8: DecorateClass

        public void DecorateClass(CodeTypeDeclaration typeDeclaration,
                                  ISchema schema,
                                  IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
                                  INestedClassProvider internalClassProvider)
        {
            typeDeclaration.ThrowIfNull("typeDeclaration");
            schema.ThrowIfNull("schema");
            implDetails.ThrowIfNull("implDetails");

            SchemaImplementationDetails details = implDetails[schema.SchemaDetails];

            // If this method is refered as a result directly, add an inheritance to IResponse and implement
            // the interface
            if (details.IsMethodResult)
            {
                logger.Debug("Applying decorator to schema "+schema.Name);
                typeDeclaration.BaseTypes.Add(GetIResponseBaseType());
                typeDeclaration.Members.AddRange(CreateETagProperty(typeDeclaration));
            }
        }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:20,代码来源:ResponseInterfaceDecorator.cs

示例9: ImplementAdditionalProperties

        internal void ImplementAdditionalProperties(CodeTypeDeclaration type,
                                                    JsonSchema schema,
                                                    IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
                                                    INestedClassProvider internalClassProvider)
        {
            // Validate the input parameters.
            type.ThrowIfNull("type");
            schema.ThrowIfNull("schema");
            implDetails.ThrowIfNull("implDetails");
            internalClassProvider.ThrowIfNull("internalClassProvider");

            // Check if this decorator applies to the specified json schema.
            if (schema.AdditionalProperties == null)
            {
                return;
            }

            // Note/ToDo: Currently we only support AdditionalProperties for schemas
            //            specifiying no normal properties, as these won't be used
            //            by the newtonsoft json library if a dictionary is specified.
            if (schema.Properties != null && schema.Properties.Count > 0)
            {
                type.Comments.Add(new CodeCommentStatement("TODO: Add support for additionalProperties on schemas"));
                type.Comments.Add(new CodeCommentStatement("      which have normal properties defined."));
                return;
            }

            // Generate the underlying type.
            SchemaImplementationDetails details = implDetails[schema];
            CodeTypeReference underlyingTypeRef = SchemaDecoratorUtil.GetCodeType(
                schema.AdditionalProperties, details, internalClassProvider);

            // Add the base type reference.
            CodeTypeReference dictionaryRef = new CodeTypeReference(typeof(Dictionary<,>));
            dictionaryRef.TypeArguments.Add(typeof(string));
            dictionaryRef.TypeArguments.Add(underlyingTypeRef);
            type.BaseTypes.Add(dictionaryRef);
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:38,代码来源:AdditionalPropertiesSchemaDecorator.cs

示例10: AddCommentsToAllProperties

        internal void AddCommentsToAllProperties(string name, JsonSchema schema, CodeTypeDeclaration typeDeclaration)
        {
            schema.ThrowIfNull("schema");
            name.ThrowIfNullOrEmpty("name");
            typeDeclaration.ThrowIfNull("typeDeclaration");

            logger.Debug("Adding attributes to properties for {0}", name);

            if (schema.Properties.IsNullOrEmpty())
            {
                logger.Debug("No properties found for schema " + name);
                return;
            }

            int index = 0;
            foreach (var propertyPair in schema.Properties)
            {
                var schemaFieldName = propertyPair.Key;
                var propertyDefinition = SchemaUtil.FindCodePropertyForName(
                    typeDeclaration, schemaFieldName, index++, schema.Properties.Keys);
                propertyDefinition.Comments.AddRange(CreateComment(propertyPair.Value));
            }
        }
开发者ID:nick0816,项目名称:LoggenCSG,代码行数:23,代码来源:StandardSchemaCommentDecorator.cs

示例11: GenerateEnum

        internal static CodeTypeDeclaration GenerateEnum(CodeTypeDeclaration typeDeclaration,
                                                       string proposedName,
                                                       string description,
                                                       IEnumerable<KeyValuePair<string, string>> entries)
        {
            typeDeclaration.ThrowIfNull("typeDeclaration");
            proposedName.ThrowIfNullOrEmpty("proposedName");
            entries.ThrowIfNull("entries");

            // Create a safe enum name by avoiding the names of all members which are already in this type.
            IEnumerable<string> memberNames = from CodeTypeMember m in typeDeclaration.Members select m.Name;
            string name = GeneratorUtils.GetEnumName(proposedName, memberNames);

            // Create the enum type.
            var decl = new CodeTypeDeclaration(name);
            decl.IsEnum = true;

            // Get the EnumStringValueTypeConverter type.
            Type converterType = typeof(EnumStringValueTypeConverter);

            // [TypeConverter(..)]
            var typeConvAttribute = new CodeAttributeDeclaration(
                new CodeTypeReference(typeof(TypeConverterAttribute)));

            // .. typeof(EnumStringValueTypeConverter) ..
            typeConvAttribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(converterType)));
            decl.CustomAttributes.Add(typeConvAttribute);

            foreach (KeyValuePair<string, string> enumEntry in entries)
            {
                // Consider the names of all members in the current type as used words.
                IEnumerable<string> usedNames = from CodeTypeMember m in decl.Members select m.Name;
                string safeName = GeneratorUtils.GetEnumValueName(enumEntry.Key, usedNames);
                var member = new CodeMemberField(typeof(int), safeName);

                // Attribute:
                var valueAttribute = new CodeAttributeDeclaration();
                valueAttribute.Name = typeof(StringValueAttribute).FullName;
                valueAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(enumEntry.Key)));
                member.CustomAttributes.Add(valueAttribute);

                // Comments:
                member.Comments.AddRange(DecoratorUtil.CreateSummaryComment(enumEntry.Value));

                // Add member to enum.
                decl.Members.Add(member);
            }

            // Class comment:
            decl.Comments.AddRange(DecoratorUtil.CreateSummaryComment(description));

            return decl;
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:53,代码来源:EnumResourceDecorator.cs

示例12: DecorateClass

 public void DecorateClass(CodeTypeDeclaration typeDeclaration,
                           ISchema schema,
                           IDictionary<JsonSchema, SchemaImplementationDetails> implDetails,
                           INestedClassProvider internalClassProvider)
 {
     typeDeclaration.ThrowIfNull("typeDeclaration");
     schema.ThrowIfNull("schema");
     internalClassProvider.ThrowIfNull("internalClassProvider");
     Count++;
 }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:10,代码来源:SchemaGeneratorTest.cs


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