本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Resolver.TypeInference.GetBestCommonType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInference.GetBestCommonType方法的具体用法?C# TypeInference.GetBestCommonType怎么用?C# TypeInference.GetBestCommonType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Resolver.TypeInference
的用法示例。
在下文中一共展示了TypeInference.GetBestCommonType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveArrayCreation
/// <summary>
/// Resolves an array creation.
/// </summary>
/// <param name="elementType">
/// The array element type.
/// Pass null to resolve an implicitly-typed array creation.
/// </param>
/// <param name="dimensions">
/// The number of array dimensions.
/// </param>
/// <param name="sizeArguments">
/// The size arguments. May be null if no explicit size was given.
/// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
/// </param>
/// <param name="initializerElements">
/// The initializer elements. May be null if no array initializer was specified.
/// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
/// </param>
/// <param name="allowArrayConstants">
/// Specifies whether to allow treating single-dimensional arrays like compile-time constants.
/// This is used for attribute arguments.
/// </param>
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, int dimensions = 1, ResolveResult[] sizeArguments = null, ResolveResult[] initializerElements = null)
{
if (sizeArguments != null && dimensions != Math.Max(1, sizeArguments.Length))
throw new ArgumentException("dimensions and sizeArguments.Length don't match");
if (elementType == null) {
TypeInference typeInference = new TypeInference(compilation, conversions);
bool success;
elementType = typeInference.GetBestCommonType(initializerElements, out success);
}
IType arrayType = new ArrayType(compilation, elementType, dimensions);
if (sizeArguments != null)
AdjustArrayAccessArguments(sizeArguments);
if (initializerElements != null) {
for (int i = 0; i < initializerElements.Length; i++) {
initializerElements[i] = Convert(initializerElements[i], elementType);
}
}
return new ArrayCreateResolveResult(arrayType, sizeArguments, initializerElements);
}
示例2: ResolveArrayCreation
/// <summary>
/// Resolves an array creation.
/// </summary>
/// <param name="elementType">
/// The array element type.
/// Pass null to resolve an implicitly-typed array creation.
/// </param>
/// <param name="sizeArguments">
/// The size arguments.
/// The length of this array will be used as the number of dimensions of the array type.
/// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
/// </param>
/// <param name="initializerElements">
/// The initializer elements. May be null if no array initializer was specified.
/// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
/// </param>
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, ResolveResult[] sizeArguments, ResolveResult[] initializerElements = null)
{
int dimensions = sizeArguments.Length;
if (dimensions == 0)
throw new ArgumentException("sizeArguments.Length must not be 0");
if (elementType == null) {
TypeInference typeInference = new TypeInference(compilation, conversions);
bool success;
elementType = typeInference.GetBestCommonType(initializerElements, out success);
}
IType arrayType = new ArrayType(compilation, elementType, dimensions);
AdjustArrayAccessArguments(sizeArguments);
if (initializerElements != null) {
for (int i = 0; i < initializerElements.Length; i++) {
initializerElements[i] = Convert(initializerElements[i], elementType);
}
}
return new ArrayCreateResolveResult(arrayType, sizeArguments, initializerElements);
}