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


C# IPropertySymbol.GetAttributes方法代码示例

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


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

示例1: GenerateIndexerDeclaration

        private static MemberDeclarationSyntax GenerateIndexerDeclaration(
            IPropertySymbol property,
            CodeGenerationDestination destination,
            CodeGenerationOptions options)
        {
            var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(property.ExplicitInterfaceImplementations);

            return AddCleanupAnnotationsTo(
                AddAnnotationsTo(property, SyntaxFactory.IndexerDeclaration(
                    attributeLists: AttributeGenerator.GenerateAttributeLists(property.GetAttributes(), options),
                    modifiers: GenerateModifiers(property, destination, options),
                    type: property.Type.GenerateTypeSyntax(),
                    explicitInterfaceSpecifier: explicitInterfaceSpecifier,
                    parameterList: ParameterGenerator.GenerateBracketedParameterList(property.Parameters, explicitInterfaceSpecifier != null, options),
                    accessorList: GenerateAccessorList(property, destination, options))));
        }
开发者ID:riversky,项目名称:roslyn,代码行数:16,代码来源:PropertyGenerator.cs

示例2: ValidateProperty

            private void ValidateProperty(IPropertySymbol property, out bool isCollection, out ITypeSymbol scalarType)
            {
                if (!IsSupportedPropertyType(property.Type, out isCollection, out scalarType))
                {
                    throw new InvalidOperationException(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Invalid property: {0} - the property type {1} is not supported by Entity Framework.",
                            property.ToDisplayString(this.ErrorMessageDisplayFormat),
                            property.Type.ToDisplayString(this.ErrorMessageDisplayFormat)));
                }

                var inversePropertyAttributeType = compilation.GetTypeByMetadataName(Constants.InversePropertyAttribute);
                var inversePropertyAttribute = property.GetAttributes().SingleOrDefault(x => x.AttributeClass == inversePropertyAttributeType);

                if (inversePropertyAttribute != null)
                {
                    var scalarTypeCopy = scalarType;
                    var targetType = this.interfaceSymbols.SingleOrDefault(x => x == scalarTypeCopy);

                    if (targetType == null)
                    {
                        throw new InvalidOperationException(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                "Invalid {0} attribute on property {1}. The property type {2} must be marked as an Entity.",
                                inversePropertyAttributeType.ToDisplayString(this.ErrorMessageDisplayFormat),
                                property.ToDisplayString(this.ErrorMessageDisplayFormat),
                                scalarType.ToDisplayString(this.ErrorMessageDisplayFormat)));
                    }

                    var inversePropertyName = (string)inversePropertyAttribute.ConstructorArguments[0].Value;

                    var targetProperty = targetType
                        .GetMembers()
                        .OfType<IPropertySymbol>()
                        .Where(x => x.Name == inversePropertyName)
                        .FirstOrDefault();

                    if (targetProperty == null)
                    {
                        throw new InvalidOperationException(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                "Invalid {0} attribute on property {1}. A property named '{2}' cannot be found on the target interface type {3}.",
                                inversePropertyAttributeType.ToDisplayString(this.ErrorMessageDisplayFormat),
                                property.ToDisplayString(this.ErrorMessageDisplayFormat),
                                inversePropertyName,
                                targetType.ToDisplayString(this.ErrorMessageDisplayFormat)));
                    }
                }
            }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:52,代码来源:Generator.cs

示例3: IsIgnoredProperty

 private bool IsIgnoredProperty(IPropertySymbol property)
 {
     var ignoreAttributeType = compilation.GetTypeByMetadataName(Constants.IgnoreAttribute);
     return property
         .GetAttributes()
         .Any(x => x.AttributeClass == ignoreAttributeType);
 }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:7,代码来源:Generator.cs

