コード例 #1
0
        private static bool IsDerivedFromIdentityTypes(AttributeData attribute, PXContext pxContext)
        {
            var attributeInformation = new AttributeInformation(pxContext);

            return(attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, pxContext.FieldAttributes.PXDBIdentityAttribute) ||
                   attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, pxContext.FieldAttributes.PXDBLongIdentityAttribute));
        }
コード例 #2
0
        /// <summary>
        /// Get DAC properties from the DAC extension and its base DAC.
        /// </summary>
        /// <param name="dacExtension">The DAC extension to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <param name="dacFields">The DAC fields.</param>
        /// <param name="cancellation">(Optional) Cancellation token.</param>
        /// <returns>
        /// The properties from DAC extension and base DAC.
        /// </returns>
        public static OverridableItemsCollection <DacPropertyInfo> GetPropertiesFromDacExtensionAndBaseDac(this ITypeSymbol dacExtension, PXContext pxContext,
                                                                                                           IDictionary <string, DacFieldInfo> dacFields,
                                                                                                           CancellationToken cancellation = default)
        {
            dacExtension.ThrowOnNull(nameof(dacExtension));
            pxContext.ThrowOnNull(nameof(pxContext));

            var attributeInformation = new AttributeInformation(pxContext);

            return(GetPropertiesOrFieldsInfoFromDacExtension <DacPropertyInfo>(dacExtension, pxContext, AddPropertiesFromDac, AddPropertiesFromDacExtension));

            //-----------------------Local function----------------------------------------
            int AddPropertiesFromDac(OverridableItemsCollection <DacPropertyInfo> propertiesCollection, ITypeSymbol dac, int startingOrder)
            {
                var rawDacProperties = dac.GetRawPropertiesFromDacImpl(pxContext, includeFromInheritanceChain: true, cancellation);

                return(propertiesCollection.AddRangeWithDeclarationOrder(rawDacProperties, startingOrder,
                                                                         (dacProperty, order) => DacPropertyInfo.Create(pxContext, dacProperty.Node, dacProperty.Symbol, order, attributeInformation, dacFields)));
            }

            int AddPropertiesFromDacExtension(OverridableItemsCollection <DacPropertyInfo> propertiesCollection, ITypeSymbol dacExt, int startingOrder)
            {
                var rawDacExtensionProperties = GetRawPropertiesFromDacOrDacExtensionImpl(dacExt, pxContext, cancellation);

                return(propertiesCollection.AddRangeWithDeclarationOrder(rawDacExtensionProperties, startingOrder,
                                                                         (dacProperty, order) => DacPropertyInfo.Create(pxContext, dacProperty.Node, dacProperty.Symbol, order, attributeInformation, dacFields)));
            }
        }
コード例 #3
0
ファイル: AttributeInfo.cs プロジェクト: Acumatica/Acuminator
        private static bool IsPXDefaultAttribute(AttributeData attribute, AttributeInformation attributeInformation)
        {
            var pxDefaultAttribute        = attributeInformation.Context.AttributeTypes.PXDefaultAttribute;
            var pxUnboundDefaultAttribute = attributeInformation.Context.AttributeTypes.PXUnboundDefaultAttribute;

            return(attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, pxDefaultAttribute) &&
                   !attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, pxUnboundDefaultAttribute));
        }
コード例 #4
0
        internal static void RegisterAttribute(string name, HtmlTextWriterStyle key, bool encode, bool isUrl)
        {
            string str = name.ToLower(CultureInfo.InvariantCulture);

            attrKeyLookupTable.Add(str, key);
            if (key < attrNameLookupArray.Length)
            {
                attrNameLookupArray[(int)key] = new AttributeInformation(name, encode, isUrl);
            }
        }
コード例 #5
0
        public virtual void AddAttribute(HtmlTextWriterAttribute key, string value, bool fEncode)
        {
            int attributeIndex = (int)key;

            if (attributeIndex >= 0 && attributeIndex < _attrNameLookupArray.Length)
            {
                AttributeInformation info = _attrNameLookupArray [attributeIndex];
                AddAttribute(info.name, value, key, fEncode, info.isUrl);
            }
        }
