本文整理汇总了C#中IPropertySymbol类的典型用法代码示例。如果您正苦于以下问题:C# IPropertySymbol类的具体用法?C# IPropertySymbol怎么用?C# IPropertySymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPropertySymbol类属于命名空间,在下文中一共展示了IPropertySymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetParsedProperty
private SDProperty GetParsedProperty(IPropertySymbol property)
{
var syntaxReference = property.DeclaringSyntaxReferences.Any() ? property.DeclaringSyntaxReferences.Single() : null;
var sdProperty = new SDProperty(property.GetIdentifier())
{
Name = property.Name,
DeclaringType = _typeRefParser.GetParsedTypeReference(property.ContainingType),
Accessibility = property.DeclaredAccessibility.ToString().ToLower(),
ReturnType = _typeRefParser.GetParsedTypeReference(property.Type),
CanGet = property.GetMethod != null,
CanSet = property.SetMethod != null,
IsAbstract = property.IsAbstract,
IsVirtual = property.IsVirtual,
IsOverride = property.IsOverride,
Documentations = DocumentationParser.ParseDocumentation(property),
Region = syntaxReference != null ? new SDRegion
{
Start = syntaxReference.Span.Start,
End = syntaxReference.Span.End,
StartLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).StartLinePosition.Line + 1,
EndLine = syntaxReference.SyntaxTree.GetLineSpan(syntaxReference.Span).EndLinePosition.Line + 1,
FilePath = syntaxReference.SyntaxTree.FilePath,
Filename = Path.GetFileName(syntaxReference.SyntaxTree.FilePath)
} : null
};
ParserOptions.SDRepository.AddMember(sdProperty);
return sdProperty;
}
示例2: CreatePropertySymbol
internal static IPropertySymbol CreatePropertySymbol(
INamedTypeSymbol containingType,
IList<AttributeData> attributes,
Accessibility accessibility,
DeclarationModifiers modifiers,
ITypeSymbol type,
IPropertySymbol explicitInterfaceSymbol,
string name,
IList<IParameterSymbol> parameters,
IMethodSymbol getMethod,
IMethodSymbol setMethod,
bool isIndexer = false,
SyntaxNode initializer = null)
{
var result = new CodeGenerationPropertySymbol(
containingType,
attributes,
accessibility,
modifiers,
type,
explicitInterfaceSymbol,
name,
isIndexer,
parameters,
getMethod,
setMethod);
CodeGenerationPropertyInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, initializer);
return result;
}
示例3: FindSimilarityRank
public virtual SimilarityRank<IPropertySymbol> FindSimilarityRank(IPropertySymbol sourceProperty, IEnumerable<IPropertySymbol> targetProperties, List<IClassPropertyComparer> allComparers)
{
var allMatches = FindAllMatches(sourceProperty, targetProperties, allComparers);
var topMatch = allMatches.OrderByDescending(r => r.Confidence).FirstOrDefault(r => r.Confidence > 0);
return (topMatch ?? new SimilarityRank<IPropertySymbol>());
}
示例4: HandleValueField
internal void HandleValueField(ValueField valueField, IPropertySymbol property, ImmutableArray<AttributeData> propertyAttributes)
{
AddKeyAttribute(property, propertyAttributes, valueField);
AddIndexAttribute(property, propertyAttributes, valueField);
AddMaxLengthAttribute(property, propertyAttributes, valueField);
AddDatabaseGeneratedAttribute(property, propertyAttributes, valueField);
}
示例5: GenerateSetAccessor
private IMethodSymbol GenerateSetAccessor(
Compilation compilation,
IPropertySymbol property,
Accessibility accessibility,
bool generateAbstractly,
bool useExplicitInterfaceSymbol,
INamedTypeSymbol[] attributesToRemove,
CancellationToken cancellationToken)
{
if (property.SetMethod == null)
{
return null;
}
var setMethod = property.SetMethod.RemoveInaccessibleAttributesAndAttributesOfTypes(
this.State.ClassOrStructType,
attributesToRemove);
return CodeGenerationSymbolFactory.CreateAccessorSymbol(
setMethod,
attributes: null,
accessibility: accessibility,
explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.SetMethod : null,
statements: GetSetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));
}
示例6: Create
public static void Create(IPropertySymbol symbol, SymbolKeyWriter visitor)
{
visitor.WriteString(symbol.MetadataName);
visitor.WriteSymbolKey(symbol.ContainingSymbol);
visitor.WriteBoolean(symbol.IsIndexer);
visitor.WriteRefKindArray(symbol.Parameters);
visitor.WriteParameterTypesArray(symbol.OriginalDefinition.Parameters);
}
示例7: Compare
public SimilarityRank<IPropertySymbol> Compare(IPropertySymbol sourceProperty, IPropertySymbol targetProperty)
{
//TODO: check for subclasses
bool sameType = sourceProperty.Type.Equals(targetProperty.Type);
int confidence = (sameType ? 100 : 0);
return new SimilarityRank<IPropertySymbol>() { Confidence = confidence, Symbol = targetProperty };
}
示例8: Attach
public static void Attach(
IPropertySymbol property,
bool isNew,
bool isUnsafe)
{
var info = new CodeGenerationPropertyInfo(isNew, isUnsafe);
propertyToInfoMap.Add(property, info);
}
示例9: HaveSameSignature
public static bool HaveSameSignature (IPropertySymbol property1, IPropertySymbol property2, bool caseSensitive)
{
try {
return (bool)haveSameSignature2Method.Invoke(instance, new object[] { property1, property2, caseSensitive });
} catch (TargetInvocationException ex) {
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
return false;
}
}
示例10: Attach
public static void Attach(
IPropertySymbol property,
bool isNew,
bool isUnsafe,
SyntaxNode initializer)
{
var info = new CodeGenerationPropertyInfo(isNew, isUnsafe, initializer);
s_propertyToInfoMap.Add(property, info);
}
示例11: ReadSymbol
protected override void ReadSymbol(IPropertySymbol propertySymbol)
{
// we don't need to know about static members
// because they won't be delegated from child to mixin
if (propertySymbol.IsStatic)
return;
// we ignore private and protected memebers
var hasGetter = propertySymbol.GetMethod != null &&
!(propertySymbol.GetMethod.DeclaredAccessibility == Accessibility.Private ||
propertySymbol.GetMethod.DeclaredAccessibility == Accessibility.Protected);
var hasSetter = propertySymbol.SetMethod != null &&
!(propertySymbol.SetMethod.DeclaredAccessibility == Accessibility.Private ||
propertySymbol.SetMethod.DeclaredAccessibility == Accessibility.Protected);
// property has no accessors or accessors are not accessible => skip property
if (!hasSetter && !hasGetter)
return;
Property property = null;
if (propertySymbol.IsIndexer) // symbol is an indexer property
{
var indexerProperty = new IndexerProperty(
propertySymbol.Type,
hasGetter,
hasSetter);
var parameterReader = new ParameterSymbolReader(indexerProperty);
parameterReader.VisitSymbol(propertySymbol);
property = indexerProperty;
}
else // symbol is a normal property
{
property = new Property(
propertySymbol.Name,
propertySymbol.Type,
hasGetter,
hasSetter);
}
property.IsAbstract = propertySymbol.IsAbstract;
property.IsOverride = propertySymbol.IsOverride;
// store information if accessors are internal,
// we will need this for the generation later
property.IsGetterInternal = hasGetter &&
propertySymbol.GetMethod
.DeclaredAccessibility.HasFlag(Accessibility.Internal);
property.IsSetterInternal = hasSetter &&
propertySymbol.SetMethod
.DeclaredAccessibility.HasFlag(Accessibility.Internal);
property.Documentation = new DocumentationComment(propertySymbol.GetDocumentationCommentXml());
_properties.AddProperty(property);
}
示例12: FindAllMatches
private List<SimilarityRank<IPropertySymbol>> FindAllMatches(IPropertySymbol sourceProperty, IEnumerable<IPropertySymbol> targetProperties, List<IClassPropertyComparer> allComparers)
{
var allMatches = new List<SimilarityRank<IPropertySymbol>>();
foreach (var comparer in allComparers)
{
allMatches.AddRange(FindMatches(sourceProperty, targetProperties, comparer));
}
return allMatches;
}
示例13: AddPropertyTo
internal static CompilationUnitSyntax AddPropertyTo(
CompilationUnitSyntax destination,
IPropertySymbol property,
CodeGenerationOptions options,
IList<bool> availableIndices)
{
var declaration = GeneratePropertyOrIndexer(property, CodeGenerationDestination.CompilationUnit, options);
var members = Insert(destination.Members, declaration, options,
availableIndices, after: LastPropertyOrField, before: FirstMember);
return destination.WithMembers(members);
}
示例14: CompoundCompare
private SimilarityRank<IPropertySymbol> CompoundCompare(IPropertySymbol sourceProperty, IPropertySymbol targetProperty, IEnumerable<IClassPropertyComparer> comparers)
{
List<SimilarityRank<IPropertySymbol>> allResultRanks = new List<SimilarityRank<IPropertySymbol>>();
foreach (var propertyComparer in comparers)
{
SimilarityRank<IPropertySymbol> rank = propertyComparer.Compare(sourceProperty, targetProperty);
allResultRanks.Add(rank);
}
return BuildCombinedRank(targetProperty, allResultRanks);
}
示例15: GenerateProperty
private ISymbol GenerateProperty(
Compilation compilation,
IPropertySymbol property,
Accessibility accessibility,
DeclarationModifiers modifiers,
bool generateAbstractly,
bool useExplicitInterfaceSymbol,
string memberName,
CancellationToken cancellationToken)
{
var factory = this.Document.GetLanguageService<SyntaxGenerator>();
var comAliasNameAttribute = compilation.ComAliasNameAttributeType();
var getAccessor = property.GetMethod == null
? null
: CodeGenerationSymbolFactory.CreateAccessorSymbol(
property.GetMethod.RemoveInaccessibleAttributesAndAttributesOfType(
accessibleWithin: this.State.ClassOrStructType,
removeAttributeType: comAliasNameAttribute),
attributes: null,
accessibility: accessibility,
explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.GetMethod : null,
statements: GetGetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));
var setAccessor = property.SetMethod == null
? null
: CodeGenerationSymbolFactory.CreateAccessorSymbol(
property.SetMethod.RemoveInaccessibleAttributesAndAttributesOfType(
accessibleWithin: this.State.ClassOrStructType,
removeAttributeType: comAliasNameAttribute),
attributes: null,
accessibility: accessibility,
explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.SetMethod : null,
statements: GetSetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));
var syntaxFacts = Document.GetLanguageService<ISyntaxFactsService>();
var parameterNames = NameGenerator.EnsureUniqueness(
property.Parameters.Select(p => p.Name).ToList(), isCaseSensitive: syntaxFacts.IsCaseSensitive);
var updatedProperty = property.RenameParameters(parameterNames);
updatedProperty = updatedProperty.RemoveAttributeFromParameters(comAliasNameAttribute);
// TODO(cyrusn): Delegate through throughMember if it's non-null.
return CodeGenerationSymbolFactory.CreatePropertySymbol(
updatedProperty,
accessibility: accessibility,
modifiers: modifiers,
explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property : null,
name: memberName,
getMethod: getAccessor,
setMethod: setAccessor);
}