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


C# Method.GetAttribute方法代码示例

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


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

示例1: MethodIsOwned

 public static bool MethodIsOwned(Method m) {
   if (m == null) return false;
   return m.GetAttribute(SystemTypes.RepAttribute) != null || m.GetAttribute(SystemTypes.PeerAttribute) != null;
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:4,代码来源:AdmissibilityChecker.cs

示例2: MethodIsRep

 public static bool MethodIsRep(Method m) {
   if (m == null) return false;
   AttributeNode attr = m.GetAttribute(SystemTypes.RepAttribute);
   return (attr != null);
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:5,代码来源:AdmissibilityChecker.cs

示例3: MethodIsElementCollection

 public static bool MethodIsElementCollection(Method m) {
   if (m == null) return false;
   return m.GetAttribute(SystemTypes.ElementCollectionAttribute) != null;
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:4,代码来源:AdmissibilityChecker.cs

示例4: MethodIsElementOrElementCollection

 /// <summary>
 /// Returns true iff method is marked [Element] or is the [] getter or method is marked ElementCollection.
 /// </summary>
 private bool MethodIsElementOrElementCollection(Method method) {
   if (method == null) return false;
   if (method.GetAttribute(SystemTypes.ElementAttribute) != null)
     return true;
   if ((method.DeclaringType != null && (method.DeclaringType.IsAssignableTo(SystemTypes.IEnumerable) || checker.HasEnumerablePattern(method.DeclaringType))) &&
        method.IsPropertyGetter && method.Name.ToString().Equals(StandardIds.getItem.ToString()))
     return true;
   if (method.GetAttribute(SystemTypes.ElementCollectionAttribute) != null)
     return true;
   return false;
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:14,代码来源:AdmissibilityChecker.cs

示例5: RecursionTerminationValue

 // Note: second parameter is just optimiziation for the case when we do know that m's spec contains method call(s)
 private int RecursionTerminationValue(Method m, bool doMethodCallCheck) {
   if (m == null) return System.Int32.MaxValue;
   AttributeNode attr = m.GetAttribute(SystemTypes.RecursionTerminationAttribute);
   if (attr == null) { // recursion termination not specified
     if (!doMethodCallCheck)
       return System.Int32.MaxValue;
     else {
       CallAndResultVisitor visitor = new CallAndResultVisitor(this.checker);
       if (m.Contract != null) {
         foreach (Ensures ens in m.Contract.Ensures) {
           visitor.HasCall = false;
           visitor.VisitExpression(ens.PostCondition);
           if (visitor.HasCall)
             return System.Int32.MaxValue; // method spec contains call
         }
         foreach (Requires req in m.Contract.Requires) {
           visitor.HasCall = false;
           visitor.VisitExpression(req.Condition);
           if (visitor.HasCall)
             return System.Int32.MaxValue; // method spec contains call
         }
       }
       return 0; // did not find call in method spec
     }
   }
   ExpressionList exprs = attr.Expressions;
   if (exprs == null || exprs.Count == 0) return 0; // default value for attribute w/o param
   Expression arg = exprs[0];
   Literal lit = arg as Literal;
   if (lit != null && lit.Value is int)
     return (int)lit.Value;
   return System.Int32.MaxValue;
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:34,代码来源:AdmissibilityChecker.cs

示例6: VisitMethod

    public override Method VisitMethod(Method method) {
      if (method == null) return null;

      // Need to call base visitor so that contract inheritance has already happened
      Method result = base.VisitMethod(method);

      #region MustOverride
      if (method.GetAttribute(Runtime.MustOverrideAttribute) != null
        && !method.IsVirtual) {
        this.HandleError(method.Name, Error.MethodMarkedMustOverrideMustBeVirtual, this.GetMethodSignature(method));
      }
      #endregion
      #region Check constraints when the method overrides a virtual method or implements an interface method
      if ((method.ImplementedInterfaceMethods != null && method.ImplementedInterfaceMethods.Count > 0)
            || (method.ImplicitlyImplementedInterfaceMethods != null && method.ImplicitlyImplementedInterfaceMethods.Count > 0)
            || method.OverriddenMethod != null
            || (method.IsPropertyGetter && method.DeclaringMember.OverriddenMember != null)
        ) {
        #region Purity must be consistent
        AttributeNode purityMarker = null;
        Method otherMethod = null;
        for (int i = 0, n = method.ImplementedInterfaceMethods == null ? 0 : method.ImplementedInterfaceMethods.Count; i < n; i++) {
          Method m = method.ImplementedInterfaceMethods[i];
          if (m == null) continue;
          purityMarker = GetPurityAttribute(m);
          if (purityMarker != null) {
            otherMethod = m;
            break; // FIXME! if one is marked, all should be marked the same!!
          }
        }
        if (otherMethod == null) {
          for (int i = 0, n = method.ImplicitlyImplementedInterfaceMethods == null ? 0 : method.ImplicitlyImplementedInterfaceMethods.Count; i < n; i++) {
            Method m = method.ImplicitlyImplementedInterfaceMethods[i];
            if (m == null) continue;
            purityMarker = GetPurityAttribute(m);
            if (purityMarker != null) {
              otherMethod = m;
              break; // FIXME! if one is marked, all should be marked the same!!
            }
          }
        }
        if (otherMethod == null){
          if (method.OverriddenMethod != null) {
            purityMarker = GetPurityAttribute(method.OverriddenMethod);
            if (purityMarker != null) {
              otherMethod = method.OverriddenMethod;
            }
          }
        }
        if (otherMethod == null) {
          if (method.IsPropertyGetter && method.DeclaringMember.OverriddenMember != null) {
            Property p = method.DeclaringMember.OverriddenMember as Property;
            if (p != null) {
              purityMarker = GetPurityAttribute(p.Getter);
              if (purityMarker != null) {
                otherMethod = p.Getter;
              }
            }
          }
        }
        Method methodToComplainAbout = method;
        ProxyMethod pm = methodToComplainAbout as ProxyMethod;
        if (pm != null) {
          methodToComplainAbout = pm.ProxyFor;
        }
        if (purityMarker != null) {
          if (!PurityLessThanOrEqualTo(otherMethod, methodToComplainAbout)) {
            string marking;
            if (otherMethod.IsPure)
              marking = "[Pure]";
            else if (otherMethod.IsConfined)
              marking = "[Pure]";
            else //(otherMethod.IsStateIndependent)
              marking = "[Pure][Reads(ReadsAttribute.Reads.Nothing)]";
            this.HandleError(methodToComplainAbout.Name, Error.MethodInheritingPurityMustBeMarked,
              this.GetMethodSignature(methodToComplainAbout),
              this.GetMethodSignature(otherMethod),
              marking);
          }
        }
        #endregion Purity must be consistent
      }
      #endregion Check constraints when the method overrides a virtual method or implements an inteface method

      #region Additive
      AttributeNode attrNode = method.GetAttribute(SystemTypes.AdditiveAttribute);
      AttributeNode overridenAttr = null;
      bool isAdditive = IsAdditive(attrNode);
      if (isAdditive && attrNode != null) {
        if (attrNode.Target == AttributeTargets.ReturnValue) {
          if (method.ReturnType.IsValueType) {
            this.HandleError(attrNode, Error.AttributeAllowedOnlyOnReferenceTypeParameters, this.GetTypeName(attrNode.Type));
          }
        } else if (method.DeclaringType.IsValueType) {
          this.HandleError(attrNode, Error.AttributeAllowedOnlyOnReferenceTypeParameters, this.GetTypeName(attrNode.Type));
        } else if (method.IsStatic) {
          // don't need to check for whether method is a ctor (which would be an error) because
          // if the method is a ctor, then an error will already have been generated since
          // ctors are not listed as a valid target for [Additive]
          this.HandleError(method, Error.StaticMethodCannotBeMarkedWithAttribute, this.GetTypeName(SystemTypes.AdditiveAttribute));
//.........这里部分代码省略.........
开发者ID:hesam,项目名称:SketchSharp,代码行数:101,代码来源:Checker.cs


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