コード例 #6
0
ファイル: AttributeInfo.cs プロジェクト: Acumatica/Acuminator
        private static bool CheckForAutoNumberAttribute(AttributeData attribute, AttributeInformation attributeInformation)
        {
            var autoNumberAttribute = attributeInformation.Context.AttributeTypes.AutoNumberAttribute.Type;

            if (autoNumberAttribute == null)
            {
                return(false);
            }

            return(attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, autoNumberAttribute));
        }
コード例 #7
0
        public override void Analyze(SymbolAnalysisContext context, PXContext pxContext, DacSemanticModel dacOrDacExt)
        {
            context.CancellationToken.ThrowIfCancellationRequested();
            var autoNumberProperties = dacOrDacExt.DeclaredDacProperties.Where(property => property.IsAutoNumbering);
            AttributeInformation attributeInformation = new AttributeInformation(pxContext);

            foreach (DacPropertyInfo dacProperty in autoNumberProperties)
            {
                CheckDacProperty(context, attributeInformation, dacProperty);
            }
        }
コード例 #8
0
        private void CheckDacProperty(SymbolAnalysisContext context, AttributeInformation attributeInformation, DacPropertyInfo dacProperty)
        {
            if (dacProperty.PropertyType.SpecialType != SpecialType.System_String)
            {
                ReportDacPropertyTypeIsNotString(context, attributeInformation.Context, dacProperty);
                return;
            }

            context.CancellationToken.ThrowIfCancellationRequested();
            CheckIfStringLengthIsSufficientForAutoNumbering(context, attributeInformation, dacProperty);
        }
コード例 #9
0
ファイル: NXObject.cs プロジェクト: suifengsigan/TEST_1
 public AttributeInformation[] GetAttributeInfo()
 {
     NXOpen.NXObject.AttributeInformation[] userAttributes = this.NXOpenDisplayableObject.GetUserAttributes();
     AttributeInformation[] informationArray2 = new AttributeInformation[userAttributes.Length];
     for (int i = 0; i < informationArray2.Length; i++)
     {
         informationArray2[i].Title = userAttributes[i].Title;
         informationArray2[i].Type  = (AttributeType)userAttributes[i].Type;
     }
     return(informationArray2);
 }
コード例 #10
0
        private static void RegisterAttribute(string name, HtmlTextWriterAttribute key, bool encode, bool isUrl)
        {
            string nameLCase = name;            //.ToLower ();

            _attrKeyLookupTable.Add(nameLCase, key);

            if ((int)key < _attrNameLookupArray.Length)
            {
                _attrNameLookupArray [(int)key] = new AttributeInformation(name, encode, isUrl);
            }
        }
コード例 #11
0
ファイル: NXObject.cs プロジェクト: suifengsigan/TEST_1
        public AttributeInformation[] GetAttributeInfo()
        {
            NXOpen.NXObject.AttributeInformation[] userAttributes = this.NXOpenDisplayableObject.GetUserAttributes();
            AttributeInformation[] informationArray2 = new AttributeInformation[userAttributes.Length];
            for (int i = 0; i < informationArray2.Length; i++)
            {
                informationArray2[i].Title = userAttributes[i].Title;
                switch (userAttributes[i].Type)
                {
                case NXOpen.NXObject.AttributeType.Any:
                {
                    informationArray2[i].Type = AttributeType.Any;
                    break;
                }

                case NXOpen.NXObject.AttributeType.Integer:
                {
                    informationArray2[i].Type = AttributeType.Integer;
                    break;
                }

                case NXOpen.NXObject.AttributeType.Null:
                {
                    informationArray2[i].Type = AttributeType.Null;
                    break;
                }

                case NXOpen.NXObject.AttributeType.Real:
                {
                    informationArray2[i].Type = AttributeType.Real;
                    break;
                }

                case NXOpen.NXObject.AttributeType.Reference:
                {
                    informationArray2[i].Type = AttributeType.Reference;
                    break;
                }

                case NXOpen.NXObject.AttributeType.Time:
                {
                    informationArray2[i].Type = AttributeType.Time;
                    break;
                }

                default:
                {
                    informationArray2[i].Type = AttributeType.String;
                    break;
                }
                }
            }
            return(informationArray2);
        }
