小编Dre*_*kes的帖子

C#有时货币格式不起作用

似乎有时货币格式不起作用:

string Amount = "11123.45";
Literal2.Text = string.Format("{0:c}", Amount);
Run Code Online (Sandbox Code Playgroud)

读取11123.45

它应该是:

$ 11,123.45

c# asp.net

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

C#Reflection - 将两个对象合并在一起

我需要更新对象A的属性,如果null为对象B的等效属性,如果它不为null.我想要可以用于各种对象的代码.

我有一个版本工作,直到其中一个对象包含List类型的属性,这是我在下面的代码中有空白的地方.我的主要问题是如何才能最好地实现这部分代码.其次是有更好的方法来做这件事,第三,我知道它永远不会很快,但任何加快它的建议都会受到赞赏.

提前致谢.

public T MergeWith<T, U>(T primarySource, U secondarySource) where U : class, T
    {
        Type primaryType = typeof(T);
        Type secondaryType = typeof(U);
        foreach (PropertyInfo primaryInfo in primaryType.GetProperties())
        {
            if (primaryInfo.CanWrite)
            {
                object currentPrimary = primaryInfo.GetValue(primarySource, null);

                PropertyInfo secondaryInfo = secondaryType.GetProperty(primaryInfo.Name);
                object currentSecondary = secondaryInfo.GetValue(secondarySource, null);

                if (currentPrimary == null && currentSecondary != null)
                {
                    primaryInfo.SetValue(primarySource, currentSecondary, null);
                }
                else if ((currentPrimary != null && currentSecondary != null) && isChildClass(primaryInfo))
                {
                    if (isCollection(currentPrimary))
                    {
                        // here


                    }
                    else
                    { …
Run Code Online (Sandbox Code Playgroud)

c#

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

WPF datatemplate ItemsControl指定初始值和最终值

我一直在WPF中使用ItemsControl来保持安静.我正在使用MVVM来开发我的应用程序.

现在我遇到了一个问题.我有一个要求,根据IList <>中的值的数量,我必须显示之间用逗号分隔的TextBox的数量.我编写了一个ItemsControl,它迭代绑定的IList <>并根据元素的数量显示TextBoxes.

我写过像这样的DataTemplate

<DataTemplate x:Key="ParameterDisplay1">  
    <ItemsControl ItemsSource="{Binding Parameters}">  
        <ItemsControl.ItemsPanel>  
            <ItemsPanelTemplate>  
                <StackPanel Orientation="Horizontal"></StackPanel>  
            </ItemsPanelTemplate>  
        </ItemsControl.ItemsPanel>  
        <ItemsControl.ItemTemplate>  
            <DataTemplate>  
                <StackPanel Orientation="Horizontal" >  
                    <TextBox  Width="40" Height="auto" Margin="2" Text="{Binding ProcessData}"></TextBox>  
                    <TextBlock Text=" , " Width="auto" Height="auto" Margin="2" FontSize="15"></TextBlock>  
                </StackPanel>  
            </DataTemplate>  
        </ItemsControl.ItemTemplate>  
     </ItemsControl>  
</DataTemplate>  
Run Code Online (Sandbox Code Playgroud)

我这样使用它:

<dg:DataGrid x:Name="DataGrid_Standard" toGenerateColumns="False">
    <dg:DataGrid.Columns>  
        <dg:DataGridTemplateColumn Header="Parameters" Width="SizeToCells" IsReadOnly="True"  
            CellTemplateSelector="{StaticResource paramTemplateSelector}">
        </dg:DataGridTemplateColumn> 
    </dg:DataGrid.Columns>  
</dg:DataGrid>  
Run Code Online (Sandbox Code Playgroud)

但问题是,我必须在TextBox之间显示"("在第一个TextBox之后的"(" )和最后一个TextBox之后的",".
我必须显示类似这样的东西::::>**(TextBox,TextBox,TextBox)**

使用代码隐藏实现这一点很容易,但我不想在我的代码隐藏文件中写任何东西,我希望我的View是干净的.我想在XAML文件中编写所有内容关于如何执行此操作的示例说明将非常有用!

.net wpf datatemplate itemscontrol

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

帮助InvalidProgramException(无效的IL代码?)

我在System.Reflection.Emit使用mono 导出的程序集中遇到了一个奇怪的错误.在尝试运行我的程序集时,我得到一个InvalidProgramException:无效的IL代码.

monodis 给我这个CIL结果(这与我用Emit导出的结果一致):

.method public static hidebysig 
       default void f_main (class [Pine.Core]Pine.Core.Function A_0, class [Pine.Core]Pine.Core.ValueList A_1)  cil managed 
{
    // Method begins at RVA 0x2144
    // Code size 26 (0x1a)
    .maxstack 4
    .locals init (
        class [Pine.Core]Pine.Core.Function V_0,
        class [Pine.Core]Pine.Core.IScope   V_1,
        class [Pine.Core]Pine.Core.ValueList    V_2,
        class [Pine.Core]Pine.Core.IScope   V_3)
    IL_0000:  ldarg.0 
    IL_0001:  stloc.0 
    IL_0002:  ldarg.1 
    IL_0003:  stloc.2 
    IL_0004:  ldloc.0 
    IL_0005:  ldftn instance class [Pine.Core]Pine.Core.IScope class [Pine.Core]Pine.Core.Function::get_Scope()
    IL_000b:  stloc.1 
    IL_000c:  ldloc.1 
    IL_000d:  newobj instance void class [Pine.Core]Pine.Core.BlockScope::'.ctor'(class [Pine.Core]Pine.Core.IScope) …
Run Code Online (Sandbox Code Playgroud)

.net mono cil exception reflection.emit

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

Silverlight DataGrid中的列对齐

如何在Silverlight DataGrid中设置单元格内容的对齐方式?

另一个问题上为WPF DataGrids提供的方法在Silverlight中似乎不起作用.

.net silverlight datagrid

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

我可以对 HTML 字符串中存储的信息使用 addClass 吗?

我有一个字符串,例如看起来像这样。

var html = '<div class="templatemo_post_text grid-85">
<div id="wmd-preview"><h2>Skriv något!</h2>
<p>Lorem ipsum</p></div>
<div class="templatemo_post_footer">
<div class="templatemo_post_on">
<span class="orange">Skrivet den</span> 3 Mar 2013</div>
<div class="templatemo_post_comment">
<a href="#">Inlägg nummer </a>
</div></div></div>';
Run Code Online (Sandbox Code Playgroud)

我可以以某种方式使用 .addClass() 将类添加到 id=wmd-preview 中吗?
实际上,我的问题是所有 JavaScript 都修改现有变量。我想做的另一件事是用新标签替换整个标签。

谢谢。

javascript jquery

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

使被覆盖的虚拟函数非虚拟的目的

考虑C++ 11中的以下类:

class Base
{
public:
  virtual void foo() = 0;
}

class Sub1 : public Base
{
public:
  virtual void foo() override {};
}

class Sub2 : public Base
{
public:
  void foo() override {};
}
Run Code Online (Sandbox Code Playgroud)

使被覆盖的函数非虚拟化的后果是什么Sub2

c++ inheritance overriding virtual-functions c++11

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

JavaScript浮点运算中的跨浏览器一致性

我的目标是拥有一个百分度/弧度的翻译工具.

var PI      = 3.1415926535897936;
var PI_100  = 1.5707963267948968; // PI*0.5;
var PI_300  = 4.71238898038469;   // PI*(1.5);
var D_PI    = 6.283185307179587;  // 2*pi

var centTo  = 0.015707963267948967; 
Run Code Online (Sandbox Code Playgroud)

Chrome评估以下表达式,如下所示:

PI*2 == D_PI      >>> true
PI*0.5 = PI_100   >>> true
PI*1.5 = PI_300   >>> true

100*centTo == PI_100  >>> true
300*centTo == PI_300  >>> true
Run Code Online (Sandbox Code Playgroud)

这些表达式总是true在每个浏览器上?

或者我必须在比较时使用epsilon吗?

var epsilon = 0.0000001;
Math.abs(a - b) < epsilon
Run Code Online (Sandbox Code Playgroud)

javascript floating-point

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

Java元数据提取器导致java.lang.NoClassDefFoundError

我正在尝试使用NetBeans 在Java https://github.com/drewnoakes/metadata-extractor中将该库用于图像元数据提取。

我将文件metadata-extractor-2.7.0.jar导入到项目的jar文件夹中,就像自述文件所述,我只是这样做:

File file = fc.getSelectedFile ();
try {
    Metadata metadata = ImageMetadataReader.readMetadata(file);
} catch ( ImageProcessingException ex ) {
    Logger.getLogger ( UserInterface.class.getName() ).log ( Level.SEVERE, null, ex );
} catch ( IOException ex ) {
    Logger.getLogger ( UserInterface.class.getName() ).log ( Level.SEVERE, null, ex );
}
Run Code Online (Sandbox Code Playgroud)

但我总是得到

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/adobe/xmp/XMPException
at com.drew.imaging.jpeg.JpegMetadataReader.<clinit>(Unknown Source)
at com.drew.imaging.ImageMetadataReader.readMetadata(Unknown Source)
at com.drew.imaging.ImageMetadataReader.readMetadata(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

开始使用此库之前,需要在Netbeans中进行配置吗?

java metadata extractor metadata-extractor

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

使用 MSBuild.exe 时等效于 dotnet build --version-suffix

使用dotnet build.NET SDK 中的工具,您可以通过--version-suffix,例如制作带有后缀的预发布包rc1,等等。

我必须MSBuild.exe直接使用才能解决定位错误,net35并想知道等效的命令行参数是什么。

.net msbuild dotnet-sdk

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