本文整理汇总了C#中IPropertySymbol.ToDisplayString方法的典型用法代码示例。如果您正苦于以下问题:C# IPropertySymbol.ToDisplayString方法的具体用法?C# IPropertySymbol.ToDisplayString怎么用?C# IPropertySymbol.ToDisplayString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPropertySymbol
的用法示例。
在下文中一共展示了IPropertySymbol.ToDisplayString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateIdentityProperty
private void ValidateIdentityProperty(IPropertySymbol identityProperty)
{
var stringType = compilation.GetTypeByMetadataName(typeof(string).FullName);
var identifierAttributeType = compilation.GetTypeByMetadataName(Constants.IdentifierAttribute);
if (identityProperty.Type != stringType)
{
throw new InvalidOperationException(
string.Format(
CultureInfo.InvariantCulture,
"The property '{0}' must be of type {1} to be used as the identity property for an entity. If this property is intended to be the identity property for the entity please change its type to {1}. If it is not intended to be the identity property, either rename this property or create an identity property and decorate it with the [{2}] attribute.",
identityProperty.ToDisplayString(this.ErrorMessageDisplayFormat),
stringType.ToDisplayString(this.ErrorMessageDisplayFormat),
identifierAttributeType.ToDisplayString(this.ErrorMessageDisplayFormat)));
}
if (identityProperty.SetMethod != null)
{
throw new InvalidOperationException(
string.Format(
CultureInfo.InvariantCulture,
"The property '{0}' must not have a setter to be used as the identity property for an entity. If this property is intended to be the identity property for the entity please remove the setter. If it is not intended to be the identity property, either rename this property or create an identity propertyn and decorate it with the [{1}] attribute.",
identityProperty.ToDisplayString(this.ErrorMessageDisplayFormat),
identifierAttributeType.ToDisplayString(this.ErrorMessageDisplayFormat)));
}
}
示例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)));
}
}
}
示例3: GetTooltipForProperty
private string GetTooltipForProperty(IPropertySymbol propertySymbol)
=> propertySymbol.ToDisplayString();