コード例 #12
0
        public static AttributeInfo Create(AttributeData attribute, AttributeInformation attributeInformation, int declarationOrder)
        {
            attribute.ThrowOnNull(nameof(attribute));
            attributeInformation.ThrowOnNull(nameof(attributeInformation));

            BoundType boundType                 = attributeInformation.GetBoundAttributeType(attribute);
            bool      isPXDefaultAttribute      = IsPXDefaultAttribute(attribute, attributeInformation);
            bool      isIdentityAttribute       = IsDerivedFromIdentityTypes(attribute, attributeInformation);
            bool      isAttributeWithPrimaryKey = attribute.NamedArguments.Any(arg => arg.Key.Contains(DelegateNames.IsKey) &&
                                                                               arg.Value.Value is bool isKeyValue && isKeyValue == true);

            return(new AttributeInfo(attribute, boundType, declarationOrder, isAttributeWithPrimaryKey, isIdentityAttribute, isPXDefaultAttribute));
        }
コード例 #13
0
        private static Task AnalyzePropertyAsync(SymbolAnalysisContext symbolContext, PXContext pxContext)
        {
            if (!(symbolContext.Symbol is INamedTypeSymbol dacExt) || !dacExt.IsDacExtension())
            {
                return(Task.FromResult(false));
            }

            AttributeInformation attributeInformation = new AttributeInformation(pxContext);

            Task[] allTasks = dacExt.GetMembers()
                              .OfType <IPropertySymbol>()
                              .Select(property => CheckDacPropertyAsync(property, symbolContext, pxContext, attributeInformation))
                              .ToArray();

            return(Task.WhenAll(allTasks));
        }
コード例 #14
0
        /// <summary>
        /// Gets the DAC property symbols and syntax nodes from DAC and, if <paramref name="includeFromInheritanceChain"/> is <c>true</c>, its base DACs.
        /// </summary>
        /// <param name="dac">The DAC to act on.</param>
        /// <param name="pxContext">Context.</param>
        /// <param name="dacFields">The DAC fields.</param>
        /// <param name="includeFromInheritanceChain">(Optional) True to include, false to exclude the properties from the inheritance chain.</param>
        /// <param name="cancellation">(Optional) Cancellation token.</param>
        /// <returns>
        /// The DAC property symbols with nodes from DAC.
        /// </returns>
        public static OverridableItemsCollection <DacPropertyInfo> GetDacPropertiesFromDac(this ITypeSymbol dac, PXContext pxContext,
                                                                                           IDictionary <string, DacFieldInfo> dacFields,
                                                                                           bool includeFromInheritanceChain = true,
                                                                                           CancellationToken cancellation   = default)
        {
            pxContext.ThrowOnNull(nameof(pxContext));
            dacFields.ThrowOnNull(nameof(dacFields));

            if (!dac.IsDAC(pxContext))
            {
                return(new OverridableItemsCollection <DacPropertyInfo>());
            }

            int estimatedCapacity    = dac.GetTypeMembers().Length;
            var propertiesByName     = new OverridableItemsCollection <DacPropertyInfo>(estimatedCapacity);
            var dacProperties        = GetRawPropertiesFromDacImpl(dac, pxContext, includeFromInheritanceChain, cancellation);
            var attributeInformation = new AttributeInformation(pxContext);

            propertiesByName.AddRangeWithDeclarationOrder(dacProperties, startingOrder: 0,
                                                          (rawData, order) => DacPropertyInfo.Create(pxContext, rawData.Node, rawData.Symbol, order, attributeInformation, dacFields));
            return(propertiesByName);
        }
