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


C# ISymbol.Parameters方法代码示例

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


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

示例1: TryGetMethodReference

    public bool TryGetMethodReference(ISymbol semanticMethod, out IMethodReference cciMethod) {
      Contract.Requires(semanticMethod == null || semanticMethod.Kind == SymbolKind.Method);
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out cciMethod) != null);

      cciMethod = null;

      #region Check input
      if (semanticMethod == null) {
        return false;
      }
      #endregion
      #region Check cache
      if (ContractsPackageAccessor.Current.VSOptionsPage.Caching)
        if (_semanticMembersToCCIMethods.TryGetValue(semanticMethod, out cciMethod))
          return (!(cciMethod is Dummy)) && cciMethod != null;
      #endregion
      #region Set up our working cci method
      var workingCciMethod = new Microsoft.Cci.MutableCodeModel.MethodReference();
      #endregion
      #region Set the intern factory
      workingCciMethod.InternFactory = Host.InternFactory;
      #endregion
      #region Get calling conventions
      workingCciMethod.CallingConvention = CSharpToCCIHelper.GetCallingConventionFor(semanticMethod);
      #endregion
      #region Get containing type reference
      ITypeReference containingType;
      if (!TryGetTypeReference(semanticMethod.ContainingType, out containingType))
        goto ReturnFalse;
      workingCciMethod.ContainingType = containingType;
      #endregion
      #region Get return type reference
      if (semanticMethod.IsConstructor())
        workingCciMethod.Type = this.Host.PlatformType.SystemVoid;
      else {
        ITypeReference returnType;
        if (!TryGetTypeReference(semanticMethod.ReturnType(), out returnType))
          goto ReturnFalse;
        workingCciMethod.Type = returnType;
      }
      #endregion
      #region Get name
      if (!semanticMethod.IsConstructor() && semanticMethod.Name == null) goto ReturnFalse;
      workingCciMethod.Name = Host.NameTable.GetNameFor(semanticMethod.IsConstructor()?".ctor":semanticMethod.Name);
      #endregion
      #region Get generic param count
      if (semanticMethod.TypeParameters().IsDefault)
        workingCciMethod.GenericParameterCount = 0;
      else
        workingCciMethod.GenericParameterCount = (ushort)semanticMethod.TypeParameters().Length;
      #endregion
      #region Get parameter references
      List<IParameterTypeInformation> cciParameters;
      if (semanticMethod.Parameters().IsDefault) goto ReturnFalse;
      Contract.Assume(semanticMethod.Parameters().Length <= ushort.MaxValue, "Should be a postcondition?");
      if (!TryGetParametersList(semanticMethod.Parameters(), out cciParameters))
        goto ReturnFalse;
      workingCciMethod.Parameters = cciParameters;
      #endregion
      #region Get the assembly reference (this also ensures the assembly gets loaded properly)
      IAssemblyReference assemblyReference;
      TryGetAssemblyReference(semanticMethod.ContainingAssembly, out assemblyReference);
      #endregion
      cciMethod = workingCciMethod;
      return true;
      #region ReturnFalse:
    ReturnFalse:
      cciMethod = Dummy.MethodReference;
      if (ContractsPackageAccessor.Current.VSOptionsPage.Caching)
        _semanticMembersToCCIMethods[semanticMethod] = cciMethod;
      return false;
      #endregion
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:73,代码来源:ContractsProvider.cs

