本文整理汇总了C#中AstType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# AstType.ToString方法的具体用法?C# AstType.ToString怎么用?C# AstType.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstType
的用法示例。
在下文中一共展示了AstType.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsSkipType
/// <summary>
/// Check if the type should be skipped to generate 'Contract.Ensures' and 'Contract.Requires' statemets.
/// </summary>
/// <param name="type">the type</param>
/// <returns>true: skip type</returns>
public static bool IsSkipType(AstType type)
{
string typeName = type.HasChildren ? type.FirstChild.ToString() : type.ToString();
if (SkipTypes == null)
{
return false;
}
return SkipTypes.Any(s => s.ToUpper() == typeName.ToUpper());
}
示例2: AreTypesEqual
/// <summary>
/// Determines whether the types are equal.
/// </summary>
/// <param name="expectedType">The expected type.</param>
/// <param name="typeReference">The type reference.</param>
/// <returns><c>true</c> if parameters are equal, otherwise <c>false</c>.</returns>
private static bool AreTypesEqual(string expectedType, AstType typeReference)
{
SimpleType simpleType = typeReference as SimpleType; // Generic types
if (simpleType != null)
{
if (simpleType.TypeArguments.Count == 1)
{
typeReference = simpleType.TypeArguments.First();
}
else if (simpleType.TypeArguments.Count >= 2)
{
// This can't be handled correctly
return true;
}
}
ComposedType composedType = typeReference as ComposedType; // Arrays
if (composedType != null)
{
if (!expectedType.EndsWith("[]", StringComparison.Ordinal))
{
return false;
}
else
{
expectedType = expectedType.Replace("[]", string.Empty);
typeReference = composedType.BaseType;
}
}
if (expectedType.StartsWith("ref ", StringComparison.Ordinal))
{
expectedType = expectedType.Replace("ref ", string.Empty);
}
string typeReplacement;
if (TypeReplacements.TryGetValue(expectedType, out typeReplacement))
{
expectedType = typeReplacement;
}
// Validate
string typeName = typeReference.ToString();
if (expectedType.Equals(typeName, StringComparison.OrdinalIgnoreCase)
|| ("System." + expectedType).Equals(typeName, StringComparison.OrdinalIgnoreCase)
|| expectedType.Substring(expectedType.LastIndexOf('.') + 1).Equals(typeName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
return false;
}
示例3: ReplaceType
void ReplaceType(AstType type)
{
int length = type.EndLocation.Column - type.StartLocation.Column;
int offset = type.StartLocation.Column - 1;
ReplaceType (type.ToString (), offset, length);
}
示例4: CreateTypeCompletionData
IEnumerable<ICompletionData> CreateTypeCompletionData(IType hintType, AstType hintTypeAst)
{
var wrapper = new CompletionDataWrapper(this);
var state = GetState();
Func<IType, IType> pred = null;
if (hintType != null) {
if (hintType.Kind != TypeKind.Unknown) {
var lookup = new MemberLookup(ctx.CurrentTypeDefinition, Compilation.MainAssembly);
pred = t => {
// check if type is in inheritance tree.
if (hintType.GetDefinition() != null && !t.GetDefinition().IsDerivedFrom(hintType.GetDefinition())) {
return null;
}
if (t.Kind == TypeKind.Interface && hintType.Kind != TypeKind.Array) {
return null;
}
// check for valid constructors
if (t.GetConstructors().Count() > 0) {
bool isProtectedAllowed = currentType != null ? currentType.Resolve(ctx).GetDefinition().IsDerivedFrom(t.GetDefinition()) : false;
if (!t.GetConstructors().Any(m => lookup.IsAccessible(m, isProtectedAllowed)))
return null;
}
var typeInference = new TypeInference(Compilation);
typeInference.Algorithm = TypeInferenceAlgorithm.ImprovedReturnAllResults;
var inferedType = typeInference.FindTypeInBounds(new [] { t }, new [] { hintType });
wrapper.AddType(inferedType, amb.ConvertType(inferedType));
return null;
};
if (!(hintType.Kind == TypeKind.Interface && hintType.Kind != TypeKind.Array)) {
DefaultCompletionString = GetShortType(hintType, GetState());
wrapper.AddType(hintType, DefaultCompletionString);
}
if (hintType is ParameterizedType && hintType.TypeParameterCount == 1 && hintType.FullName == "System.Collections.Generic.IEnumerable") {
var arg = ((ParameterizedType)hintType).TypeArguments.FirstOrDefault();
var array = new ArrayTypeReference(arg.ToTypeReference(), 1).Resolve(ctx);
wrapper.AddType(array, amb.ConvertType(array));
}
} else {
DefaultCompletionString = hintTypeAst.ToString();
wrapper.AddType(hintType, DefaultCompletionString);
}
}
AddTypesAndNamespaces(wrapper, state, null, pred, m => false);
if (hintType == null || hintType == SpecialType.UnknownType)
AddKeywords(wrapper, primitiveTypesKeywords.Where(k => k != "void"));
CloseOnSquareBrackets = true;
AutoCompleteEmptyMatch = true;
return wrapper.Result;
}
示例5: GenerateNamespaceString
string GenerateNamespaceString(AstType astType)
{
return astType.ToString();
}