コード例 #15
0
        private static async Task AnalyzeAttributesWithinBoundFieldAsync(IPropertySymbol property, ImmutableArray <AttributeData> attributes,
                                                                         PXContext pxContext,
                                                                         SymbolAnalysisContext symbolContext,
                                                                         AttributeInformation attributeInformation)
        {
            if (property.ContainingType.IsDAC())             // BQLTable class bound field
            {
                return;
            }

            foreach (var attribute in attributes)
            {
                if (attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, pxContext.AttributeTypes.PXDefaultAttribute))
                {
                    foreach (KeyValuePair <string, TypedConstant> argument in attribute.NamedArguments)
                    {
                        if (isAttributeContainsPersistingCheckNothing(argument))
                        {
                            return;
                        }
                    }

                    Location attributeLocation = await GetAttributeLocationAsync(attribute, symbolContext.CancellationToken);

                    if (attributeLocation != null)
                    {
                        var diagnosticProperties = new Dictionary <string, string>
                        {
                            { DiagnosticProperty.IsBoundField, true.ToString() }
                        }.ToImmutableDictionary();

                        symbolContext.ReportDiagnostic(
                            Diagnostic.Create(
                                Descriptors.PX1030_DefaultAttibuteToExisitingRecords, attributeLocation, diagnosticProperties));
                    }
                }
            }
        }
コード例 #16
0
        private static async Task CheckDacPropertyAsync(IPropertySymbol property, SymbolAnalysisContext symbolContext, PXContext pxContext,
                                                        AttributeInformation attributeInformation)
        {
            ImmutableArray <AttributeData> attributes = property.GetAttributes();

            if (attributes.Length == 0)
            {
                return;
            }

            symbolContext.CancellationToken.ThrowIfCancellationRequested();

            bool isBoundField = attributeInformation.ContainsBoundAttributes(attributes);

            if (isBoundField)
            {
                await AnalyzeAttributesWithinBoundFieldAsync(property, attributes, pxContext, symbolContext, attributeInformation).ConfigureAwait(false);
            }
            else if (!isBoundField)
            {
                await AnalyzeAttributesWithinUnBoundFieldAsync(property, attributes, pxContext, symbolContext, attributeInformation).ConfigureAwait(false);
            }
        }
コード例 #17
0
ファイル: WpfXmlWriter.cs プロジェクト: wilversings/atdl4net
        public void WriteAttribute(WpfXmlWriterAttribute attribute, string value)
        {
            AttributeInformation attributeInfo = _attributeInformation[(int)attribute];

            _writer.WriteAttributeString(attributeInfo.Name, value);
        }
コード例 #18
0
ファイル: NonLogger.cs プロジェクト: dbartels13/Common
 public void AttributeExit(AttributeInformation info)
 {
 }
コード例 #19
0
        private static void BuildAttributeBeliefs(BeliefSet res)
        {
            var suspects = new List <string>
            {
                "Miss Scarlet", "Professor Plum", "Mrs. Peacock", "Mr. Green", "Mrs. White"
            };

            var adjectives1 = new List <string>
            {
                "tall"
            };

            var adjectives2 = new List <string>
            {
                "evil", "bemustached"
            };

            foreach (var suspect in suspects)
            {
                foreach (var adjective in adjectives1)
                {
                    var info = new AttributeInformation()
                    {
                        Subject   = suspect,
                        Adjective = adjective,
                        IsTrue    = true
                    };
                    res.AddSubjectAttribute(info);
                }
                foreach (var adjective in adjectives2)
                {
                    var info = new AttributeInformation()
                    {
                        Subject   = suspect,
                        Adjective = adjective,
                        IsTrue    = false
                    };
                    res.AddSubjectAttribute(info);
                }
            }

            foreach (var adjective in adjectives2)
            {
                var info = new AttributeInformation()
                {
                    Subject   = "Colonel Mustard",
                    Adjective = adjective,
                    IsTrue    = true
                };
                res.AddSubjectAttribute(info);
            }
            foreach (var adjective in adjectives1)
            {
                var info = new AttributeInformation()
                {
                    Subject   = "Colonel Mustard",
                    Adjective = adjective,
                    IsTrue    = false
                };
                res.AddSubjectAttribute(info);
            }
        }
