/// <summary>
            /// Constructs a <see cref="InfoSectionDefinition"/> based on <paramref name="type"/> and <paramref name="attribute"/>
            /// </summary>
            /// <param name="type"></param>
            /// <param name="attribute"></param>
            /// <param name="infoSection"></param>
            /// <returns></returns>
            protected override bool TryConstructInfoSection(Type type, DisplayCurrentInfo attribute, out InfoSectionDefinition infoSection)
            {
                infoSection = new InfoSectionDefinition(
                    new CurrentInfoResolver(type),
                    new CurrentInfoInterpreter(),
                    attribute.SectionIndex,
                    attribute.Header);

                // InfoSectionDefinition for current can always be constructed
                return(true);
            }
Пример #2
0
            /// <summary>
            /// Tries to construct InfoSectionDefinition for <paramref name="type"/> and <paramref name="attribute"/>.
            /// </summary>
            /// <param name="type"></param>
            /// <param name="attribute"></param>
            /// <param name="infoSection"></param>
            /// <returns></returns>
            protected override bool TryConstructInfoSection(Type type, DisplayVoltageInfo attribute, out InfoSectionDefinition infoSection)
            {
                // Try to get terminalB
                if (type.TryGetProperty <ITerminal>(attribute.TerminalB, out var terminalB))
                {
                    // If successful, create a variable for a resolver
                    VoltageInfoResolver resolver = null;

                    // If TerminalA is an empty string
                    if (attribute.TerminalA == string.Empty)
                    {
                        // Create a resolver from ground to terminal B
                        resolver = new VoltageInfoResolver(type, terminalB);
                    }
                    // Otherwise try to get terminalA
                    else if (type.TryGetProperty <ITerminal>(attribute.TerminalA, out var terminalA))
                    {
                        // If successful create a resolver from terminalA to terminalB
                        resolver = new VoltageInfoResolver(type, terminalA, terminalB);
                    }

                    // If resolver was successfully created
                    if (resolver != null)
                    {
                        // Create a new info section definition
                        infoSection = new InfoSectionDefinition(
                            resolver,
                            new VoltageInfoInterpreter(),
                            attribute.SectionIndex,
                            attribute.Header);

                        // And return success
                        return(true);
                    }
                }

                // If the method didn't return by now it means that it failed

                // Log failure when debugging
                LogIncorrectTerminalPropertyNames(type, attribute);

                // Assign null
                infoSection = null;

                // Return failure
                return(false);
            }
Пример #3
0
 /// <summary>
 /// Method called on each type with each T attribute defined for it that should try to construct an InfoSectionDefinition
 /// and return true on success.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="attribute"></param>
 /// <param name="infoSection"></param>
 /// <returns></returns>
 protected abstract bool TryConstructInfoSection(Type type, T attribute, out InfoSectionDefinition infoSection);