/// <summary>
/// Returns the name of the TypeUsage's EdmType that is safe for
/// use as an identifier.
/// </summary>
public string Escape(TypeUsage typeUsage)
{
if (typeUsage == null)
{
return(null);
}
if (typeUsage.EdmType is ComplexType ||
typeUsage.EdmType is EntityType)
{
return(Escape(typeUsage.EdmType.Name));
}
else if (typeUsage.EdmType is SimpleType)
{
Type clrType = _ef.UnderlyingClrType(typeUsage.EdmType);
string typeName = typeUsage.EdmType is EnumType?Escape(typeUsage.EdmType.Name) : Escape(clrType);
if (clrType.IsValueType && _ef.IsNullable(typeUsage))
{
return(String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName));
}
return(typeName);
}
else if (typeUsage.EdmType is CollectionType)
{
return(String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", Escape(((CollectionType)typeUsage.EdmType).TypeUsage)));
}
throw new ArgumentException("typeUsage");
}