示例2: TryGetPropertyAccessorReferences

    public bool TryGetPropertyAccessorReferences(ISymbol semanticProperty, out IMethodReference getter, out IMethodReference setter) {
      Contract.Requires(semanticProperty == null || semanticProperty.Kind == SymbolKind.Property);

      getter = setter = null;

      #region Check input
      if (semanticProperty == null) {
        return false;
      }
      #endregion
      #region Check cache
      Tuple<IMethodReference, IMethodReference> cacheOutput;
      if (_semanticPropertiesToCCIAccessorMethods.TryGetValue(semanticProperty, out cacheOutput)) {
        Contract.Assume(cacheOutput != null, "Non-null only dictionary");
        getter = cacheOutput.Item1;
        setter = cacheOutput.Item2;
        return (getter != null && getter != Dummy.MethodReference) || (setter != null && setter != Dummy.MethodReference);
      }
      #endregion
      #region Get calling conventions
      var callingConventions = CSharpToCCIHelper.GetCallingConventionFor(semanticProperty);
      #endregion
      #region get containing type
      ITypeReference containingType;
      if (!TryGetTypeReference(semanticProperty.ContainingType, out containingType))
        goto ReturnFalse;
      #endregion
      #region Get return type
      ITypeReference returnType;
      if (!TryGetTypeReference(semanticProperty.ReturnType(), out returnType))
        goto ReturnFalse;
      #endregion
      #region Get the property's name
      string propertyName;
      if (semanticProperty.IsIndexer())
        propertyName = "Item";
      else
      {
        if (semanticProperty.Name == null) goto ReturnFalse;
        propertyName = semanticProperty.Name;
      }
      #endregion
      #region Get the parameters
      List<IParameterTypeInformation> getterParams;
      if (!semanticProperty.Parameters().IsDefault) {
        if (!TryGetParametersList(semanticProperty.Parameters(), out getterParams))
          goto ReturnFalse;
      } else
        getterParams = new List<IParameterTypeInformation>();

      List<IParameterTypeInformation> setterParams;
      if (!semanticProperty.Parameters().IsDefault) {
        if (!TryGetParametersList(semanticProperty.Parameters(), out setterParams, 1))
          goto ReturnFalse;
        #region Append the "value" param
        var valParam = new Microsoft.Cci.MutableCodeModel.ParameterTypeInformation() {
          Type = returnType,
          Index = 0,
          IsByReference = false
        };
        setterParams.Insert(0, valParam);
        #endregion
      } else
        setterParams = new List<IParameterTypeInformation>();
      #endregion
      #region Build the getter
      getter = new Microsoft.Cci.MutableCodeModel.MethodReference() {
        InternFactory = Host.InternFactory,
        CallingConvention = callingConventions,
        ContainingType = containingType,
        Type = returnType,
        Name = Host.NameTable.GetNameFor("get_" + propertyName),
        GenericParameterCount = 0,
        Parameters = getterParams
      };
      #endregion
      #region Build the setter
      setter = new Microsoft.Cci.MutableCodeModel.MethodReference() {
        InternFactory = Host.InternFactory,
        CallingConvention = callingConventions,
        ContainingType = containingType,
        Type = Host.PlatformType.SystemVoid,
        Name = Host.NameTable.GetNameFor("set_" + propertyName),
        GenericParameterCount = 0,
        Parameters = setterParams
      };
      #endregion
      #region Get the assembly reference (this also ensures the assembly gets loaded properly)
      IAssemblyReference assemblyReference;
      TryGetAssemblyReference(semanticProperty.ContainingAssembly, out assemblyReference);
      #endregion
      #region ReturnTrue:
    //ReturnTrue:
      _semanticPropertiesToCCIAccessorMethods[semanticProperty] = new Tuple<IMethodReference, IMethodReference>(getter, setter);
      return true;
      #endregion
      #region ReturnFalse:
    ReturnFalse:
      if (semanticProperty.Name != null)
      {
//.........这里部分代码省略.........
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:101,代码来源:ContractsProvider.cs

示例3: FuzzyIdentifySignature

    private void FuzzyIdentifySignature(ISymbol mem, ISymbol[] result, [Pure] IList<ISignature> signatures)
    {
        Contract.Requires(signatures != null);
        Contract.Requires(result != null);
        Contract.Requires(result.Length >= signatures.Count);
        Contract.Requires(mem != null);

        for (int i = 0; i < signatures.Count; i++)
        {
            if (result[i] != null) continue;
            var sig = signatures[i];
            if (sig == null) continue;
            if (sig.Parameters == null) continue;
            if (mem.Parameters().IsDefault) continue;
            if (sig.Parameters.Count != mem.Parameters().Length) continue;

            var match = true;
            for (int j = 0; j < mem.Parameters().Length; j++)
            {
                var p = mem.Parameters()[j];
                var s = sig.Parameters[j];
                if (p == null || p.Name == null || s == null || p.Name != s.Name) { match = false; break; }
                // need to compare types, but how. Sig doesn't seem to give it to us
            }
            if (!match) continue;

            result[i] = mem;
            break;
        }
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:30,代码来源:SignatureHelp.cs


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