Disabling OBSOLETE error in C#

前端 未结 3 619
半阙折子戏
半阙折子戏 2020-12-03 21:22

I am using the Microsoft TFS API and one of the properties on one of the interfaces has been marked as Obsolete and it instructs me to use a different property. Unfortunate

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 21:49

    Following works for me:

    #pragma warning disable 612,618
                request.CommandLineArguments = arguments;
    #pragma warning restore 612,618
    

    notice no leading 0 in the numbers

    EDIT: Okay, your assembly has the "true" argument in the ObsoleteAttribute constructor. This means you can't use the property and not get an error.

    If you can't re-write your code to avoid using this property, you'll have to invoke the property setter via reflection, for example:

    request.GetType().GetProperty("Number").SetValue(request, arguments, null);
    

    and getting is similar:

    (string)request.GetType().GetProperty("CommandLineArguments").GetValue(request, null);

提交回复
热议问题