小编use*_*807的帖子

获取当前方法名称

我想要调用当前Handler的名称.

MethodInfo.GetCurrentMethod().Name或者MethodBase.GetCurrentMethod().Name在调试模式下正常工作.

但是一旦我混淆了(使用confuserEx)我的项目,2个函数就会返回"System.Reflection.MethodBase ()".

我注意到我可以使用以下行获取我的函数名称: ((RoutedEventHandler)this.MyMethodName).GetMethodInfo().Name

它返回"MyMethodName"哪个是预期结果.

但它根本不是通用的.当我不知道当前方法的名称时,我想要一段代码.

c# methods

11
推荐指数
1
解决办法
1万
查看次数

使用PowerShell获取当前git分支的名称

我希望能够从PowerShell脚本执行git命令,该脚本与我的git repo不在同一个文件夹中.

首先,我想检查当前的分支,如果它不是主要的,请尝试检查主机和拉主机.

到目前为止我做了什么:

function Get-ScriptDirectory {
    Split-Path $script:MyInvocation.MyCommand.Path
}

$currentPath = Get-ScriptDirectory
[string]$Path_GIT = "C:\Program Files\Git\git-cmd.exe"
$gitRepo = $currentPath + "\..\"
$nameCurrentBranch = & $Path_GIT git -C "$gitRepo" rev-parse --abbrev-ref HEAD
Run Code Online (Sandbox Code Playgroud)

这里的文档和这个问题的答案.

$gitRepo 包含包含git repo的文件夹的路径.

我收到错误:

git-cmd.exe : fatal: Cannot change to 'C:\Users\MyName\Documents\Projects\MyProject\
Batchs\.." rev-parse --abbrev-ref HEAD': Invalid argument
At C:\Users\MyName\Documents\Projects\MyProject\Batchs\Publish.ps1:64 char:22
+ ... entBranch = & $Path_GIT git -C "$gitRepo" rev-parse --abbrev-ref HEAD ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (fatal: Cannot c...nvalid argument:String) …

git powershell github

8
推荐指数
2
解决办法
3936
查看次数

旋转滑块WPF

我想在WPF中旋转4个滑块来创建自定义控件.

这是我的代码:

<Grid Margin="20">
   <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="*"/>
   </Grid.RowDefinitions>
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="*"/>
   </Grid.ColumnDefinitions>
   <Slider Name="Slider_Top_Left" Minimum="0" Maximum="100" Value="75"     RenderTransformOrigin="0,0">
      <Slider.LayoutTransform>
         <RotateTransform CenterX="0" CenterY="0" Angle="-135"/>
      </Slider.LayoutTransform>
   </Slider>
   <Slider Name="Slider_Top_Right" Grid.Column="1" Minimum="0" Maximum="100" Value="75">
      <Slider.LayoutTransform>
         <RotateTransform CenterX="0" CenterY="0" Angle="-45"/>
      </Slider.LayoutTransform>
   </Slider>
   <Slider Name="Slider_Bottom_Right" Grid.Column="1" Grid.Row="1" Minimum="0" Maximum="100" Value="75">
      <Slider.LayoutTransform>
         <RotateTransform CenterX="0" CenterY="0" Angle="45"/>
      </Slider.LayoutTransform>
   </Slider>
   <Slider Name="Slider_Bottom_Left" Grid.Column="0" Grid.Row="1" Minimum="0" Maximum="100" Value="75">
      <Slider.LayoutTransform>
         <RotateTransform CenterX="-10" CenterY="-10" Angle="135"/>
      </Slider.LayoutTransform>
   </Slider>
</Grid>
Run Code Online (Sandbox Code Playgroud)

结果 : 结果

我想要的是 :通缉

我试过没有网格定义,有不同的中心(它没有改变任何东西).

我已经按照在线帮助进行布局转换,但我无法使其正常工作.

谢谢您的帮助.

c# wpf xaml slider

5
推荐指数
1
解决办法
1373
查看次数

进度栏栏样式右半径

我正在尝试为带有圆角的进度栏创建一个模板,但是在实现进度栏的右侧时遇到问题。

这是我的模板:

<ProgressBar Name="blabla" Value="80" Maximum="100" Margin="95,282,113,0">
    <ProgressBar.Style>
        <Style TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Grid Height="10" MinWidth="50" Background="{TemplateBinding Background}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Determinate" />
                                    <VisualState x:Name="Indeterminate">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Duration="00:00:00"
                                                                           Storyboard.TargetName="PART_Indicator"
                                                                           Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <SolidColorBrush>Transparent</SolidColorBrush>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>

                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="PART_Track" CornerRadius="4" BorderThickness="1"
                                    BorderBrush="{DynamicResource CouleurForegroundProgressBar}">
                            </Border>

                            <Border CornerRadius="4,0,0,4" BorderThickness="1" x:Name="PART_Indicator"
                                    HorizontalAlignment="Left" Background="{DynamicResource CouleurForegroundProgressBar}"
                                    BorderBrush="{DynamicResource CouleurForegroundProgressBar}"
                                    Margin="0,0,0,0">                               
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Foreground" Value="{DynamicResource CouleurForegroundProgressBar}" />
        </Style>
    </ProgressBar.Style>
</ProgressBar> …
Run Code Online (Sandbox Code Playgroud)

wpf xaml templates progress-bar

3
推荐指数
1
解决办法
3543
查看次数

