// compares by namespace and type name, ignores signatures private static bool EarlyDecodeIsTargetAttribute(NamedTypeSymbol attributeType, AttributeSyntax attributeSyntax, AttributeDescription description, bool skipParamCheck = false) { if (!skipParamCheck) { int parameterCount = description.GetParameterCount(signatureIndex: 0); int argumentCount = (attributeSyntax.ArgumentList != null) ? attributeSyntax.ArgumentList.Arguments.Count : 0; if (argumentCount != parameterCount) { return false; } } Debug.Assert(!attributeType.IsErrorType()); string actualNamespaceName = attributeType.ContainingNamespace.ToDisplayString(SymbolDisplayFormat.QualifiedNameOnlyFormat); return actualNamespaceName.Equals(description.Namespace) && attributeType.Name.Equals(description.Name); }
public static IEnumerable <CSharpAttributeData> GetAttributes(this Symbol @this, AttributeDescription description) { return(@this.GetAttributes().Where(a => a.IsTargetAttribute(@this, description))); }
/// <summary> /// Returns a possibly ExtensionAttribute filtered roArray of attributes. If /// filterExtensionAttributes is set to true, the method will remove all ExtensionAttributes /// from the returned array. If it is false, the parameter foundExtension will always be set to /// false and can be safely ignored. /// /// The paramArrayAttribute parameter is similar to the foundExtension parameter, but instead /// of just indicating if the attribute was found, the parameter is set to the attribute handle /// for the ParamArrayAttribute if any is found and is null otherwise. This allows NoPia to filter /// the attribute out for the symbol but still cache it separately for emit. /// </summary> internal ImmutableArray<CSharpAttributeData> GetCustomAttributesForToken(EntityHandle token, out CustomAttributeHandle filteredOutAttribute1, AttributeDescription filterOut1, out CustomAttributeHandle filteredOutAttribute2, AttributeDescription filterOut2) { filteredOutAttribute1 = default(CustomAttributeHandle); filteredOutAttribute2 = default(CustomAttributeHandle); ArrayBuilder<CSharpAttributeData> customAttributesBuilder = null; try { foreach (var customAttributeHandle in _module.GetCustomAttributesOrThrow(token)) { if (filterOut1.Signatures != null && Module.GetTargetAttributeSignatureIndex(customAttributeHandle, filterOut1) != -1) { // It is important to capture the last application of the attribute that we run into, // it makes a difference for default and constant values. filteredOutAttribute1 = customAttributeHandle; continue; } if (filterOut2.Signatures != null && Module.GetTargetAttributeSignatureIndex(customAttributeHandle, filterOut2) != -1) { // It is important to capture the last application of the attribute that we run into, // it makes a difference for default and constant values. filteredOutAttribute2 = customAttributeHandle; continue; } if (customAttributesBuilder == null) { customAttributesBuilder = ArrayBuilder<CSharpAttributeData>.GetInstance(); } customAttributesBuilder.Add(new PEAttributeData(this, customAttributeHandle)); } } catch (BadImageFormatException) { } if (customAttributesBuilder != null) { return customAttributesBuilder.ToImmutableAndFree(); } return ImmutableArray<CSharpAttributeData>.Empty; }
internal override int GetTargetAttributeSignatureIndex(Symbol underlyingSymbol, CSharpAttributeData attrData, AttributeDescription description) { return(attrData.GetTargetAttributeSignatureIndex(underlyingSymbol, description)); }
internal override int GetTargetAttributeSignatureIndex(Symbol targetSymbol, AttributeDescription description) { if (!IsTargetAttribute(description.Namespace, description.Name)) { return(-1); } var ctor = this.AttributeConstructor; // Ensure that the attribute data really has a constructor before comparing the signature. if (ctor is null) { return(-1); } // Lazily loaded System.Type type symbol TypeSymbol?lazySystemType = null; ImmutableArray <ParameterSymbol> parameters = ctor.Parameters; bool foundMatch = false; for (int i = 0; i < description.Signatures.Length; i++) { byte[] targetSignature = description.Signatures[i]; if (targetSignature[0] != (byte)SignatureAttributes.Instance) { continue; } byte parameterCount = targetSignature[1]; if (parameterCount != parameters.Length) { continue; } if ((SignatureTypeCode)targetSignature[2] != SignatureTypeCode.Void) { continue; } foundMatch = (targetSignature.Length == 3); int k = 0; for (int j = 3; j < targetSignature.Length; j++) { if (k >= parameters.Length) { break; } TypeSymbol parameterType = parameters[k].Type; SpecialType specType = parameterType.SpecialType; byte targetType = targetSignature[j]; if (targetType == (byte)SignatureTypeCode.TypeHandle) { j++; if (parameterType.Kind != SymbolKind.NamedType && parameterType.Kind != SymbolKind.ErrorType) { foundMatch = false; break; } var namedType = (NamedTypeSymbol)parameterType; AttributeDescription.TypeHandleTargetInfo targetInfo = AttributeDescription.TypeHandleTargets[targetSignature[j]]; // Compare name and containing symbol name. Uses HasNameQualifier // extension method to avoid string allocations. if (!string.Equals(namedType.MetadataName, targetInfo.Name, System.StringComparison.Ordinal) || !namedType.HasNameQualifier(targetInfo.Namespace)) { foundMatch = false; break; } targetType = (byte)targetInfo.Underlying; if (parameterType.IsEnumType()) { specType = parameterType.GetEnumUnderlyingType() !.SpecialType; } } else if (parameterType.IsArray()) { specType = ((ArrayTypeSymbol)parameterType).ElementType.SpecialType; } switch (targetType) { case (byte)SignatureTypeCode.Boolean: foundMatch = specType == SpecialType.System_Boolean; k += 1; break; case (byte)SignatureTypeCode.Char: foundMatch = specType == SpecialType.System_Char; k += 1; break; case (byte)SignatureTypeCode.SByte: foundMatch = specType == SpecialType.System_SByte; k += 1; break; case (byte)SignatureTypeCode.Byte: foundMatch = specType == SpecialType.System_Byte; k += 1; break; case (byte)SignatureTypeCode.Int16: foundMatch = specType == SpecialType.System_Int16; k += 1; break; case (byte)SignatureTypeCode.UInt16: foundMatch = specType == SpecialType.System_UInt16; k += 1; break; case (byte)SignatureTypeCode.Int32: foundMatch = specType == SpecialType.System_Int32; k += 1; break; case (byte)SignatureTypeCode.UInt32: foundMatch = specType == SpecialType.System_UInt32; k += 1; break; case (byte)SignatureTypeCode.Int64: foundMatch = specType == SpecialType.System_Int64; k += 1; break; case (byte)SignatureTypeCode.UInt64: foundMatch = specType == SpecialType.System_UInt64; k += 1; break; case (byte)SignatureTypeCode.Single: foundMatch = specType == SpecialType.System_Single; k += 1; break; case (byte)SignatureTypeCode.Double: foundMatch = specType == SpecialType.System_Double; k += 1; break; case (byte)SignatureTypeCode.String: foundMatch = specType == SpecialType.System_String; k += 1; break; case (byte)SignatureTypeCode.Object: foundMatch = specType == SpecialType.System_Object; k += 1; break; case (byte)SerializationTypeCode.Type: if (lazySystemType is null) { lazySystemType = GetSystemType(targetSymbol); } foundMatch = TypeSymbol.Equals(parameterType, lazySystemType, TypeCompareKind.ConsiderEverything2); k += 1; break; case (byte)SignatureTypeCode.SZArray: // Skip over and check the next byte foundMatch = parameterType.IsArray(); break; default: return(-1); } if (!foundMatch) { break; } } if (foundMatch) { return(i); } } Debug.Assert(!foundMatch); return(-1); }
internal bool IsTargetAttribute(TSymbol underlyingSymbol, TAttributeData attrData, AttributeDescription description) { return(GetTargetAttributeSignatureIndex(underlyingSymbol, attrData, description) != -1); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public static AttributeSyntax ToAttributeSyntax(this AttributeDescription description) { return(AttributeSyntaxEmitter.EmitSyntax(description)); }
internal abstract int GetTargetAttributeSignatureIndex(Symbol targetSymbol, AttributeDescription description);
internal override int GetTargetAttributeSignatureIndex(Symbol targetSymbol, AttributeDescription description) { throw new NotImplementedException(); }
/// <summary> /// Enhances or animates the texture coordinates using already existing base coordinates of (0, 0, 1, 1) or similar /// (base texture coordinates may differ depending on the actual shape) /// </summary> /// <param name="vertexBuilder">Target vertex buffer builder to use</param> /// <param name="sorter"><see cref="ParticleSorter"/> to use to iterate over all particles drawn this frame</param> /// <param name="texCoordsDescription">Attribute description of the texture coordinates in the current vertex layout</param> public abstract void BuildUVCoordinates(ParticleVertexBuilder vertexBuilder, ParticleSorter sorter, AttributeDescription texCoordsDescription);
internal override int GetTargetAttributeSignatureIndex(Symbol targetSymbol, AttributeDescription description) { if (!IsTargetAttribute(description.Namespace, description.Name)) { return(-1); } var ctor = this.AttributeConstructor; // Ensure that the attribute data really has a constructor before comparing the signature. if (ctor is null) { return(-1); } // Lazily loaded System.Type type symbol TypeSymbol?lazySystemType = null; ImmutableArray <ParameterSymbol> parameters = ctor.Parameters; for (int signatureIndex = 0; signatureIndex < description.Signatures.Length; signatureIndex++) { byte[] targetSignature = description.Signatures[signatureIndex]; if (matches(targetSignature, parameters, ref lazySystemType)) { return(signatureIndex); } } return(-1); bool matches(byte[] targetSignature, ImmutableArray <ParameterSymbol> parameters, ref TypeSymbol?lazySystemType) { if (targetSignature[0] != (byte)SignatureAttributes.Instance) { return(false); } byte parameterCount = targetSignature[1]; if (parameterCount != parameters.Length) { return(false); } if ((SignatureTypeCode)targetSignature[2] != SignatureTypeCode.Void) { return(false); } int parameterIndex = 0; for (int signatureByteIndex = 3; signatureByteIndex < targetSignature.Length; signatureByteIndex++) { if (parameterIndex >= parameters.Length) { return(false); } TypeSymbol parameterType = parameters[parameterIndex].Type; SpecialType specType = parameterType.SpecialType; byte targetType = targetSignature[signatureByteIndex]; if (targetType == (byte)SignatureTypeCode.TypeHandle) { signatureByteIndex++; if (parameterType.Kind != SymbolKind.NamedType && parameterType.Kind != SymbolKind.ErrorType) { return(false); } var namedType = (NamedTypeSymbol)parameterType; AttributeDescription.TypeHandleTargetInfo targetInfo = AttributeDescription.TypeHandleTargets[targetSignature[signatureByteIndex]]; // Compare name and containing symbol name. Uses HasNameQualifier // extension method to avoid string allocations. if (!string.Equals(namedType.MetadataName, targetInfo.Name, System.StringComparison.Ordinal) || !namedType.HasNameQualifier(targetInfo.Namespace)) { return(false); } targetType = (byte)targetInfo.Underlying; if (parameterType.IsEnumType()) { specType = parameterType.GetEnumUnderlyingType() !.SpecialType; } } else if (targetType != (byte)SignatureTypeCode.SZArray && parameterType.IsArray()) { if (targetSignature[signatureByteIndex - 1] != (byte)SignatureTypeCode.SZArray) { return(false); } specType = ((ArrayTypeSymbol)parameterType).ElementType.SpecialType; } switch (targetType) { case (byte)SignatureTypeCode.Boolean: if (specType != SpecialType.System_Boolean) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Char: if (specType != SpecialType.System_Char) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.SByte: if (specType != SpecialType.System_SByte) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Byte: if (specType != SpecialType.System_Byte) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Int16: if (specType != SpecialType.System_Int16) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.UInt16: if (specType != SpecialType.System_UInt16) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Int32: if (specType != SpecialType.System_Int32) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.UInt32: if (specType != SpecialType.System_UInt32) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Int64: if (specType != SpecialType.System_Int64) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.UInt64: if (specType != SpecialType.System_UInt64) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Single: if (specType != SpecialType.System_Single) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Double: if (specType != SpecialType.System_Double) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.String: if (specType != SpecialType.System_String) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.Object: if (specType != SpecialType.System_Object) { return(false); } parameterIndex += 1; break; case (byte)SerializationTypeCode.Type: lazySystemType ??= GetSystemType(targetSymbol); if (!TypeSymbol.Equals(parameterType, lazySystemType, TypeCompareKind.ConsiderEverything)) { return(false); } parameterIndex += 1; break; case (byte)SignatureTypeCode.SZArray: // Skip over and check the next byte if (!parameterType.IsArray()) { return(false); } break; default: return(false); } } return(true); } }
/// <inheritdoc /> public override unsafe void BuildUVCoordinates(ref ParticleBufferState bufferState, ref ParticleList sorter, AttributeDescription texCoordsDescription) { var lifeField = sorter.GetField(ParticleFields.RemainingLife); if (!lifeField.IsValid()) { return; } var texAttribute = bufferState.GetAccessor(texCoordsDescription); if (texAttribute.Size == 0 && texAttribute.Offset == 0) { return; } var texDefault = bufferState.GetAccessor(bufferState.DefaultTexCoords); if (texDefault.Size == 0 && texDefault.Offset == 0) { return; } foreach (var particle in sorter) { var normalizedTimeline = 1f - *(float *)(particle[lifeField]); var spriteId = startingFrame + (int)(normalizedTimeline * animationSpeedOverLife); Vector4 uvTransform = new Vector4((spriteId % xDivisions) * xStep, (spriteId / xDivisions) * yStep, xStep, yStep); bufferState.TransformAttributePerParticle(texDefault, texAttribute, this, ref uvTransform); bufferState.NextParticle(); } bufferState.StartOver(); }
public override void VisitAttribute(AttributeDescription attribute) { base.VisitAttribute(attribute); AddReferencedType(attribute.AttributeType); }
/// <summary> /// Enhances or animates the texture coordinates using already existing base coordinates of (0, 0, 1, 1) or similar /// (base texture coordinates may differ depending on the actual shape) /// </summary> /// <param name="bufferState">The particle buffer state which is used to build the assigned vertex buffer</param> /// <param name="sorter"><see cref="ParticleSorter"/> to use to iterate over all particles drawn this frame</param> /// <param name="texCoordsDescription">Attribute description of the texture coordinates in the current vertex layout</param> public abstract void BuildUVCoordinates(ref ParticleBufferState bufferState, ref ParticleList sorter, AttributeDescription texCoordsDescription);
public override void MakeSchemaCompliant() { base.MakeSchemaCompliant(); AttributeDescription.MakeSchemaCompliant(); ContentType.MakeSchemaCompliant(); }
/// <summary> /// This method finds an attribute by metadata name and signature. The algorithm for signature matching is similar to the one /// in Module.GetTargetAttributeSignatureIndex. Note, the signature matching is limited to primitive types /// and System.Type. It will not match an arbitrary signature but it is sufficient to match the signatures of the current set of /// well known attributes. /// </summary> /// <param name="targetSymbol">The symbol which is the target of the attribute</param> /// <param name="description">The attribute to match.</param> internal override int GetTargetAttributeSignatureIndex(Symbol targetSymbol, AttributeDescription description) { if (!IsTargetAttribute(description.Namespace, description.Name)) { return -1; } var ctor = this.AttributeConstructor; // Ensure that the attribute data really has a constructor before comparing the signature. if ((object)ctor == null) { return -1; } // Lazily loaded System.Type type symbol TypeSymbol lazySystemType = null; ImmutableArray<ParameterSymbol> parameters = ctor.Parameters; bool foundMatch = false; for (int i = 0; i < description.Signatures.Length; i++) { byte[] targetSignature = description.Signatures[i]; if (targetSignature[0] != SignatureHeader.HasThis) { continue; } byte parameterCount = targetSignature[1]; if (parameterCount != parameters.Length) { continue; } if ((SignatureTypeCode)targetSignature[2] != SignatureTypeCode.Void) { continue; } foundMatch = (targetSignature.Length == 3); int k = 0; for (int j = 3; j < targetSignature.Length; j++) { if (k >= parameters.Length) { break; } TypeSymbol parameterType = parameters[k].Type; SpecialType specType = parameterType.SpecialType; byte targetType = targetSignature[j]; if (targetType == (byte)SignatureTypeCode.TypeHandle) { j++; if (parameterType.Kind != SymbolKind.NamedType && parameterType.Kind != SymbolKind.ErrorType) { foundMatch = false; break; } var namedType = (NamedTypeSymbol)parameterType; AttributeDescription.TypeHandleTargetInfo targetInfo = AttributeDescription.TypeHandleTargets[targetSignature[j]]; // Compare name and containing symbol name. Uses HasNameQualifier // extension method to avoid string allocations. if (!string.Equals(namedType.MetadataName, targetInfo.Name, System.StringComparison.Ordinal) || !namedType.HasNameQualifier(targetInfo.Namespace)) { foundMatch = false; break; } targetType = (byte)targetInfo.Underlying; if (parameterType.IsEnumType()) { specType = parameterType.GetEnumUnderlyingType().SpecialType; } } else if (parameterType.IsArray()) { specType = ((ArrayTypeSymbol)parameterType).ElementType.SpecialType; } switch (targetType) { case (byte)SignatureTypeCode.Boolean: foundMatch = specType == SpecialType.System_Boolean; k += 1; break; case (byte)SignatureTypeCode.Char: foundMatch = specType == SpecialType.System_Char; k += 1; break; case (byte)SignatureTypeCode.SByte: foundMatch = specType == SpecialType.System_SByte; k += 1; break; case (byte)SignatureTypeCode.Byte: foundMatch = specType == SpecialType.System_Byte; k += 1; break; case (byte)SignatureTypeCode.Int16: foundMatch = specType == SpecialType.System_Int16; k += 1; break; case (byte)SignatureTypeCode.UInt16: foundMatch = specType == SpecialType.System_UInt16; k += 1; break; case (byte)SignatureTypeCode.Int32: foundMatch = specType == SpecialType.System_Int32; k += 1; break; case (byte)SignatureTypeCode.UInt32: foundMatch = specType == SpecialType.System_UInt32; k += 1; break; case (byte)SignatureTypeCode.Int64: foundMatch = specType == SpecialType.System_Int64; k += 1; break; case (byte)SignatureTypeCode.UInt64: foundMatch = specType == SpecialType.System_UInt64; k += 1; break; case (byte)SignatureTypeCode.Single: foundMatch = specType == SpecialType.System_Single; k += 1; break; case (byte)SignatureTypeCode.Double: foundMatch = specType == SpecialType.System_Double; k += 1; break; case (byte)SignatureTypeCode.String: foundMatch = specType == SpecialType.System_String; k += 1; break; case (byte)SignatureTypeCode.Object: foundMatch = specType == SpecialType.System_Object; k += 1; break; case (byte)SerializationTypeCode.Type: if ((object)lazySystemType == null) { lazySystemType = GetSystemType(targetSymbol); } foundMatch = parameterType == lazySystemType; k += 1; break; case (byte)SignatureTypeCode.SZArray: // Skip over and check the next byte foundMatch = parameterType.IsArray(); break; default: return -1; } if (!foundMatch) { break; } } if (foundMatch) { return i; } } Debug.Assert(!foundMatch); return -1; }
internal static int IndexOfAttribute(this ImmutableArray <CSharpAttributeData> attributes, Symbol targetSymbol, AttributeDescription description) { for (int i = 0; i < attributes.Length; i++) { if (attributes[i].IsTargetAttribute(targetSymbol, description)) { return(i); } } return(-1); }
/// <inheritdoc /> public unsafe override void BuildUVCoordinates(ParticleVertexBuilder vertexBuilder, ParticleSorter sorter, AttributeDescription texCoordsDescription) { var lifeField = sorter.GetField(ParticleFields.RemainingLife); if (!lifeField.IsValid()) { return; } var texAttribute = vertexBuilder.GetAccessor(texCoordsDescription); if (texAttribute.Size == 0 && texAttribute.Offset == 0) { return; } var texDefault = vertexBuilder.GetAccessor(vertexBuilder.DefaultTexCoords); if (texDefault.Size == 0 && texDefault.Offset == 0) { return; } foreach (var particle in sorter) { var normalizedTimeline = 1f - *(float *)(particle[lifeField]);; var uvTransform = Vector4.Lerp(StartFrame, EndFrame, normalizedTimeline); uvTransform.Z -= uvTransform.X; uvTransform.W -= uvTransform.Y; ParticleVertexBuilder.TransformAttributeDelegate <Vector2> transformCoords = (ref Vector2 value) => { value.X = uvTransform.X + uvTransform.Z * value.X; value.Y = uvTransform.Y + uvTransform.W * value.Y; }; vertexBuilder.TransformAttributePerParticle(texDefault, texAttribute, transformCoords); vertexBuilder.NextParticle(); } vertexBuilder.RestartBuffer(); }
protected abstract void ReportMissingAttribute(AttributeDescription description, TSyntaxNode syntaxNodeOpt, DiagnosticBag diagnostics);
private CSharpAttributeData EarlyDecodeAttributeForDefaultParameterValue(AttributeDescription description, ref EarlyDecodeWellKnownAttributeArguments<EarlyWellKnownAttributeBinder, NamedTypeSymbol, AttributeSyntax, AttributeLocation> arguments) { Debug.Assert(description.Equals(AttributeDescription.DefaultParameterValueAttribute) || description.Equals(AttributeDescription.DecimalConstantAttribute) || description.Equals(AttributeDescription.DateTimeConstantAttribute)); bool hasAnyDiagnostics; var attribute = arguments.Binder.GetAttribute(arguments.AttributeSyntax, arguments.AttributeType, out hasAnyDiagnostics); ConstantValue value; if (attribute.HasErrors) { value = ConstantValue.Bad; hasAnyDiagnostics = true; } else { value = DecodeDefaultParameterValueAttribute(description, attribute, arguments.AttributeSyntax, diagnose: false, diagnosticsOpt: null); } var paramData = arguments.GetOrCreateData<ParameterEarlyWellKnownAttributeData>(); if (paramData.DefaultParameterValue == ConstantValue.Unset) { paramData.DefaultParameterValue = value; } return !hasAnyDiagnostics ? attribute : null; }
internal abstract int GetTargetAttributeSignatureIndex(TSymbol underlyingSymbol, TAttributeData attrData, AttributeDescription description);
private void DecodeDefaultParameterValueAttribute(AttributeDescription description, ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments) { var attribute = arguments.Attribute; var syntax = arguments.AttributeSyntaxOpt; var diagnostics = arguments.Diagnostics; Debug.Assert(syntax != null); Debug.Assert(diagnostics != null); var value = DecodeDefaultParameterValueAttribute(description, attribute, syntax, diagnose: true, diagnosticsOpt: diagnostics); if (!value.IsBad) { VerifyParamDefaultValueMatchesAttributeIfAny(value, syntax, diagnostics); } }
private void CreateEmbeddedAttributeIfNeeded(ref SynthesizedEmbeddedAttributeSymbol symbol, DiagnosticBag diagnostics, AttributeDescription description) { if ((object)symbol == null) { var attributeMetadataName = MetadataTypeName.FromFullName(description.FullName); var userDefinedAttribute = _sourceAssembly.SourceModule.LookupTopLevelMetadataType(ref attributeMetadataName); Debug.Assert((object)userDefinedAttribute.ContainingModule == _sourceAssembly.SourceModule); if (!(userDefinedAttribute is MissingMetadataTypeSymbol)) { diagnostics.Add(ErrorCode.ERR_TypeReserved, userDefinedAttribute.Locations[0], description.FullName); } symbol = new SynthesizedEmbeddedAttributeSymbol(description, _sourceAssembly.DeclaringCompilation, diagnostics); } }
private ConstantValue DecodeDefaultParameterValueAttribute(AttributeDescription description, CSharpAttributeData attribute, AttributeSyntax node, bool diagnose, DiagnosticBag diagnosticsOpt) { Debug.Assert(!attribute.HasErrors); if (description.Equals(AttributeDescription.DefaultParameterValueAttribute)) { return DecodeDefaultParameterValueAttribute(attribute, node, diagnose, diagnosticsOpt); } else if (description.Equals(AttributeDescription.DecimalConstantAttribute)) { return attribute.DecodeDecimalConstantValue(); } else { Debug.Assert(description.Equals(AttributeDescription.DateTimeConstantAttribute)); return attribute.DecodeDateTimeConstantValue(); } }
protected override void ReportMissingAttribute(AttributeDescription description, SyntaxNode syntaxNodeOpt, DiagnosticBag diagnostics) { EmbeddedTypesManager.Error(diagnostics, ErrorCode.ERR_InteropTypeMissingAttribute, syntaxNodeOpt, UnderlyingNamedType, description.FullName); }
/// <summary> /// Matches an attribute by metadata namespace, metadata type name and metadata signature. Does not load the /// type symbol for the attribute. /// </summary> /// <param name="targetSymbol">Target symbol.</param> /// <param name="description">Attribute to match.</param> /// <returns> /// An index of the target constructor signature in /// signatures array, -1 if /// this is not the target attribute. /// </returns> internal override int GetTargetAttributeSignatureIndex(Symbol targetSymbol, AttributeDescription description) { // Matching an attribute by name should not load the attribute class. return _decoder.GetTargetAttributeSignatureIndex(_handle, description); }
/* * first time running this by just changing the filter a little i got this message. * There was an error generating the XML document. ---> System.InvalidOperationException: * Value of ItemElementName mismatches the type of DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.SubstringFilter; * you need to set it to DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.ItemChoiceType.@substrings. * * * System.InvalidOperationException: There was an error generating the XML document. ---> * System.InvalidOperationException: Value of ItemElementName mismatches the type of DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.SubstringFilter; * you need to set it to DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.ItemChoiceType.@substrings. * * * The next time I changed out the ava filter for a substring type and got this message * Error Response * [LDAP: error code 50 - Search filter not permitted (substring too short)] */ public IEnumerable <NyGovUser> GetUsers(String ou) { GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888); List <NyGovUser> returnList = new List <NyGovUser>(); //example OU |||| dn =”ou = Department of General Services,ou = Government,o = ny,c = us BatchRequest batch = new BatchRequest(); SearchRequest search = new SearchRequest(); Filter filter = new Filter(); dsmlQueryService client = new dsmlQueryService(); client.Url = "https://qadaws.svc.ny.gov/daws/services/dsmlSoapQuery"; batch.searchRequest = new SearchRequest[1] { search }; client.Credentials = new NetworkCredential("prxwsTL1HESC", "sfvwRMnB7N"); search.dn = "'ou = Department of General Services,ou = Government,o = ny,c = us'"; //search.dn = ou; //can't use attribute value assertion for substring choice. instead make substring filter //AttributeValueAssertion ava = new AttributeValueAssertion(); //ava.name = "nyacctgovernment"; //ava.value = "Y"; SubstringFilter[] substrings = new SubstringFilter[4]; SubstringFilter substring = new SubstringFilter(); substring.name = "nyacctgovernment"; substring.initial = "Y"; substrings[0] = substring; SubstringFilter substring1 = new SubstringFilter(); substring1.name = "nyacctlevel1"; substring1.initial = "Y"; substrings[1] = substring1; SubstringFilter substring2 = new SubstringFilter(); substring2.name = "sn"; substring2.initial = "smith"; substrings[2] = substring2; SubstringFilter substring3 = new SubstringFilter(); substring3.name = "ou"; substring3.initial = "Department of General Services"; substrings[3] = substring3; //FilterSet fSet = new FilterSet(); //ItemsChoiceType[] chioceTypes = new ItemsChoiceType[4]; //fSet.ItemsElementName = chioceTypes; filter.ItemElementName = ItemChoiceType.substrings; filter.Item = substring2; search.filter = filter; search.scope = SearchRequestScope.wholeSubtree; AttributeDescriptions attrBucket = new AttributeDescriptions(); AttributeDescription[] attributeDescriptionList = new AttributeDescription[7]; attributeDescriptionList[0] = new AttributeDescription() { name = "nyacctgovernment" }; attributeDescriptionList[1] = new AttributeDescription() { name = "sn" }; attributeDescriptionList[2] = new AttributeDescription() { name = "givenname" }; attributeDescriptionList[3] = new AttributeDescription() { name = "mail" }; attributeDescriptionList[4] = new AttributeDescription() { name = "uid" }; attributeDescriptionList[5] = new AttributeDescription() { name = "nyacctpersonal" }; attributeDescriptionList[6] = new AttributeDescription() { name = "nyacctbusiness" }; attrBucket.attribute = attributeDescriptionList; search.attributes = attrBucket; //client.PreAuthenticate = true; //client.AllowAutoRedirect = true; BatchResponse response = null; try { //WebProxy myproxy = new WebProxy("proxy-internet.cio.state.nyenet", 80); //myproxy.BypassProxyOnLocal = false; //myproxy.Credentials = new NetworkCredential("mjordan", "fuckU023$6"); //client.Proxy = myproxy; response = client.directoryRequest(batch); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Dang it. probably a 502 from the server and even more probable about async. " + e); } System.Diagnostics.Debug.WriteLine("just sent the request for a batch seach to directory request"); System.Diagnostics.Debug.WriteLine("Response: " + response); if (response != null) { SearchResponse[] sResponses = response.searchResponse; System.Diagnostics.Debug.WriteLine("Search Response: " + sResponses); if (sResponses != null) { System.Diagnostics.Debug.WriteLine("Got " + sResponses.Length + " responses"); for (int i = 0; i < sResponses.Length; i++) { System.Diagnostics.Debug.WriteLine("Search Response #" + i + " requestID: " + sResponses[i].requestID); SearchResultEntry[] srEntries = sResponses[i].searchResultEntry; LDAPResult srd = sResponses[i].searchResultDone; if (srd != null) { System.Diagnostics.Debug.WriteLine("LDAP Result AKA search result done"); System.Diagnostics.Debug.WriteLine(srd.resultCode.descr); } if (srEntries != null) { System.Diagnostics.Debug.WriteLine("Search Result Entries Cycle"); for (int r = 0; r < srEntries.Length; r++) { NyGovUser user = new NyGovUser(); user.NysSogUid = srEntries[r].dn; System.Diagnostics.Debug.WriteLine(srEntries[r].dn); System.Diagnostics.Debug.WriteLine(srEntries[r].attr); DsmlAttr[] attributeList = srEntries[r].attr; if (attributeList != null) { for (int a = 0; a < attributeList.Length; a++) { System.Diagnostics.Debug.WriteLine("name: " + attributeList[a].name); String attName = attributeList[a].name; StringBuilder valueBuilder = new StringBuilder(); if (attributeList[a].value != null) { for (int x = 0; x < attributeList[a].value.Length; x++) { System.Diagnostics.Debug.WriteLine("value: " + attributeList[a].value[x]); valueBuilder.Append(attributeList[a].value[x]); } } if (attName.Equals("uid")) { user.Uid = valueBuilder.ToString(); } else if (attName.Equals("cn")) { user.CommonName = valueBuilder.ToString(); } else if (attName.Equals("nyacctgovernment")) { user.IsGovernmentAccount = Convert.ToBoolean(valueBuilder.ToString()); } else if (attName.Equals("sn")) { user.Surname = valueBuilder.ToString(); } else if (attName.Equals("givenname")) { user.Firstname = valueBuilder.ToString(); } else if (attName.Equals("mail")) { user.EmailAddress = valueBuilder.ToString(); } else if (attName.Equals("nyacctbusiness")) { user.IsBusinessPartnerAccount = Convert.ToBoolean(valueBuilder.ToString()); } else if (attName.Equals("nyacctpersonal")) { user.IsCitizenAccount = Convert.ToBoolean(valueBuilder.ToString()); } } } returnList.Add(user); } } else { System.Diagnostics.Debug.WriteLine("Search results list is null for some reason"); } } } ErrorResponse[] eResponses = response.errorResponse; if (eResponses != null) { System.Diagnostics.Debug.WriteLine("Checking out errors from the batch response"); System.Diagnostics.Debug.WriteLine("Errors Count: " + eResponses.Length); //After adding a attribute value assertion and fitler to the search the error response ends up null so make a check for that if (eResponses != null) { if (eResponses.Length > 0) { System.Diagnostics.Debug.WriteLine("Error Response"); for (int i = 0; i < eResponses.Length; i++) { ErrorResponse error = eResponses[i]; System.Diagnostics.Debug.WriteLine(error.message); System.Diagnostics.Debug.WriteLine(error.detail); System.Diagnostics.Debug.WriteLine(error.type); } } } } else { System.Diagnostics.Debug.WriteLine("No errors from the response"); } } return(returnList); }
private bool VerifyObsoleteAttributeAppliedToMethod( ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments, AttributeDescription description) { if (arguments.Attribute.IsTargetAttribute(this, description)) { if (this.IsAccessor()) { // CS1667: Attribute '{0}' is not valid on property or event accessors. It is only valid on '{1}' declarations. AttributeUsageInfo attributeUsage = arguments.Attribute.AttributeClass.GetAttributeUsageInfo(); arguments.Diagnostics.Add(ErrorCode.ERR_AttributeNotOnAccessor, arguments.AttributeSyntaxOpt.Name.Location, description.FullName, attributeUsage.GetValidTargetsString()); } return true; } return false; }
internal TypeSymbol TryDecodeAttributeWithTypeArgument(EntityHandle handle, AttributeDescription attributeDescription) { string typeName; if (_module.HasStringValuedAttribute(handle, attributeDescription, out typeName)) { return new MetadataDecoder(this).GetTypeSymbolForSerializedType(typeName); } return null; }
public override ImmutableArray <CSharpAttributeData> GetAttributes() { if (_lazyCustomAttributes.IsDefault) { Debug.Assert(!_handle.IsNil); var containingPEModuleSymbol = (PEModuleSymbol)this.ContainingModule; // Filter out ParamArrayAttributes if necessary and cache // the attribute handle for GetCustomAttributesToEmit bool filterOutParamArrayAttribute = (!_lazyIsParams.HasValue() || _lazyIsParams.Value()); ConstantValue defaultValue = this.ExplicitDefaultConstantValue; AttributeDescription filterOutConstantAttributeDescription = default(AttributeDescription); if ((object)defaultValue != null) { if (defaultValue.Discriminator == ConstantValueTypeDiscriminator.DateTime) { filterOutConstantAttributeDescription = AttributeDescription.DateTimeConstantAttribute; } else if (defaultValue.Discriminator == ConstantValueTypeDiscriminator.Decimal) { filterOutConstantAttributeDescription = AttributeDescription.DecimalConstantAttribute; } } if (filterOutParamArrayAttribute || filterOutConstantAttributeDescription.Signatures != null) { CustomAttributeHandle paramArrayAttribute; CustomAttributeHandle constantAttribute; ImmutableArray <CSharpAttributeData> attributes = containingPEModuleSymbol.GetCustomAttributesForToken( _handle, out paramArrayAttribute, filterOutParamArrayAttribute ? AttributeDescription.ParamArrayAttribute : default(AttributeDescription), out constantAttribute, filterOutConstantAttributeDescription); if (!paramArrayAttribute.IsNil || !constantAttribute.IsNil) { var builder = ArrayBuilder <CSharpAttributeData> .GetInstance(); if (!paramArrayAttribute.IsNil) { builder.Add(new PEAttributeData(containingPEModuleSymbol, paramArrayAttribute)); } if (!constantAttribute.IsNil) { builder.Add(new PEAttributeData(containingPEModuleSymbol, constantAttribute)); } ImmutableInterlocked.InterlockedInitialize(ref _lazyHiddenAttributes, builder.ToImmutableAndFree()); } else { ImmutableInterlocked.InterlockedInitialize(ref _lazyHiddenAttributes, ImmutableArray <CSharpAttributeData> .Empty); } if (!_lazyIsParams.HasValue()) { Debug.Assert(filterOutParamArrayAttribute); _lazyIsParams = (!paramArrayAttribute.IsNil).ToThreeState(); } ImmutableInterlocked.InterlockedInitialize( ref _lazyCustomAttributes, attributes); } else { ImmutableInterlocked.InterlockedInitialize(ref _lazyHiddenAttributes, ImmutableArray <CSharpAttributeData> .Empty); containingPEModuleSymbol.LoadCustomAttributes(_handle, ref _lazyCustomAttributes); } } Debug.Assert(!_lazyHiddenAttributes.IsDefault); return(_lazyCustomAttributes); }
/// <summary> /// Matches an attribute by metadata namespace, metadata type name and metadata signature. Does not load the /// type symbol for the attribute. /// </summary> /// <param name="targetSymbol">Target symbol.</param> /// <param name="description">Attribute to match.</param> /// <returns> /// An index of the target constructor signature in /// signatures array, -1 if /// this is not the target attribute. /// </returns> internal override int GetTargetAttributeSignatureIndex(Symbol targetSymbol, AttributeDescription description) { // Matching an attribute by name should not load the attribute class. return(_decoder.GetTargetAttributeSignatureIndex(_handle, description)); }
/// <summary> /// Checks if an applied attribute with the given attributeType matches the namespace name and type name of the given early attribute's description /// and the attribute description has a signature with parameter count equal to the given attributeArgCount. /// NOTE: We don't allow early decoded attributes to have optional parameters. /// </summary> internal static bool IsTargetEarlyAttribute(INamedTypeSymbol attributeType, int attributeArgCount, AttributeDescription description) { int attributeCtorsCount = description.Signatures.Length; for (int i = 0; i < attributeCtorsCount; i++) { int parameterCount = description.GetParameterCount(signatureIndex: i); // NOTE: Below assumption disallows early decoding well-known attributes with optional parameters. if (attributeArgCount == parameterCount) { string actualNamespaceAndNestedType = attributeType.ContainingSymbol.ToDisplayString(SymbolDisplayFormat.QualifiedNameOnlyFormat); StringComparison options = description.MatchIgnoringCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; return(actualNamespaceAndNestedType.Equals(description.NamespaceAndNestedType, options) && attributeType.Name.Equals(description.Name, options)); } } return(false); }
internal ImmutableArray <CSharpAttributeData> GetCustomAttributesForToken(EntityHandle token, out CustomAttributeHandle filteredOutAttribute1, AttributeDescription filterOut1) { return(GetCustomAttributesForToken(token, out filteredOutAttribute1, filterOut1, out _, default, out _, default, out _, default));
/// <inheritdoc /> public unsafe override void BuildUVCoordinates(ref ParticleBufferState bufferState, ref ParticleList sorter, AttributeDescription texCoordsDescription) { var lifeField = sorter.GetField(ParticleFields.RemainingLife); if (!lifeField.IsValid()) { return; } var texAttribute = bufferState.GetAccessor(texCoordsDescription); if (texAttribute.Size == 0 && texAttribute.Offset == 0) { return; } var texDefault = bufferState.GetAccessor(bufferState.DefaultTexCoords); if (texDefault.Size == 0 && texDefault.Offset == 0) { return; } foreach (var particle in sorter) { var normalizedTimeline = 1f - *(float *)(particle[lifeField]);; Vector4 uvTransform = Vector4.Lerp(StartFrame, EndFrame, normalizedTimeline); uvTransform.Z -= uvTransform.X; uvTransform.W -= uvTransform.Y; bufferState.TransformAttributePerSegment(texDefault, texAttribute, this, ref uvTransform); bufferState.NextSegment(); } bufferState.StartOver(); }
internal bool IsTargetAttribute(Symbol targetSymbol, AttributeDescription description) { return(GetTargetAttributeSignatureIndex(targetSymbol, description) != -1); }
protected override void ReportMissingAttribute(AttributeDescription description, CSharpSyntaxNode syntaxNodeOpt, DiagnosticBag diagnostics) { EmbeddedTypesManager.Error(diagnostics, ErrorCode.ERR_InteropTypeMissingAttribute, syntaxNodeOpt, UnderlyingNamedType, description.FullName); }
/// <summary> /// Checks if an applied attribute with the given attributeType matches the namespace name and type name of the given early attribute's description /// and the attribute description has a signature with parameter count equal to the given attribute syntax's argument list count. /// NOTE: We don't allow early decoded attributes to have optional parameters. /// </summary> internal static bool IsTargetEarlyAttribute(NamedTypeSymbol attributeType, AttributeSyntax attributeSyntax, AttributeDescription description) { Debug.Assert(!attributeType.IsErrorType()); int argumentCount = (attributeSyntax.ArgumentList != null) ? attributeSyntax.ArgumentList.Arguments.Count((arg) => arg.NameEquals == null) : 0; return(AttributeData.IsTargetEarlyAttribute(attributeType, argumentCount, description)); }
/// <summary> /// Checks if an applied attribute with the given attributeType matches the namespace name and type name of the given early attribute's description /// and the attribute description has a signature with parameter count equal to the given attributeArgCount. /// NOTE: We don't allow early decoded attributes to have optional parameters. /// </summary> internal static bool IsTargetEarlyAttribute(INamedTypeSymbolInternal attributeType, int attributeArgCount, AttributeDescription description) { if (attributeType.ContainingSymbol?.Kind != SymbolKind.Namespace) { return(false); } int attributeCtorsCount = description.Signatures.Length; for (int i = 0; i < attributeCtorsCount; i++) { int parameterCount = description.GetParameterCount(signatureIndex: i); // NOTE: Below assumption disallows early decoding well-known attributes with optional parameters. if (attributeArgCount == parameterCount) { StringComparison options = description.MatchIgnoringCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; return(attributeType.Name.Equals(description.Name, options) && namespaceMatch(attributeType.ContainingNamespace, description.Namespace, options)); } } return(false);
private bool IsTargetAttribute(TAttributeData attrData, AttributeDescription description) { return(TypeManager.IsTargetAttribute(UnderlyingNamedType, attrData, description)); }
internal static void CheckAttribute(IEnumerable <byte> assembly, IMethodSymbol method, AttributeDescription description, bool expected) { var module = AssemblyMetadata.CreateFromImage(assembly).GetModules().Single().Module; var typeName = method.ContainingType.Name; var typeHandle = module.MetadataReader.TypeDefinitions .Single(handle => module.GetTypeDefNameOrThrow(handle) == typeName); var methodName = method.Name; var methodHandle = module .GetMethodsOfTypeOrThrow(typeHandle) .Single(handle => module.GetMethodDefNameOrThrow(handle) == methodName); var returnParamHandle = module.GetParametersOfMethodOrThrow(methodHandle).FirstOrDefault(); if (returnParamHandle.IsNil) { Assert.False(expected); } else { var attributes = module .GetCustomAttributesOrThrow(returnParamHandle) .Where(handle => module.GetTargetAttributeSignatureIndex(handle, description) != -1); if (expected) { Assert.Equal(1, attributes.Count()); } else { Assert.Empty(attributes); } } }