示例4: GeneratePropertyDeclaration

        private static MemberDeclarationSyntax GeneratePropertyDeclaration(
           IPropertySymbol property, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            var initializerNode = CodeGenerationPropertyInfo.GetInitializer(property) as ExpressionSyntax;

            var initializer = initializerNode != null
                ? SyntaxFactory.EqualsValueClause(initializerNode)
                : default(EqualsValueClauseSyntax);

            var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(property.ExplicitInterfaceImplementations);

            var accessorList = GenerateAccessorList(property, destination, options);

            return AddCleanupAnnotationsTo(
                AddAnnotationsTo(property, SyntaxFactory.PropertyDeclaration(
                    attributeLists: AttributeGenerator.GenerateAttributeLists(property.GetAttributes(), options),
                    modifiers: GenerateModifiers(property, destination, options),
                    type: property.Type.GenerateTypeSyntax(),
                    explicitInterfaceSpecifier: explicitInterfaceSpecifier,
                    identifier: property.Name.ToIdentifierToken(),
                    accessorList: accessorList,
                    expressionBody: default(ArrowExpressionClauseSyntax),
                    initializer: initializer)));
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:24,代码来源:PropertyGenerator.cs

示例5: GetBindableInfo

 BindableInfo GetBindableInfo(IPropertySymbol property)
 {
     return property.GetAttributes()
         .FirstOrDefault(x => x.AttributeClass == bindablePropertyAttributeType)
         .With(x => {
             var args = x.ConstructorArguments.Select(arg => arg.Value).ToArray();
             var namedArgs = x.NamedArguments.ToImmutableDictionary(p => p.Key, p => (string)p.Value.Value); //TODO error if names are not recognizable
             return new BindableInfo(args.Length > 0 ? (bool)args[0] : true,
                 namedArgs.GetValueOrDefault("OnPropertyChangedMethodName"),
                 namedArgs.GetValueOrDefault("OnPropertyChangingMethodName"));
         });
 }
开发者ID:VitalyTVA,项目名称:MetaSharp,代码行数:12,代码来源:ViewModelCompleter.cs

示例6: IsExcludedFromMapping

        private static bool IsExcludedFromMapping(IPropertySymbol property, ITypeSymbol metadataClass)
        {
            if (metadataClass != null)
            {
                property = (metadataClass.GetMembers(property.Name).FirstOrDefault() as IPropertySymbol) ?? property;
            }

            return property
                .GetAttributes()
                .Any(a => a.AttributeClass.ToString() == "NCR.Engage.RoslynAnalysis.ExcludeFromMappingAttribute");
        }
开发者ID:NCR-Engage,项目名称:MapEnforcerAnalyzer,代码行数:11,代码来源:DiagnosticAnalyzer.cs

示例7: GetPropertyMetadata

        private ControlPropertyMetadata GetPropertyMetadata(IPropertySymbol property)
        {
            var attribute = property.GetAttributes().FirstOrDefault(a => CheckType(a.AttributeClass, typeof(MarkupOptionsAttribute)));

            var metadata = new ControlPropertyMetadata()
            {
                Type = property.Type,
                IsTemplate = CheckType((INamedTypeSymbol)property.Type, typeof(ITemplate)) || property.Type.AllInterfaces.Any(i => CheckType(i, typeof(ITemplate))),
                AllowHtmlContent = property.Type.AllInterfaces.Any(i => CheckType(i, typeof(IControlWithHtmlAttributes)))
            };

            if (attribute != null)
            {
                metadata.Name = attribute.NamedArguments.Where(a => a.Key == "Name").Select(a => a.Value.Value as string).FirstOrDefault() ?? property.Name;
                metadata.AllowBinding = attribute.NamedArguments.Where(a => a.Key == "AllowBinding").Select(a => a.Value.Value as bool?).FirstOrDefault() ?? true;
                metadata.AllowHardCodedValue = attribute.NamedArguments.Where(a => a.Key == "AllowHardCodedValue").Select(a => a.Value.Value as bool?).FirstOrDefault() ?? true;

                var mappingMode = (MappingMode)(attribute.NamedArguments.Where(a => a.Key == "MappingMode").Select(a => a.Value.Value as int?).FirstOrDefault() ?? 0);
                if (mappingMode == MappingMode.InnerElement)
                {
                    metadata.IsElement = true;
                }
                else if (mappingMode == MappingMode.Exclude)
                {
                    return null;
                }
            }
            else
            {
                metadata.Name = property.Name;
                metadata.AllowBinding = true;
                metadata.AllowHardCodedValue = true;
            }

            if (metadata.IsTemplate)
            {
                metadata.IsElement = true;
            }

            return metadata;
        }
开发者ID:adamjez,项目名称:dotvvm,代码行数:41,代码来源:MetadataControlResolver.cs

示例8: GeneratePropertyDeclaration

        public static MemberDeclarationSyntax GeneratePropertyDeclaration(
           IPropertySymbol property, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(property.ExplicitInterfaceImplementations);

            return AddCleanupAnnotationsTo(
                AddAnnotationsTo(property, SyntaxFactory.PropertyDeclaration(
                    attributeLists: AttributeGenerator.GenerateAttributeLists(property.GetAttributes(), options),
                    modifiers: GenerateModifiers(property, destination, options),
                    type: property.Type.GenerateTypeSyntax(),
                    explicitInterfaceSpecifier: explicitInterfaceSpecifier,
                    identifier: property.Name.ToIdentifierToken(),
                    accessorList: GenerateAccessorList(property, destination, options))));
        }
开发者ID:riversky,项目名称:roslyn,代码行数:14,代码来源:PropertyGenerator.cs


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