コード例 #20
0
ファイル: BeliefSet.cs プロジェクト: YehudaShapira/Questor
 internal void AddSubjectAttribute(AttributeInformation info)
 {
     attributes.Add(info);
 }
コード例 #21
0
        private void CheckIfStringLengthIsSufficientForAutoNumbering(SymbolAnalysisContext context, AttributeInformation attributeInformation,
                                                                     DacPropertyInfo dacProperty)
        {
            var dbBoundStringAttribute = attributeInformation.Context.FieldAttributes.PXDBStringAttribute;
            var unboundStringAttribute = attributeInformation.Context.FieldAttributes.PXStringAttribute;
            var stringAttributes       = dacProperty.Attributes
                                         .Where(a => IsStringAttribute(a, attributeInformation, dbBoundStringAttribute, unboundStringAttribute))
                                         .ToList();

            if (stringAttributes.Count != 1)
            {
                return;
            }

            AttributeInfo stringAttribute  = stringAttributes[0];
            int?          stringLength     = GetStringLengthFromStringAttribute(stringAttribute);
            int           minAllowedLength = attributeInformation.Context.AttributeTypes.AutoNumberAttribute.MinAutoNumberLength;

            if (stringLength.HasValue && stringLength < minAllowedLength)
            {
                var attributeLocation = GetLocationToReportInsufficientStringLength(context, stringAttribute, stringLength.Value);
                var diagnostic        = Diagnostic.Create(Descriptors.PX1020_InsufficientStringLengthForDacPropertyWithAutoNumbering, attributeLocation, minAllowedLength);
                context.ReportDiagnosticWithSuppressionCheck(diagnostic, attributeInformation.Context.CodeAnalysisSettings);
            }
        }
コード例 #22
0
ファイル: HtmlTextWriter.cs プロジェクト: HtmlTags/htmltags
        private static void RegisterAttribute(string name, HtmlTextWriterAttribute key, bool encode, bool isUrl)
        {
            string nameLCase = name.ToLower();

            _attrKeyLookupTable.Add(nameLCase, key);

            if ((int)key < _attrNameLookupArray.Length)
            {
                _attrNameLookupArray[(int)key] = new AttributeInformation(name, encode, isUrl);
            }
        }
コード例 #23
0
ファイル: AttributeInfo.cs プロジェクト: Acumatica/Acuminator
 private static bool IsDerivedFromIdentityTypes(AttributeData attribute, AttributeInformation attributeInformation) =>
 attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, attributeInformation.Context.FieldAttributes.PXDBIdentityAttribute) ||
 attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeClass, attributeInformation.Context.FieldAttributes.PXDBLongIdentityAttribute);
コード例 #24
0
 private bool IsStringAttribute(AttributeInfo attribute, AttributeInformation attributeInformation,
                                INamedTypeSymbol dbBoundStringAttribute, INamedTypeSymbol unboundStringAttribute) =>
 attribute.BoundType != BoundType.NotDefined &&
 (attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeType, dbBoundStringAttribute) ||
  attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeType, unboundStringAttribute));
コード例 #25
0
 public virtual void AttributeExit(AttributeInformation info) => DoUpdate(info);
