我想了解我在UWP应用程序上工作时遇到的这个问题。我能够解决这个问题,但我仍然不清楚其背后的解释/推理。UWP应用程序的调试和发布模式
我在我的代码库中使用XAMLBehaviours SDK中的“EventTriggerBehavior”。这个事件是为了检查GridView的“ClickedItem”。
Microsoft.Xaml.Interactivity的IAction.Execute方法获取ClickedItem事件作为参数。
函数定义为对象IAction.Execute(对象发件人,对象参数)
当我运行在调试模式下的应用程序,这是工作的罚款和参数是越来越分配正确的值。但是当我对Release进行配置时,我意识到我的Behaviors SDK工作不正常。
这是上面的代码片段:
object IAction.Execute(object sender, object parameter)
{
object propertyValue = parameter;
foreach (var propertyPathPart in propertyPathParts)
{
var propInfo = propertyValue.GetType().GetTypeInfo().GetDeclaredProperty(propertyPathPart);
if (propInfo != null)
propertyValue = propInfo.GetValue(propertyValue);
}
}
在进一步的调查,我意识到的PropertyValue没有得到正确的值初始化。因此,为了解决这个问题,我对参数进行了类型转换。
object propertyValue = parameter as ItemClickEventArgs;
现在一切都开始在发布模式下正常工作,包括启用代码优化时。
我将分类到该System.reflection在释放模式下工作正常,当编译.NET本地工具链已启用。当我进行隐式投射时,它不再是一个问题。
根据此视频https://channel9.msdn.com/Shows/Going+Deep/Inside-NET-Native,反射仍然有效,但我不得不投入Behaviors SDK。我想知道更详细的信息并正确理解。