获取datagrid的scrollviewer

我正在尝试使datagrid的scrollviewer能够设置偏移量(该偏移量已存储在前面)。

我使用这个功能:

public static T GetVisualChild<T>(DependencyObject parent) where T : Visual       
{     
    T child = default(T);

    int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
    for (int i = 0; i < numVisuals; i++)
    {
        Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
        child = v as T;
        if (child == null)
        {
            child = GetVisualChild<T>(v);
        }
        if (child != null)
        {
            break;
        }
    }
    return child;
}
Run Code Online (Sandbox Code Playgroud)

我这样称呼它:

this.dataGrid.ItemsSource = _myData;
ScrollViewer sc = ressource_design.GetVisualChild<ScrollViewer>(this.dataGrid);
if (sc != null) sc.ScrollToVerticalOffset(stateDatagrid.ScrollbarOffset);
Run Code Online (Sandbox Code Playgroud)

它在许多情况下都有效,但是在某些情况下,该函数返回null,而我无法获取scrollviewer。

只需在设置ItemsSource(项目的ObservableCollection)之后进行此调用,即可在90%的情况下正常运行。该数据网格尚未呈现。

我也尝试过使用该功能:

public static ScrollViewer GetScrollViewerFromDataGrid(DataGrid …
Run Code Online (Sandbox Code Playgroud)

c# wpf datagrid

3
推荐指数
1
解决办法
1909
查看次数

创建 mdb 文件以在 Unity 中调试托管 DLL

我正在尝试在 Unity 中调试我的托管 DLL。它曾经在 Unity 2018.x 上运行良好

现在我有 Unity 2019.3 并且我无法再调试(我的 DLL 工作正常,我只是无法调试它们)。

我的 DLL 及其 pdb 文件位于 Assets 文件夹中。这曾经足以调试它们。

阅读此文档:https : //docs.unity3d.com/Manual/UsingDLL.html,我正在尝试创建 mdb 文件。

第一个问题,文档说我必须将 .pdb 文件作为参数传递,而谷歌上的大多数链接都说要传递 .dll

此链接还指出我应该更改 .bat 文件的工作目录才能使用 pdb2mdb.exe:https ://answers.unity.com/questions/294195/pdb2mdb-usage-error-from-command-line .html

这是我的代码:

set PathToLib="Libraries\"
if exist Libraries\LibBDD.dll  (
    echo Before switching directory for my lib %CD%
    cd %PathToLib% 
    echo new directory %CD%
    @pause
    "C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0\pdb2mdb.exe" LibBDD.dll

    @pause
    cd ..\..\..\..\..\
    echo LibBDD done, new directory %CD%
    )
Run Code Online (Sandbox Code Playgroud)

首先,我不确定我的 CD 命令是否有效,因为路径保持不变。但我没有任何例外。

有了这个代码,我得到:

致命错误:Microsoft.Cci.Pdb.PdbDebugException:未知的自定义元数据项种类:6 à Microsoft.Cci.Pdb.PdbFunction.ReadCustomMetadata(BitAccess …

scripting batch-file unity-game-engine visual-studio

3
推荐指数
1
解决办法
1590
查看次数

覆盖Dictionary <Datetime,int>的ContainsKey

我有这样的Dictionary<DateTime, int>定义:

public Dictionary<DateTime, int> Days;
Run Code Online (Sandbox Code Playgroud)

每个DateTime都与一个int.我想要一个函数来指示DateTime我的词典中是否已存在同一天:

public int GetIntFromDate(DateTime date)
{
    int i = -1;
    if (Days.ContainsKey(date))
    {
        i= CorrespondanceJoursMatchs[date];
    }

    return i;
}
Run Code Online (Sandbox Code Playgroud)

这是完美的,但如果已经有一个同一天+月+年(不看小时/分钟/秒),我想要ContainsKey返回.trueDateTime

事实上,我的字典不应该允许2个DateTime索引具有相同的日/月/年.

一个解决方案是创建一个类只有一个DateTime属性,并覆盖GetHashCodeEquals,但也许有更好的解决办法?

c# containskey

2
推荐指数
1
解决办法
1482
查看次数

在C#中导入C++ DLL,函数参数

我正在尝试在C#中导入我的C++ Dll.它似乎适用于没有参数的函数,但我的函数有一些问题.

我的C++功能:

__declspec(dllexport) bool SetValue(const std::string& strV, bool bUpload)
{ 
    return ::MyClass::SetValue(strV.c_str(), bUpload);              
}
Run Code Online (Sandbox Code Playgroud)

它包含在"extern"C"{"中

该函数调用另一个函数:

bool SetValue(const char* szValue, bool bUpload)
{
}
Run Code Online (Sandbox Code Playgroud)

我的C#功能:

[DllImport("MyDll.dll", EntryPoint = "SetValue", CharSet = CharSet.Auto, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern void SetValue([MarshalAs(UnmanagedType.LPStr)]string strVal, bool bUpload);
Run Code Online (Sandbox Code Playgroud)

当我使用调试模式并输入SetValue(const char*sZvalue,bool bUpload)函数时,sZvalue为"0x4552494F",但是当我尝试扩展Visual Studio的视图以查看其值为"undefined value"的值时.

也许有人知道我的代码有什么问题?

谢谢 !

c# c++ string pinvoke

2
推荐指数
1
解决办法
1782
查看次数