コード例 #26
0
        private async Task <Document> RemoveKeysFromFieldsAsync(Document document,
                                                                CancellationToken cancellationToken,
                                                                Diagnostic diagnostic,
                                                                CodeFixModes mode)
        {
            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var pxContext            = new PXContext(semanticModel.Compilation);
            var attributeInformation = new AttributeInformation(pxContext);

            cancellationToken.ThrowIfCancellationRequested();

            List <Location> attributeLocations = diagnostic.AdditionalLocations.ToList();

            attributeLocations.Add(diagnostic.Location);

            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            List <SyntaxNode> deletedNodes = new List <SyntaxNode>();

            foreach (var attributeLocation in attributeLocations)
            {
                AttributeSyntax attributeNode = root?.FindNode(attributeLocation.SourceSpan) as AttributeSyntax;

                if (attributeNode == null)
                {
                    return(document);
                }

                ITypeSymbol attributeType = semanticModel.GetTypeInfo(attributeNode, cancellationToken).Type;

                if (attributeType == null)
                {
                    return(document);
                }

                bool isIdentityAttribute = attributeInformation.IsAttributeDerivedFromClass(attributeType, pxContext.FieldAttributes.PXDBIdentityAttribute) ||
                                           attributeInformation.IsAttributeDerivedFromClass(attributeType, pxContext.FieldAttributes.PXDBLongIdentityAttribute);


                if ((mode == CodeFixModes.EditIdentityAttribute && isIdentityAttribute) ||
                    (mode == CodeFixModes.EditKeyFieldAttributes && !isIdentityAttribute))
                {
                    IEnumerable <AttributeArgumentSyntax> deletedNode = GetIsKeyEQTrueArguments(attributeNode);

                    deletedNodes.AddRange(deletedNode);
                }

                if (mode == CodeFixModes.RemoveIdentityAttribute && isIdentityAttribute)
                {
                    if ((attributeNode.Parent as AttributeListSyntax).Attributes.Count == 1)
                    {
                        deletedNodes.Add(attributeNode.Parent);
                    }
                    else
                    {
                        deletedNodes.Add(attributeNode);
                    }
                }
            }

            SyntaxNode newRoot;

            if (mode == CodeFixModes.RemoveIdentityAttribute)
            {
                newRoot = root.RemoveNodes(deletedNodes, SyntaxRemoveOptions.KeepExteriorTrivia);
            }
            else
            {
                newRoot = root.RemoveNodes(deletedNodes, SyntaxRemoveOptions.KeepNoTrivia);
            }

            return(document.WithSyntaxRoot(newRoot));
        }
コード例 #27
0
        private static int FindClosestFormat(IntPtr dcHandle, FramebufferFormat format)
        {
            const int WGL_NO_ACCELERATION_ARB = 0x2025;

            int[] formatValue = new int[1];

            if (!GetPixelFormatAttribivARB(dcHandle, 1, 0, 1, new int[1] {
                (int)WGL.ARB.Attribute.WGL_NUMBER_PIXEL_FORMATS_ARB
            }, formatValue))
            {
                throw new PlatformException($"wglGetPixelFormatAttribivARB failed: {Marshal.GetLastWin32Error()}");
            }

            int formatCount = formatValue[0];

            List <int> tempAttributeList = new List <int>();

            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_SUPPORT_OPENGL_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_DRAW_TO_WINDOW_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_PIXEL_TYPE_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_ACCELERATION_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_RED_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_GREEN_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_BLUE_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_ALPHA_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_DEPTH_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_STENCIL_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_ACCUM_RED_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_ACCUM_GREEN_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_ACCUM_BLUE_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_ACCUM_ALPHA_BITS_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_STEREO_ARB);
            tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_DOUBLE_BUFFER_ARB);

            if (Extensions.Contains("WGL_ARB_multisample"))
            {
                tempAttributeList.Add((int)WGL.ARB.Attribute.WGL_SAMPLES_ARB);
            }

            int[] attributes = tempAttributeList.ToArray();

            int[] values = new int[Unsafe.SizeOf <AttributeInformation>() / sizeof(int)];

            int  closestIndex            = int.MaxValue;
            uint leastMissing            = uint.MaxValue;
            uint leastRawColorDifference = uint.MaxValue;
            uint leastExtraDifference    = uint.MaxValue;

            for (int index = 0; index < formatCount; index++)
            {
                if (!GetPixelFormatAttribivARB(dcHandle, index + 1, 0, (uint)attributes.Length, attributes, values))
                {
                    throw new PlatformException($"wglGetPixelFormatAttribivARB failed: {Marshal.GetLastWin32Error()}");
                }

                AttributeInformation information = MemoryMarshal.Cast <int, AttributeInformation>(values)[0];

                if (information.SupportOpenGL != 0 && information.Acceleration != WGL_NO_ACCELERATION_ARB)
                {
                    if (format.Stereo && information.Stereo == 0)
                    {
                        continue;
                    }

                    if (format.Buffers > 1 && information.DoubleBuffer == 0)
                    {
                        continue;
                    }

                    // Based on glfw3 algorithm.
                    information.CompareWithDesiredFormat(format, out uint missing, out uint rawColorDifference, out uint extraDifference);

                    if (missing < leastMissing)
                    {
                        closestIndex = index;
                    }
                    else if (missing == leastMissing)
                    {
                        if ((rawColorDifference < leastRawColorDifference) || ((rawColorDifference == leastRawColorDifference) && (extraDifference < leastExtraDifference)))
                        {
                            closestIndex = index;
                        }
                    }


                    if (closestIndex == index)
                    {
                        leastMissing            = missing;
                        leastRawColorDifference = rawColorDifference;
                        leastExtraDifference    = extraDifference;
                    }
                }
            }

            if (closestIndex == int.MaxValue)
            {
                closestIndex = -1;
            }

            return(closestIndex);
        }
