ChocoPM.Commands.DataContextCommandAdapter.GetInputBindingsCollectionOwner C# (CSharp) Method

GetInputBindingsCollectionOwner() private static method

private static GetInputBindingsCollectionOwner ( IProvideValueTarget targetService ) : object
targetService IProvideValueTarget
return object
        private static object GetInputBindingsCollectionOwner(IProvideValueTarget targetService)
        {
            var xamlContextField = targetService.GetType().GetField("_xamlContext", BindingFlags.Instance | BindingFlags.NonPublic);
            if (xamlContextField == null)
            {
                return null;
            }

            var xamlContext = xamlContextField.GetValue(targetService);
            var grandParentInstanceProperty = xamlContext.GetType().GetProperty("GrandParentInstance");
            if (grandParentInstanceProperty == null)
            {
                return null;
            }

            var inputBindingsCollection = grandParentInstanceProperty.GetGetMethod().Invoke(xamlContext, null);
            var ownerField = inputBindingsCollection.GetType().GetField("_owner", BindingFlags.Instance | BindingFlags.NonPublic);
            if (ownerField == null)
            {
                return null;
            }

            var owner = ownerField.GetValue(inputBindingsCollection);
            return owner;
        }