当前位置: 首页>>代码示例>>C#>>正文


C# CSharpConversions类代码示例

本文整理汇总了C#中CSharpConversions的典型用法代码示例。如果您正苦于以下问题:C# CSharpConversions类的具体用法?C# CSharpConversions怎么用?C# CSharpConversions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CSharpConversions类属于命名空间,在下文中一共展示了CSharpConversions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TypeInference

		internal TypeInference(ICompilation compilation, CSharpConversions conversions)
		{
			Debug.Assert(compilation != null);
			Debug.Assert(conversions != null);
			this.compilation = compilation;
			this.conversions = conversions;
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:7,代码来源:TypeInference.cs

示例2: VisitForeachStatement

 public override void VisitForeachStatement(ForeachStatement foreachStatement)
 {
     base.VisitForeachStatement(foreachStatement);
     var rr = ctx.Resolve(foreachStatement) as ForEachResolveResult;
     if (rr == null)
         return;
     if (rr.ElementType.Kind == TypeKind.Unknown)
         return;
     if (ReflectionHelper.GetTypeCode(rr.ElementType) == TypeCode.Object)
         return;
     if (conversions == null) {
         conversions = CSharpConversions.Get(ctx.Compilation);
     }
     Conversion c = conversions.ImplicitConversion(rr.ElementType, rr.ElementVariable.Type);
     if (c.IsValid)
         return;
     var csResolver = ctx.GetResolverStateBefore(foreachStatement);
     var builder = new TypeSystemAstBuilder(csResolver);
     AstType elementType = builder.ConvertType(rr.ElementType);
     AstType variableType = foreachStatement.VariableType;
     string issueText = ctx.TranslateString("Collection element type '{0}' is not implicitly convertible to '{1}'");
     string fixText = ctx.TranslateString("Use type '{0}'");
     AddIssue(variableType, string.Format(issueText, elementType.GetText(), variableType.GetText()),
              new CodeAction(string.Format(fixText, elementType.GetText()),
                             script => script.Replace(variableType, elementType)));
 }
开发者ID:artifexor,项目名称:NRefactory,代码行数:26,代码来源:ExplicitConversionInForEachIssue.cs

示例3: CSharpResolver

		public CSharpResolver(ICompilation compilation)
		{
			if (compilation == null)
				throw new ArgumentNullException("compilation");
			this.compilation = compilation;
			this.conversions = CSharpConversions.Get(compilation);
			this.context = new CSharpTypeResolveContext(compilation.MainAssembly);
		}
开发者ID:nieve,项目名称:NRefactory,代码行数:8,代码来源:CSharpResolver.cs

示例4: CSharpResolver

        public CSharpResolver(ICompilation compilation)
        {
            if (compilation == null)
                throw new ArgumentNullException("compilation");
            this.compilation = compilation;
            this.conversions = CSharpConversions.Get(compilation);
            this.context = new CSharpTypeResolveContext(compilation.MainAssembly);

            var pc = compilation.MainAssembly.UnresolvedAssembly as CSharpProjectContent;
            if (pc != null) {
                this.checkForOverflow = pc.CompilerSettings.CheckForOverflow;
            }
        }
开发者ID:CSRedRat,项目名称:NRefactory,代码行数:13,代码来源:CSharpResolver.cs

示例5: SupportsIndexingCriterion

		public SupportsIndexingCriterion(IType returnType, IEnumerable<IType> argumentTypes, CSharpConversions conversions, bool isWriteAccess = false)
		{
			if (returnType == null)
				throw new ArgumentNullException("returnType");
			if (argumentTypes == null)
				throw new ArgumentNullException("argumentTypes");
			if (conversions == null)
				throw new ArgumentNullException("conversions");

			this.returnType = returnType;
			this.argumentTypes = argumentTypes.ToList();
			this.conversions = conversions;
			this.isWriteAccess = isWriteAccess;
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:14,代码来源:SupportsIndexingCriterion.cs

示例6: OverloadResolution

        public OverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[] argumentNames = null, IType[] typeArguments = null, CSharpConversions conversions = null)
        {
            if (compilation == null)
                throw new ArgumentNullException("compilation");
            if (arguments == null)
                throw new ArgumentNullException("arguments");
            if (argumentNames == null)
                argumentNames = new string[arguments.Length];
            else if (argumentNames.Length != arguments.Length)
                throw new ArgumentException("argumentsNames.Length must be equal to arguments.Length");
            this.compilation = compilation;
            this.arguments = arguments;
            this.argumentNames = argumentNames;

            // keep explicitlyGivenTypeArguments==null when no type arguments were specified
            if (typeArguments != null && typeArguments.Length > 0)
                this.explicitlyGivenTypeArguments = typeArguments;

            this.conversions = conversions ?? CSharpConversions.Get(compilation);
            this.AllowExpandingParams = true;
            this.AllowOptionalParameters = true;
        }
开发者ID:artifexor,项目名称:NRefactory,代码行数:22,代码来源:OverloadResolution.cs

示例7: IsValid

			public override Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions)
			{
				return conversions.ImplicitConversion(inferredReturnType, returnType);
			}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:4,代码来源:OverloadResolutionTests.cs