コード例 #28
0
        private List <DacPropertyInfo> GetDacPropertiesWithForeignKeys(PXContext pxContext, INamedTypeSymbol dacTypeSymbol, CancellationToken cancellation)
        {
            var foreignKeyAttributes = GetForeignKeyAttributes(pxContext);

            if (foreignKeyAttributes.Count == 0)
            {
                return(new List <DacPropertyInfo>());
            }

            var dacSemanticModel = DacSemanticModel.InferModel(pxContext, dacTypeSymbol, cancellation);

            if (dacSemanticModel == null || dacSemanticModel.DacType != DacType.Dac)
            {
                return(new List <DacPropertyInfo>());
            }

            var selectorAttribute                     = pxContext.AttributeTypes.PXSelectorAttribute.Type;
            var dimensionSelectorAttribute            = pxContext.AttributeTypes.PXDimensionSelectorAttribute;
            AttributeInformation attributeInformation = new AttributeInformation(pxContext);
            var dacPropertiesWithForeignKeys          =
                from dacProperty in dacSemanticModel.DacProperties
                where !dacProperty.Attributes.IsDefaultOrEmpty &&
                dacProperty.BoundType == BoundType.DbBound &&                                                                                           //only Bound FKs should work correctly
                dacProperty.Attributes.Any(attribute => IsForeignKeyAttribute(attribute))
                orderby dacProperty.DeclarationOrder ascending
                select dacProperty;

            return(dacPropertiesWithForeignKeys.ToList());

            //----------------------------------------Local Function----------------------------------------------------------------
            bool IsForeignKeyAttribute(AttributeInfo attribute)
            {
                const string selectorAttributeProperty = "SelectorAttribute";

                bool isDerivedFromOrAggregateForeignKeyAttribute =
                    foreignKeyAttributes.Exists(
                        foreignKeyAttribute => attributeInformation.IsAttributeDerivedFromClass(attribute.AttributeType, foreignKeyAttribute));

                if (isDerivedFromOrAggregateForeignKeyAttribute)
                {
                    return(true);
                }

                var selectorAttributeMembers = attribute.AttributeType.GetBaseTypesAndThis()
                                               .SelectMany(type => type.GetMembers(selectorAttributeProperty));


                var selectorAttributeCandidateMemberTypes = from type in attribute.AttributeType.GetBaseTypesAndThis()
                                                            .TakeWhile(attrType => attrType != pxContext.AttributeTypes.PXEventSubscriberAttribute)
                                                            from member in type.GetMembers(selectorAttributeProperty)
                                                            select member switch
                {
                    IPropertySymbol property => property.Type,
                    IFieldSymbol field => field.Type,
                    _ => null
                };

                return(selectorAttributeCandidateMemberTypes
                       .Any(memberType => memberType != null &&
                            (attributeInformation.IsAttributeDerivedFromClass(memberType, selectorAttribute) ||
                             attributeInformation.IsAttributeDerivedFromClass(memberType, dimensionSelectorAttribute))));
            }
        }