/// <summary> /// Specifies whether this attribute applies to derived types and/or overridden methods. /// This information is obtained from an attribute on the attribute type definition. /// </summary> public static bool Inherited(ITypeDefinition attributeType, INameTable nameTable) { foreach (ICustomAttribute ca in attributeType.Attributes) { if (!TypeHelper.TypesAreEquivalent(ca.Type, attributeType.PlatformType.SystemAttributeUsageAttribute)) { continue; } foreach (IMetadataExpression expr in ca.Arguments) { IMetadataNamedArgument /*?*/ namedArgument = expr as IMetadataNamedArgument; if (namedArgument == null) { continue; } if (namedArgument.ArgumentName.UniqueKey == nameTable.AllowMultiple.UniqueKey) { IMetadataConstant /*?*/ compileTimeConst = namedArgument.ArgumentValue as IMetadataConstant; if (compileTimeConst == null || compileTimeConst.Value == null || !(compileTimeConst.Value is bool)) { continue; } //^ assume false; //Unboxing cast might fail return((bool)compileTimeConst.Value); } } } return(false); }
public override void Visit(IMetadataNamedArgument namedArgument) { if (Process(namedArgument)) { visitor.Visit(namedArgument); } base.Visit(namedArgument); }
/// <summary> /// Traverses the metadata named argument expression. /// </summary> public void Traverse(IMetadataNamedArgument namedArgument) { Contract.Requires(namedArgument != null); if (this.preorderVisitor != null) this.preorderVisitor.Visit(namedArgument); if (this.stopTraversal) return; this.TraverseChildren(namedArgument); if (this.stopTraversal) return; if (this.postorderVisitor != null) this.postorderVisitor.Visit(namedArgument); }
public override void TraverseChildren(IMetadataNamedArgument namedArgument) { //The type should already be filled in }
public virtual void onMetadataElement(IMetadataNamedArgument namedArgument) { }
internal CustomAttribute(PEFileToObjectModel peFileToObjectModel, uint attributeRowId, IMethodReference constructor, IMetadataExpression[]/*?*/ arguments, IMetadataNamedArgument[]/*?*/ namedArguments) : base(peFileToObjectModel) { this.AttributeRowId = attributeRowId; this.Constructor = constructor; this.Arguments = arguments; this.NamedArguments = namedArguments; }
public override void TraverseChildren(IMetadataNamedArgument namedArgument) { this.sourceEmitterOutput.Write(namedArgument.ArgumentName.Value+" = "); this.Traverse(namedArgument.ArgumentValue); }
/// <summary> /// Performs some computation with the given metadata named argument expression. /// </summary> public void Visit(IMetadataNamedArgument namedArgument) { //TODO: check for completeness this.Visit((IMetadataExpression)namedArgument); if (namedArgument.ResolvedDefinition != null) { ITypeReference type; IName name; if (namedArgument.IsField) { var field = (IFieldDefinition)namedArgument.ResolvedDefinition; type = field.Type; name = field.Name; } else { var property = (IPropertyDefinition)namedArgument.ResolvedDefinition; type = property.Type; name = property.Name; } if (name.UniqueKey != namedArgument.ArgumentName.UniqueKey) this.ReportError(MetadataError.NamedArgumentNameDoesNotMatchNameOfResolvedFieldOrProperty, namedArgument); if (!TypeHelper.TypesAreEquivalent(type, namedArgument.Type)) this.ReportError(MetadataError.NamedArgumentTypeDoesNotMatchTypeOfResolvedFieldOrProperty, namedArgument); } }
/// <summary> /// Performs some computation with the given metadata named argument expression. /// </summary> public virtual void Visit(IMetadataNamedArgument namedArgument) { this.Visit((IMetadataExpression)namedArgument); }
/// <summary> /// Provides the host with an opportunity to substitute a custom attribute with another during metadata reading. /// This avoids the cost of rewriting the entire unit in order to make such changes. /// </summary> /// <param name="referringUnit">The unit that contains the custom attribute.</param> /// <param name="customAttribute">The custom attribute to rewrite (fix up).</param> /// <returns> /// Usually the value in customAttribute, but occassionally another custom attribute. /// </returns> public override ICustomAttribute Rewrite(IUnit referringUnit, ICustomAttribute customAttribute) { CustomAttribute customAttr = customAttribute as CustomAttribute; if (customAttr == null) return customAttribute; var referringModule = referringUnit as IModule; if (referringModule == null || referringModule.ContainingAssembly == null || !(referringModule.ContainingAssembly.ContainsForeignTypes)) return customAttribute; if (!TypeHelper.TypesAreEquivalent(customAttribute.Type, this.PlatformType.SystemAttributeUsageAttribute)) return customAttribute; //The custom attribute constructor has been redirected from Windows.Foundation.AttributeUsageAttribute, which has a different //set of flags from System.AttributeUsageAttribute for its first and only constructor parameter and also does not have an AllowMultiple property. var argArray = customAttr.Arguments; if (argArray == null || argArray.Length != 1) return customAttribute; var argConst = argArray[0] as ConstantExpression; if (argConst == null || !(argConst.value is int)) return customAttribute; int clrEnumValue = 0; switch ((int)argConst.Value) { case 0x00000001: clrEnumValue = 0x00001000; break; case 0x00000002: clrEnumValue = 0x00000010; break; case 0x00000004: clrEnumValue = 0x00000200; break; case 0x00000008: clrEnumValue = 0x00000100; break; case 0x00000010: clrEnumValue = 0x00000400; break; case 0x00000020: clrEnumValue = 0x00000000; break; case 0x00000040: clrEnumValue = 0x00000040; break; case 0x00000080: clrEnumValue = 0x00000800; break; case 0x00000100: clrEnumValue = 0x00000080; break; case 0x00000200: clrEnumValue = 0x00000004; break; case 0x00000400: clrEnumValue = 0x00000008; break; case 0x00000800: clrEnumValue = 0x00000000; break; case -1: clrEnumValue = 0x00007FFF; break; } argConst.value = clrEnumValue; if (this.FellowCustomAttributeIncludeAllowMultiple(customAttr)) { if (customAttr.NamedArguments != null) return customAttribute; var trueVal = new ConstantExpression(this.PlatformType.SystemBoolean, true); var namedArgArray = new IMetadataNamedArgument[1]; namedArgArray[0] = new FieldOrPropertyNamedArgumentExpression(this.AllowMultiple, Dummy.Type, false, this.PlatformType.SystemBoolean, trueVal); customAttr.NamedArguments = namedArgArray; } return customAttribute; }
/// <summary> /// Performs some computation with the given metadata named argument expression. /// </summary> public virtual void Visit(IMetadataNamedArgument namedArgument) { }
/// <summary> /// Rewrites the given metadata named argument expression. /// </summary> public virtual IMetadataNamedArgument Rewrite(IMetadataNamedArgument namedArgument) { return namedArgument; }
public override void Visit(IMetadataNamedArgument namedArgument) { allElements.Add(new InvokInfo(Traverser, "IMetadataNamedArgument", namedArgument)); }
/// <summary> /// Traverses the children of the metadata named argument expression. /// </summary> public virtual void TraverseChildren(IMetadataNamedArgument namedArgument) { Contract.Requires(namedArgument != null); this.TraverseChildren((IMetadataExpression)namedArgument); if (this.stopTraversal) return; this.Traverse(namedArgument.ArgumentValue); }
public void Visit(IMetadataNamedArgument namedArgument) { this.traverser.Traverse(namedArgument); }
//^ ensures this.path.Count == old(this.path.Count); /// <summary> /// Performs some computation with the given metadata named argument expression. /// </summary> /// <param name="namedArgument"></param> public virtual void Visit(IMetadataNamedArgument namedArgument) { if (this.stopTraversal) return; //^ int oldCount = this.path.Count; this.path.Push(namedArgument); this.Visit(namedArgument.ArgumentValue); //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count. this.path.Pop(); }
public override void TraverseChildren(IMetadataNamedArgument namedArgument) { MethodEnter(namedArgument); base.TraverseChildren(namedArgument); MethodExit(); }
public virtual void Visit(IMetadataNamedArgument namedArgument) { this.Visit(namedArgument.ArgumentValue); }
public void Visit(IMetadataNamedArgument namedArgument) { throw new NotImplementedException(); }
internal CustomAttributeDecoder(PEFileToObjectModel peFileToObjectModel, MemoryReader signatureMemoryReader, uint customAttributeRowId, IMethodReference attributeConstructor) : base(peFileToObjectModel, signatureMemoryReader) { this.CustomAttribute = Dummy.CustomAttribute; ushort prolog = this.SignatureMemoryReader.ReadUInt16(); if (prolog != SerializationType.CustomAttributeStart) return; int len = attributeConstructor.ParameterCount; IMetadataExpression[]/*?*/ exprList = len == 0 ? null : new IMetadataExpression[len]; int i = 0; foreach (var parameter in attributeConstructor.Parameters) { var parameterType = parameter.Type; if (parameterType is Dummy) { // Error... return; } ExpressionBase/*?*/ argument = this.ReadSerializedValue(parameterType); if (argument == null) { // Error... this.decodeFailed = true; return; } exprList[i++] = argument; } IMetadataNamedArgument[]/*?*/ namedArgumentArray = null; if (2 <= (int)this.SignatureMemoryReader.RemainingBytes) { ushort numOfNamedArgs = this.SignatureMemoryReader.ReadUInt16(); if (numOfNamedArgs > 0) { namedArgumentArray = new IMetadataNamedArgument[numOfNamedArgs]; for (i = 0; i < numOfNamedArgs; ++i) { if (0 >= (int)this.SignatureMemoryReader.RemainingBytes) break; bool isField = this.SignatureMemoryReader.ReadByte() == SerializationType.Field; ITypeReference/*?*/ memberType = this.GetFieldOrPropType(); if (memberType == null) { // Error... return; } string/*?*/ memberStr = this.GetSerializedString(); if (memberStr == null) return; IName memberName = this.PEFileToObjectModel.NameTable.GetNameFor(memberStr); ExpressionBase/*?*/ value = this.ReadSerializedValue(memberType); if (value == null) { // Error... return; } ITypeReference/*?*/ moduleTypeRef = attributeConstructor.ContainingType; if (moduleTypeRef == null) { // Error... return; } FieldOrPropertyNamedArgumentExpression namedArg = new FieldOrPropertyNamedArgumentExpression(memberName, moduleTypeRef, isField, memberType, value); namedArgumentArray[i] = namedArg; } } } this.CustomAttribute = peFileToObjectModel.ModuleReader.metadataReaderHost.Rewrite(peFileToObjectModel.Module, new CustomAttribute(peFileToObjectModel, customAttributeRowId, attributeConstructor, exprList, namedArgumentArray)); }
internal SecurityCustomAttribute(SecurityAttribute containingSecurityAttribute, IMethodReference constructorReference, IMetadataNamedArgument[]/*?*/ namedArguments) { this.ContainingSecurityAttribute = containingSecurityAttribute; this.ConstructorReference = constructorReference; this.NamedArguments = namedArguments; }
public override void Visit(IMetadataNamedArgument namedArgument) { if(Process(namedArgument)){visitor.Visit(namedArgument);} base.Visit(namedArgument); }