public static FindAttribute ( IEnumerable |
||
attrs | IEnumerable |
|
sa | SpecialAttribute | |
리턴 | ICustomAttribute |
public virtual void PrintParameterDefinitionModifiers(IParameterDefinition parameterDefinition) { Contract.Requires(parameterDefinition != null); if (parameterDefinition.Index == 0) { var meth = parameterDefinition.ContainingSignature as IMethodDefinition; if (meth != null) { if (Utils.FindAttribute(meth.Attributes, SpecialAttribute.Extension) != null) { PrintToken(CSharpToken.This); PrintToken(CSharpToken.Space); } } } foreach (var attribute in SortAttributes(parameterDefinition.Attributes)) { if (Utils.GetAttributeType(attribute) == SpecialAttribute.ParamArray) { sourceEmitterOutput.Write("params"); } else { this.PrintAttribute(parameterDefinition, attribute, false, null); } PrintToken(CSharpToken.Space); } if (parameterDefinition.IsOut && !parameterDefinition.IsIn && parameterDefinition.IsByReference) { // C# out keyword means [Out] ref (with no [In] allowed) PrintKeywordOut(); } else { if (parameterDefinition.IsIn) { PrintPseudoCustomAttribute(parameterDefinition, "System.Runtime.InteropServices.In", null, false, null); } if (parameterDefinition.IsOut) { PrintPseudoCustomAttribute(parameterDefinition, "System.Runtime.InteropServices.Out", null, false, null); } if (parameterDefinition.IsByReference) { PrintKeywordRef(); } } }
public virtual void PrintFieldDefinitionEnumValue(IFieldDefinition fieldDefinition) { Contract.Requires(fieldDefinition != null); PrintFieldDefinitionName(fieldDefinition); sourceEmitterOutput.Write(" = "); var val = fieldDefinition.CompileTimeValue.Value; bool isFlags = (Utils.FindAttribute(fieldDefinition.ContainingTypeDefinition.Attributes, SpecialAttribute.Flags) != null); bool castNeeded = false; if (isFlags) { // Add cast if necessary var type = fieldDefinition.CompileTimeValue.Type; if (TypeHelper.IsSignedPrimitiveInteger(type) && Convert.ToInt64(val) < 0) { castNeeded = true; sourceEmitterOutput.Write("unchecked(("); PrintTypeReference(type); PrintToken(CSharpToken.RightParenthesis); } } // Output flags values in hex, non-flags in decimal if (isFlags) { this.sourceEmitterOutput.Write(String.Format("0x{0:X}", val)); } else { Traverse(fieldDefinition.CompileTimeValue); } if (castNeeded) { PrintToken(CSharpToken.RightParenthesis); } PrintToken(CSharpToken.Comma); PrintToken(CSharpToken.NewLine); }
public override void TraverseChildren(IFieldDefinition fieldDefinition) { if (fieldDefinition.ContainingType.IsEnum && fieldDefinition.IsRuntimeSpecial && fieldDefinition.IsSpecialName) { return; // implicit value field of an enum } if (!this.printCompilerGeneratedMembers && AttributeHelper.Contains(fieldDefinition.Attributes, fieldDefinition.Type.PlatformType.SystemRuntimeCompilerServicesCompilerGeneratedAttribute)) { return; // eg. a cached anonymous delegate - may have invalid symbols } foreach (var e in fieldDefinition.ContainingTypeDefinition.Events) { if (e.Name == fieldDefinition.Name) { return; // field is probably the implicit delegate backing the event } } // Figure out if this is a special fixed buffer field ICustomAttribute fixedBufferAttr = Utils.FindAttribute(fieldDefinition.Attributes, SpecialAttribute.FixedBuffer); if (fixedBufferAttr == null) { PrintAttributes(fieldDefinition); } if (fieldDefinition.ContainingTypeDefinition.Layout == LayoutKind.Explicit) { PrintPseudoCustomAttribute(fieldDefinition, "System.Runtime.InteropServices.FieldOffset", fieldDefinition.Offset.ToString(), true, null); } PrintToken(CSharpToken.Indent); if (fieldDefinition.IsCompileTimeConstant && fieldDefinition.ContainingType.IsEnum) { PrintFieldDefinitionEnumValue(fieldDefinition); } else { PrintFieldDefinitionVisibility(fieldDefinition); PrintFieldDefinitionModifiers(fieldDefinition); if (fixedBufferAttr == null) { PrintFieldDefinitionType(fieldDefinition); PrintToken(CSharpToken.Space); PrintFieldDefinitionName(fieldDefinition); if (fieldDefinition.IsCompileTimeConstant) { sourceEmitterOutput.Write(" = "); PrintFieldDefinitionValue(fieldDefinition); } } else { PrintFieldDefinitionFixedBuffer(fieldDefinition, fixedBufferAttr); } PrintToken(CSharpToken.Semicolon); } }