當前位置: 首頁>>代碼示例>>C#>>正文


C# Field.Equals方法代碼示例

本文整理匯總了C#中System.Compiler.Field.Equals方法的典型用法代碼示例。如果您正苦於以下問題:C# Field.Equals方法的具體用法?C# Field.Equals怎麽用?C# Field.Equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Compiler.Field的用法示例。


在下文中一共展示了Field.Equals方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CheckField

    private void CheckField(Field field) {
      if (field == null) return;

      // if method is StateIndependent then has to be readonly or field of an immutable type
      if (Method.IsStateIndependent &&
          !(field.IsInitOnly || (field.DeclaringType != null && field.DeclaringType.GetAttribute(SystemTypes.ImmutableAttribute) != null)))
        this.IssueWarning();

      if (field.Equals(PTGraph.allFields) || field.Equals(PTGraph.allFieldsNotOwned)) // reading all reachable fields not admissible
        this.IssueWarning(); // NOTE: this could be refined by analysing whether only rep fields are reachable

      // if got an [ElementRep] or [ElementPeer] field then saving element-level for next visit (rep:2, peer:1, none:0) 
      currentElementLevel = previousElementLevel;
      if (Util.FieldIsElementsRepOrPeer(field))
        previousElementLevel = (byte)(Util.FieldIsElementsRep(field) ? 2 : 1);

      // first access in chain
      if (firstBoundMember) {
        firstBoundMember = false;
        // non-rep: we go out of owned cone
        if (!(field.IsRep || (field.Type != null && field.Type.IsValueType))) { // note: handling value types (e.g. structs) as owned             
          outsideOwnedCone = true;
        }
        else { // rep or struct
          if (!(field.Type != null && field.Type.IsValueType)) // field of value-type (e.g. structs) does not lead into the owned cone
            contextDepth = 1;
        }
      }
      // chain should have ended already
      else if (outsideOwnedCone) {
        // access may be any of: visible field, readonly field, field of an immutable type, state-independent method
        if (!(field.IsInitOnly || (field.DeclaringType != null && field.DeclaringType.GetAttribute(SystemTypes.ImmutableAttribute) != null)))
          this.IssueWarning();
      }
      // access is rep or struct
      else if (field.IsRep || (field.Type != null && field.Type is Struct)) {
        if (field.Type != null && !(field.Type is Struct)) // if struct then do not go down (structs cannot be owned)
          contextDepth++;
      }
      // access on an element of an ElementsPeer array (which means -1 level access relative to coll./array)
      else if (currentElementLevel == 1) { 
        contextDepth--;
        if (contextDepth < 1)
          outsideOwnedCone = true;
      }
      // NOTE: elementLevel==2 need not be handled as we stay at the same context-depth
      // access is not owned: we go outside of owned cone
      else if (currentElementLevel != 2 && !field.IsPeer) {
        outsideOwnedCone = true;
      }
    }
開發者ID:hesam,項目名稱:SketchSharp,代碼行數:51,代碼來源:AdmissibilityChecker.cs


注:本文中的System.Compiler.Field.Equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。