本文整理汇总了C#中IType.GetAllBaseTypes方法的典型用法代码示例。如果您正苦于以下问题:C# IType.GetAllBaseTypes方法的具体用法?C# IType.GetAllBaseTypes怎么用?C# IType.GetAllBaseTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.GetAllBaseTypes方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalIsValid
internal static bool InternalIsValid (RefactoringOptions options, out IType interfaceType)
{
var unit = options.Document.ParsedDocument.GetAst<CompilationUnit> ();
interfaceType = null;
if (unit == null)
return false;
var loc = options.Document.Editor.Caret.Location;
var declaration = unit.GetNodeAt<TypeDeclaration> (loc.Line, loc.Column);
if (declaration == null)
return false;
if (!declaration.BaseTypes.Any (bt => bt.Contains (loc.Line, loc.Column)))
return false;
if (options.ResolveResult == null)
return false;
interfaceType = options.ResolveResult.Type;
var def = interfaceType.GetDefinition ();
if (def == null)
return false;
if (def.Kind != TypeKind.Interface)
return false;
var declaringType = options.Document.ParsedDocument.GetInnermostTypeDefinition (loc);
var type = declaringType.Resolve (options.Document.ParsedDocument.ParsedFile.GetTypeResolveContext (options.Document.Compilation, loc)).GetDefinition ();
return interfaceType.GetAllBaseTypes ().Any (bt => CodeGenerator.CollectMembersToImplement (type, bt, false).Any ());
}
示例2: GetCollectionType
static IType GetCollectionType(IType type)
{
IType collectionType = null;
foreach (var baseType in type.GetAllBaseTypes()) {
if (baseType.IsKnownType(KnownTypeCode.IEnumerableOfT)) {
collectionType = baseType;
break;
} else if (baseType.IsKnownType(KnownTypeCode.IEnumerable)) {
collectionType = baseType;
// Don't break, continue in case type implements IEnumerable<T>
}
}
return collectionType;
}
示例3: GetObjectChildren
IEnumerable<TreeNode> GetObjectChildren(IType shownType)
{
IEnumerable<IMember> fields = shownType.GetFields(f => !f.IsConst, GetMemberOptions.IgnoreInheritedMembers);
IEnumerable<IMember> properties = shownType.GetProperties(p => p.CanGet && p.Parameters.Count == 0, GetMemberOptions.IgnoreInheritedMembers);
IEnumerable<IMember> fieldsAndProperties = fields.Concat(properties).ToList();
IEnumerable<IMember> publicStatic = fieldsAndProperties.Where(m => m.IsPublic && m.IsStatic);
IEnumerable<IMember> publicInstance = fieldsAndProperties.Where(m => m.IsPublic && !m.IsStatic);
IEnumerable<IMember> nonPublicStatic = fieldsAndProperties.Where(m => !m.IsPublic && m.IsStatic);
IEnumerable<IMember> nonPublicInstance = fieldsAndProperties.Where(m => !m.IsPublic && !m.IsStatic);
IType baseType = shownType.DirectBaseTypes.FirstOrDefault(t => t.Kind != TypeKind.Interface);
if (baseType != null) {
yield return new TreeNode(
ClassBrowserIconService.Class,
StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.BaseClass}"),
baseType.Name,
string.Empty,
baseType.FullName == "System.Object" ? (Func<IEnumerable<TreeNode>>) null : () => GetObjectChildren(baseType)
);
}
if (nonPublicInstance.Any()) {
yield return new TreeNode(
StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.NonPublicMembers}"),
() => GetMembers(nonPublicInstance)
);
}
if (publicStatic.Any() || nonPublicStatic.Any()) {
yield return new TreeNode(
StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.StaticMembers}"),
() => {
var children = GetMembers(publicStatic).ToList();
if (nonPublicStatic.Any()) {
children.Insert(0, new TreeNode(
StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.NonPublicStaticMembers}"),
() => GetMembers(nonPublicStatic)
));
}
return children;
}
);
}
// IList
if (shownType.GetAllBaseTypeDefinitions().Any(t => t.IsKnownType(KnownTypeCode.IList))) {
yield return new TreeNode(
"IList",
() => GetIListChildren(GetValue)
);
}
// IEnumberable<T> (pottentially several of them)
var ienumerableTypes = shownType.GetAllBaseTypes().OfType<ParameterizedType>().Where(p => p.IsKnownType(KnownTypeCode.IEnumerableOfT));
foreach(var ienumerableType in ienumerableTypes) {
var ienumerableTypeCopy = ienumerableType;
yield return new TreeNode(
null,
ienumerableType.Name,
ienumerableType.ReflectionName,
string.Empty,
() => {
// Note that this will bind to the current content forever and it will not reeveluate
Value list = CreateListFromIEnumerable(ienumerableTypeCopy, GetValue()).GetPermanentReferenceOfHeapValue();
return GetIListChildren(() => list);
}
);
}
foreach(TreeNode node in GetMembers(publicInstance)) {
yield return node;
}
}
示例4: IsSignatureMatch
bool IsSignatureMatch(IType indexerElementType, IList<IType> indexerParameterTypes)
{
indexerElementType.GetAllBaseTypes();
if (indexerParameterTypes.Count != argumentTypes.Count)
return false;
var returnConversion = conversions.ImplicitConversion(indexerElementType, returnType);
if (!returnConversion.IsValid)
return false;
for (int i = 0; i < argumentTypes.Count; i++) {
var conversion = conversions.ImplicitConversion(indexerParameterTypes[i], argumentTypes[i]);
if (!conversion.IsValid)
return false;
}
return true;
}
示例5: SatisfiedBy
public bool SatisfiedBy (IType type)
{
return isType == type ||
type.GetAllBaseTypes().Any(t => t == isType);
}
示例6: MakeUpperBoundInference
/// <summary>
/// Make upper bound inference from U to V.
/// C# 4.0 spec: §7.5.2.10 Upper-bound inferences
/// </summary>
void MakeUpperBoundInference(IType U, IType V)
{
Log.WriteLine(" MakeUpperBoundInference from " + U + " to " + V);
// If V is one of the unfixed Xi then U is added to the set of bounds for Xi.
TP tp = GetTPForType(V);
if (tp != null && tp.IsFixed == false) {
Log.WriteLine(" Add upper bound '" + U + "' to " + tp);
tp.UpperBounds.Add(U);
return;
}
// Handle array types:
ArrayType arrU = U as ArrayType;
ArrayType arrV = V as ArrayType;
ParameterizedType pU = U as ParameterizedType;
if (arrV != null && arrU != null && arrU.Dimensions == arrV.Dimensions) {
MakeUpperBoundInference(arrU.ElementType, arrV.ElementType);
return;
} else if (arrV != null && IsGenericInterfaceImplementedByArray(pU) && arrV.Dimensions == 1) {
MakeUpperBoundInference(pU.GetTypeArgument(0), arrV.ElementType);
return;
}
// Handle parameterized types:
if (pU != null) {
ParameterizedType uniqueBaseType = null;
foreach (IType baseV in V.GetAllBaseTypes()) {
ParameterizedType pV = baseV as ParameterizedType;
if (pV != null && object.Equals(pU.GetDefinition(), pV.GetDefinition()) && pU.TypeParameterCount == pV.TypeParameterCount) {
if (uniqueBaseType == null)
uniqueBaseType = pV;
else
return; // cannot make an inference because it's not unique
}
}
Log.Indent();
if (uniqueBaseType != null) {
for (int i = 0; i < uniqueBaseType.TypeParameterCount; i++) {
IType Ui = pU.GetTypeArgument(i);
IType Vi = uniqueBaseType.GetTypeArgument(i);
if (Ui.IsReferenceType == true) {
// look for variance
ITypeParameter Xi = pU.GetDefinition().TypeParameters[i];
switch (Xi.Variance) {
case VarianceModifier.Covariant:
MakeUpperBoundInference(Ui, Vi);
break;
case VarianceModifier.Contravariant:
MakeLowerBoundInference(Ui, Vi);
break;
default: // invariant
MakeExactInference(Ui, Vi);
break;
}
} else {
// not known to be a reference type
MakeExactInference(Ui, Vi);
}
}
}
Log.Unindent();
}
}
示例7: GetElementType
IType GetElementType (IType result)
{
foreach (var baseType in result.GetAllBaseTypes ()) {
var baseTypeDef = baseType.GetDefinition();
if (baseTypeDef != null && baseTypeDef.Name == "IEnumerable") {
if (baseTypeDef.Namespace == "System.Collections.Generic" && baseTypeDef.TypeParameterCount == 1) {
var pt = baseType as ParameterizedType;
if (pt != null) {
return pt.TypeArguments[0];
}
} else if (baseTypeDef.Namespace == "System.Collections" && baseTypeDef.TypeParameterCount == 0) {
return CurrentContext.Compilation.FindType (KnownTypeCode.Object);
}
}
}
return new UnknownType ("", "", 0);
}
示例8: IsProtectedAccessible
static bool IsProtectedAccessible(IType sourceType, IType targetType)
{
return sourceType.GetAllBaseTypes().Any(type => targetType.Equals(type));
}
示例9: IsSubtypeOf
// Determines whether s is a subtype of t.
// Helper method used for ImplicitReferenceConversion and BoxingConversion
bool IsSubtypeOf(IType s, IType t)
{
// conversion to dynamic + object are always possible
if (t == SharedTypes.Dynamic || t.Equals(objectType))
return true;
// let GetAllBaseTypes do the work for us
foreach (IType baseType in s.GetAllBaseTypes(context)) {
if (IdentityOrVarianceConversion(baseType, t))
return true;
}
return false;
}
示例10: CheckTypeCompatibility
public static TypeCompatiblity CheckTypeCompatibility(IType exprType, IType providedType)
{
var exprBaseTypes = exprType.GetAllBaseTypes ().ToArray ();
// providedType is a base type of exprType
if (exprBaseTypes.Any (t => t.Equals (providedType)))
return TypeCompatiblity.AlwaysOfProvidedType;
if ((exprType.IsReferenceType == true && providedType.IsReferenceType == false) ||
(exprType.IsReferenceType == false && providedType.IsReferenceType == true))
return TypeCompatiblity.NeverOfProvidedType;
var typeParameter = exprType as ITypeParameter;
var providedTypeParameter = providedType as ITypeParameter;
if (typeParameter != null) {
// check if providedType can be a derived type
var providedBaseTypes = providedType.GetAllBaseTypes ().ToArray ();
var providedTypeDef = providedType.GetDefinition ();
// if providedType is sealed, check if it fullfills all the type parameter constraints,
// otherwise, only check if it is derived from EffectiveBaseClass
if (providedTypeParameter == null && (providedTypeDef == null || providedTypeDef.IsSealed)) {
if (CheckTypeParameterConstraints (providedType, providedBaseTypes, typeParameter))
return TypeCompatiblity.MayOfProvidedType;
} else if (providedBaseTypes.Any (t => t.Equals (typeParameter.EffectiveBaseClass))) {
return TypeCompatiblity.MayOfProvidedType;
}
// if providedType is also a type parameter, check if base classes are compatible
if (providedTypeParameter != null &&
exprBaseTypes.Any (t => t.Equals (providedTypeParameter.EffectiveBaseClass)))
return TypeCompatiblity.MayOfProvidedType;
return TypeCompatiblity.NeverOfProvidedType;
}
// check if exprType fullfills all the type parameter constraints
if (providedTypeParameter != null &&
CheckTypeParameterConstraints (exprType, exprBaseTypes, providedTypeParameter))
return TypeCompatiblity.MayOfProvidedType;
switch (exprType.Kind) {
case TypeKind.Class:
var exprTypeDef = exprType.GetDefinition ();
if (exprTypeDef == null)
return TypeCompatiblity.MayOfProvidedType;
// exprType is sealed, but providedType is not a base type of it or it does not
// fullfill all the type parameter constraints
if (exprTypeDef.IsSealed)
break;
// check if providedType can be a derived type
if (providedType.Kind == TypeKind.Interface ||
providedType.GetAllBaseTypes ().Any (t => t.Equals (exprType)))
return TypeCompatiblity.MayOfProvidedType;
if (providedTypeParameter != null &&
exprBaseTypes.Any (t => t.Equals (providedTypeParameter.EffectiveBaseClass)))
return TypeCompatiblity.MayOfProvidedType;
break;
case TypeKind.Struct:
case TypeKind.Delegate:
case TypeKind.Enum:
case TypeKind.Array:
case TypeKind.Anonymous:
case TypeKind.Null:
break;
default:
return TypeCompatiblity.MayOfProvidedType;
}
return TypeCompatiblity.NeverOfProvidedType;
}
示例11: GetParents
public IList<ITypeInfo> GetParents(IType type, IList<ITypeInfo> list = null, bool includeSelf = false)
{
if (list == null)
{
activeTypes = new Stack<IType>();
list = new List<ITypeInfo>();
}
var typeDef = type.GetDefinition() ?? type;
if (activeTypes.Contains(typeDef))
{
return list;
}
activeTypes.Push(typeDef);
var types = type.GetAllBaseTypes();
foreach (var t in types)
{
var bType = BridgeTypes.Get(t, true);
if (bType != null && bType.TypeInfo != null && (includeSelf || bType.Type != typeDef))
{
list.Add(bType.TypeInfo);
}
if (t.TypeArguments.Count > 0)
{
foreach (var typeArgument in t.TypeArguments)
{
this.GetParents(typeArgument, list, true);
}
}
}
activeTypes.Pop();
return includeSelf ? list : list.Distinct().ToList();
}
示例12: CreateInterfaceImplementation
public string CreateInterfaceImplementation (ITypeDefinition implementingType, IUnresolvedTypeDefinition implementingPart, IType interfaceType, bool explicitly, bool wrapRegions = true)
{
SetIndentTo (implementingPart);
StringBuilder result = new StringBuilder ();
List<IMember> implementedMembers = new List<IMember> ();
foreach (var def in interfaceType.GetAllBaseTypes ().Where (bt => bt.Kind == TypeKind.Interface)) {
if (result.Length > 0) {
AppendLine (result);
AppendLine (result);
}
string implementation = InternalCreateInterfaceImplementation (implementingType, implementingPart, def, explicitly, implementedMembers);
if (string.IsNullOrWhiteSpace (implementation))
continue;
if (wrapRegions) {
result.Append (WrapInRegions (def.Name + " implementation", implementation));
} else {
result.Append (implementation);
}
}
return result.ToString ();
}