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


C# IType.IsReferenceType方法代码示例

本文整理汇总了C#中IType.IsReferenceType方法的典型用法代码示例。如果您正苦于以下问题:C# IType.IsReferenceType方法的具体用法?C# IType.IsReferenceType怎么用?C# IType.IsReferenceType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IType的用法示例。


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

示例1: PerformValueAnalysis

        /// <summary>
        /// Performs the value analysis.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="type">
        /// The type parameter.
        /// </param>
        /// <param name="range">
        /// The range.
        /// </param>
        /// <param name="name">
        /// The variable name.
        /// </param>
        private void PerformValueAnalysis(IElement element, IType type, global::JetBrains.Util.TextRange range, string name)
        {
            if (!type.IsReferenceType())
              {
            return;
              }

              var functionDeclaration = element.GetContainingElement(typeof(IFunctionDeclaration), true) as ICSharpFunctionDeclaration;
              if (functionDeclaration == null)
              {
            return;
              }

              var expression = element.GetContainingElement(typeof(IReferenceExpression), true) as IReferenceExpression;
              if (expression == null)
              {
            return;
              }

              var graf = CSharpControlFlowBuilder.Build(functionDeclaration);

              var inspect = graf.Inspect(ValueAnalysisMode.OPTIMISTIC);

              var state = inspect.GetExpressionNullReferenceState(expression);

              switch (state)
              {
            case CSharpControlFlowNullReferenceState.UNKNOWN:
              this.AddAction("Check if '{0}' is null", "F802DB32-A0B1-4227-BE5C-E7D20670284B", range, name);
              break;
            case CSharpControlFlowNullReferenceState.NOT_NULL:
              break;
            case CSharpControlFlowNullReferenceState.NULL:
              this.AddAction("Check if '{0}' is null", "F802DB32-A0B1-4227-BE5C-E7D20670284B", range, name);
              break;
            case CSharpControlFlowNullReferenceState.MAY_BE_NULL:
              break;
              }
        }
开发者ID:xerxesb,项目名称:agentjohnsonplugin,代码行数:54,代码来源:LocalVariableContext.cs

示例2: BoxingConversion

		bool BoxingConversion(IType fromType, IType toType)
		{
			// C# 4.0 spec: §6.1.7
			fromType = NullableType.GetUnderlyingType(fromType);
			return fromType.IsReferenceType(context) == false && toType.IsReferenceType(context) == true && IsSubtypeOf(fromType, toType);
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:6,代码来源:Conversions.cs

示例3: IsNonNullableValueType

		public static bool IsNonNullableValueType(IType type, ITypeResolveContext context)
		{
			return type.IsReferenceType(context) == false && !IsNullable(type);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:4,代码来源:NullableType.cs

示例4: ImplicitReferenceConversion

		public bool ImplicitReferenceConversion(IType fromType, IType toType)
		{
			// C# 4.0 spec: §6.1.6
			
			// reference conversions are possible only if both types are known to be reference types
			if (!(fromType.IsReferenceType(context) == true && toType.IsReferenceType(context) == true))
				return false;
			
			// conversion from null literal is always possible
			if (fromType == SharedTypes.Null)
				return true;
			
			ArrayType fromArray = fromType as ArrayType;
			if (fromArray != null) {
				ArrayType toArray = toType as ArrayType;
				if (toArray != null) {
					// array covariance (the broken kind)
					return fromArray.Dimensions == toArray.Dimensions
						&& ImplicitReferenceConversion(fromArray.ElementType, toArray.ElementType);
				}
				// conversion from single-dimensional array S[] to IList<T>:
				ParameterizedType toPT = toType as ParameterizedType;
				if (fromArray.Dimensions == 1 && toPT != null && toPT.TypeArguments.Count == 1
				    && toPT.Namespace == "System.Collections.Generic"
				    && (toPT.Name == "IList" || toPT.Name == "ICollection" || toPT.Name == "IEnumerable"))
				{
					// array covariance plays a part here as well (string[] is IList<object>)
					return IdentityConversion(fromArray.ElementType, toPT.TypeArguments[0])
						|| ImplicitReferenceConversion(fromArray.ElementType, toPT.TypeArguments[0]);
				}
				// conversion from any array to System.Array and the interfaces it implements:
				ITypeDefinition systemArray = context.GetTypeDefinition("System", "Array", 0, StringComparer.Ordinal);
				return systemArray != null && (systemArray.Equals(toType) || ImplicitReferenceConversion(systemArray, toType));
			}
			
			// now comes the hard part: traverse the inheritance chain and figure out generics+variance
			return IsSubtypeOf(fromType, toType);
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:38,代码来源:Conversions.cs


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