示例8: IsValid

		/// <summary>
		/// Gets whether the lambda body is valid for the given parameter types and return type.
		/// </summary>
		/// <returns>
		/// Produces a conversion with <see cref="Conversion.IsAnonymousFunctionConversion"/>=<c>true</c> if the lambda is valid;
		/// otherwise returns <see cref="Conversion.None"/>.
		/// </returns>
		public abstract Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions);
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:8,代码来源:LambdaResolveResult.cs

示例9: SetUp

 public override void SetUp()
 {
     base.SetUp();
     conversions = new CSharpConversions(compilation);
 }
开发者ID:segaman,项目名称:NRefactory,代码行数:5,代码来源:ConversionsTest.cs

示例10: IsEligibleExtensionMethod

		static bool IsEligibleExtensionMethod(ICompilation compilation, CSharpConversions conversions, IType targetType, IMethod method, bool useTypeInference, out IType[] outInferredTypes)
		{
			outInferredTypes = null;
			if (targetType == null)
				return true;
			if (method.Parameters.Count == 0)
				return false;
			IType thisParameterType = method.Parameters[0].Type;
			if (useTypeInference && method.TypeParameters.Count > 0) {
				// We need to infer type arguments from targetType:
				TypeInference ti = new TypeInference(compilation, conversions);
				ResolveResult[] arguments = { new ResolveResult(targetType) };
				IType[] parameterTypes = { method.Parameters[0].Type };
				bool success;
				var inferredTypes = ti.InferTypeArguments(method.TypeParameters, arguments, parameterTypes, out success);
				var substitution = new TypeParameterSubstitution(null, inferredTypes);
				// Validate that the types that could be inferred (aren't unknown) satisfy the constraints:
				bool hasInferredTypes = false;
				for (int i = 0; i < inferredTypes.Length; i++) {
					if (inferredTypes[i].Kind != TypeKind.Unknown && inferredTypes[i].Kind != TypeKind.UnboundTypeArgument) {
						hasInferredTypes = true;
						if (!OverloadResolution.ValidateConstraints(method.TypeParameters[i], inferredTypes[i], substitution, conversions))
							return false;
					} else {
						inferredTypes[i] = method.TypeParameters[i]; // do not substitute types that could not be inferred
					}
				}
				if (hasInferredTypes)
					outInferredTypes = inferredTypes;
				thisParameterType = thisParameterType.AcceptVisitor(substitution);
			}
			Conversion c = conversions.ImplicitConversion(targetType, thisParameterType);
			return c.IsValid && (c.IsIdentityConversion || c.IsReferenceConversion || c.IsBoxingConversion);
		}
开发者ID:nieve,项目名称:NRefactory,代码行数:34,代码来源:CSharpResolver.cs

示例11: ValidateConstraints

		internal static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor substitution, CSharpConversions conversions)
		{
			switch (typeArgument.Kind) { // void, null, and pointers cannot be used as type arguments
				case TypeKind.Void:
				case TypeKind.Null:
				case TypeKind.Pointer:
					return false;
			}
			if (typeParameter.HasReferenceTypeConstraint) {
				if (typeArgument.IsReferenceType != true)
					return false;
			}
			if (typeParameter.HasValueTypeConstraint) {
				if (!NullableType.IsNonNullableValueType(typeArgument))
					return false;
			}
			if (typeParameter.HasDefaultConstructorConstraint) {
				ITypeDefinition def = typeArgument.GetDefinition();
				if (def != null && def.IsAbstract)
					return false;
				var ctors = typeArgument.GetConstructors(
					m => m.Parameters.Count == 0 && m.Accessibility == Accessibility.Public,
					GetMemberOptions.IgnoreInheritedMembers | GetMemberOptions.ReturnMemberDefinitions
				);
				if (!ctors.Any())
					return false;
			}
			foreach (IType constraintType in typeParameter.DirectBaseTypes) {
				IType c = constraintType;
				if (substitution != null)
					c = c.AcceptVisitor(substitution);
				if (!conversions.IsConstraintConvertible(typeArgument, c))
					return false;
			}
			return true;
		}
开发者ID:FloodProject,项目名称:ICSharpCode.NRefactory,代码行数:36,代码来源:OverloadResolution.cs

示例12: IsValid

			public override Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions)
			{
				Assert.AreEqual(expectedParameterTypes, parameterTypes);
				return conversions.ImplicitConversion(inferredReturnType, returnType);
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:5,代码来源:TypeInferenceTests.cs

示例13: GatherVisitor

			public GatherVisitor (BaseRefactoringContext ctx)
				: base (ctx)
			{
				conversions = CSharpConversions.Get(ctx.Compilation);
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:5,代码来源:ExpressionIsNeverOfProvidedTypeIssue.cs

示例14: SetUp

		public void SetUp()
		{
			compilation = new SimpleCompilation(CecilLoaderTests.Mscorlib);
			conversions = new CSharpConversions(compilation);
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:5,代码来源:ConversionsTest.cs

示例15: ConstraintValidatingSubstitution

			public ConstraintValidatingSubstitution(IList<IType> classTypeArguments, IList<IType> methodTypeArguments, OverloadResolution overloadResolution)
				: base(classTypeArguments, methodTypeArguments)
			{
				this.conversions = overloadResolution.conversions;
			}
开发者ID:FloodProject,项目名称:ICSharpCode.NRefactory,代码行数:5,代码来源:OverloadResolution.cs


注:本文中的CSharpConversions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。