Introduce static Property

romanm's Avatar

romanm

30 Jan, 2018 09:43 PM

Hi,
I would like to introduce static property to existing class and wrote this code
public interface ITestsRowCountDictionary
    {
    }

    [Serializable]
    [IntroduceInterface(typeof(ITestsRowCountDictionary), OverrideAction = InterfaceOverrideAction.Ignore)]
    [MulticastAttributeUsage(MulticastTargets.Class, Inheritance = MulticastInheritance.Multicast)]
    public sealed class TestsRowCountDictionaryAttribute : InstanceLevelAspect, ITestsRowCountDictionary
    {
        private static Dictionary<string, Dictionary<string, int>> _testsDictionary;

        [IntroduceMember(Visibility = Visibility.Public, IsVirtual = false)]
        public static Dictionary<string, Dictionary<string, int>> TestsRowCountDictionary
        {
            get { return _testsDictionary; }
        }

        public override void RuntimeInitializeInstance()
        {
            base.RuntimeInitializeInstance();
            if (_testsDictionary == null)
            {
                _testsDictionary = new Dictionary<string, Dictionary<string, int>>();
            }
        }
    }

The property is generated but it is not static. Is there another way to accomplish this?

Thank you,
Roman

  1. Support Staff 1 Posted by PostSharp Techn... on 31 Jan, 2018 04:41 PM

    PostSharp Technologies's Avatar

    Hello Roman,

    this looks like a bug in PostSharp. Thank you for reporting it.

    We're closing the ticket for now as the bug has been internally filed as issue #15843. We will contact you as soon as the bug fix has been released.

    For more details on our support policies and prioritization of bug fixes, please visit https://www.postsharp.net/support/policies.

    Best regards,
    -tony

  2. PostSharp Technologies closed this discussion on 31 Jan, 2018 04:41 PM.

  3. romanm re-opened this discussion on 31 Jan, 2018 04:56 PM

  4. 2 Posted by romanm on 31 Jan, 2018 04:56 PM

    romanm's Avatar

    Hi Tony,

    I forgot to mention that my goal was also to introduce static method. It did not work out. Could you confirm that is also a bug?
    If it is working in 5.037 could you please give snippet of code how to introduce static method?

    Thank you very much,
    Roman

    Roman Muntyanu, Software Developer
    ABELSoft Inc.
    Clinical & Practice Management Software & Services
    “Dedicated to Customer Happiness”
    T. 800-267-ABEL(2235) Ext. 322
    F. 866-337-5558
    [email blocked] or
    [email blocked]
    www.abelsoft.com

  5. Support Staff 3 Posted by PostSharp Techn... on 01 Feb, 2018 11:42 AM

    PostSharp Technologies's Avatar

    Hello,

    I apologize for a misunderstanding within our team. Introduction of static members is not supported by Aspect Framework as there are not many use cases in which it can be useful. You would be able to consume such declarations only from different assemblies and not from the assembly that declares the target type as C# compiler does not see such declaration. Using a static method for introduced method/property is by design and may improve performance, but always results in instance member being introduced.

    Can you describe your use case in more detail? There are usually better approaches to using Aspect Framework to solve problems that may seem to require static member introduction.

    Thanks a lot!

    Best regards,
    Daniel

  6. Support Staff 4 Posted by PostSharp Techn... on 07 Feb, 2018 02:40 PM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as there have not been any further updates. Please feel free to reopen the discussion if you need more help.

    Thanks,
    PostSharp Team

  7. PostSharp Technologies closed this discussion on 07 Feb, 2018 02:40 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac