public static bool IsReturnTypeIObservable(IConstructor constructor) { try { var declaredType = constructor.ReturnType as IDeclaredType; if (declaredType == null) { return false; } if (declaredType.Assembly == null) { return false; } var typeElement = constructor.GetContainingType(); if (typeElement == null) { return false; } return typeElement.GetSuperTypes() .Select(t => t.GetClrName().FullName) .Any(n => n == Constants.ObservableInterfaceName); } catch (Exception exn) { Debug.WriteLine(exn); return false; } }
private object[] GetCtorArgumentExpressions(ArgumentInfo[] existedArguments, IList <IParameter> ctorParams, IClass[] superClassTypes) { var argExpressions = new List <object> { ctor.GetContainingType() }; var existedArgumentsByType = existedArguments.Where(x => x.Expression != null).GroupBy(x => x.Type).ToDictionary(x => x.Key, x => x.ToList()); foreach (var ctorParam in ctorParams) { var argumentType = ctorParam.Type; if (!existedArgumentsByType.ContainsKey(argumentType)) { var possibleArgument = existedArguments.FirstOrDefault(x => x.Type.IsImplicitlyConvertibleTo(argumentType, cSharpTypeConversionRule)); if (possibleArgument != null) { argumentType = possibleArgument.Type; } } if (existedArgumentsByType.ContainsKey(argumentType)) { var argument = existedArgumentsByType[argumentType].InfinitivePop(); argExpressions.Add(argument.Expression); } else { argExpressions.Add(GetCtorArgumentName(ctorParam.Type, ctorParam.ShortName, superClassTypes)); } } return(argExpressions.ToArray()); }
private IdentifierTooltipContent TryGetTypeIdentifierContentFromConstructor( [NotNull] IConstructor constructor, [NotNull] DeclaredElementInfo constructorInfo, [NotNull] IContextBoundSettingsStore settings) { ITypeElement typeElement = constructor.GetContainingType(); if (typeElement == null) { return(null); } var typeInfo = new DeclaredElementInfo(typeElement, constructorInfo.Substitution, constructorInfo.TreeNode, constructorInfo.SourceRange, null); return(TryPresentColorized(typeInfo, settings)); }
private static IMethodName FindAdd(IConstructor c, [NotNull] ISubstitution substitution) { if (c != null) { var declType = c.GetContainingType(); if (declType != null) { foreach (var m in declType.Methods) { if ("Add".Equals(m.ShortName) && m.Parameters.Count == 1) { return(m.GetName <IMethodName>(substitution)); } } } } return(Names.UnknownMethod); }
/// <summary> /// Obtains a reflection wrapper for a constructor. /// </summary> /// <param name="target">The constructor, or null if none.</param> /// <returns>The reflection wrapper, or null if none.</returns> public StaticConstructorWrapper Wrap(IConstructor target) { if (target == null) return null; StaticDeclaredTypeWrapper declaringType = MakeDeclaredTypeWithoutSubstitution(target.GetContainingType()); return new StaticConstructorWrapper(this, target, declaringType); }