我在下面的方法中写了以下要求 -
如果传递的attributeName中没有值,则应返回 -
3.1.对于int -1 3.2.对于Datetime DateTime.MinValue 3.3.对于String,null 3.4.对于bool,null
情况3.4下面的方法失败.
public T AttributeValue<T>(XmlNode node, string attributeName)
{
var value = new object();
if (node.Attributes[attributeName] != null && !string.IsNullOrEmpty(node.Attributes[attributeName].Value))
{
value = node.Attributes[attributeName].Value;
}
else
{
if (typeof(T) == typeof(int))
value = -1;
else if (typeof(T) == typeof(DateTime))
value = DateTime.MinValue;
else if (typeof(T) == typeof(string))
value = null;
else if (typeof(T) == typeof(bool))
value = null;
}
return (T)Convert.ChangeType(value, typeof(T));
}
Run Code Online (Sandbox Code Playgroud)
当改变这个
public System.Nullable<T> AttributeValue<T>(XmlNode node, string …
Run Code Online (Sandbox Code Playgroud) 我设法重现了测试项目中的一个错误,其结构与我的生产代码类似.它由三个简单的项目组成:
通用(类库):
namespace Common
{
public enum PrimaryColor
{
Red,
Green,
Blue
};
}
Run Code Online (Sandbox Code Playgroud)
库(WCF服务库),它引用了Common:
using Common;
namespace Library
{
[ServiceContract]
public interface ILibrary
{
[OperationContract]
PrimaryColor GetColor();
}
public class Library : ILibrary
{
public PrimaryColor GetColor()
{
return PrimaryColor.Red;
}
}
}
Run Code Online (Sandbox Code Playgroud)
ClientApp(控制台应用程序),其中包含对Common的引用,以及对Library的服务引用,称为"LibraryServiceReference":
using Common;
using ClientApp.LibraryServiceReference;
namespace ClientApp
{
class Program
{
static void Main(string[] args)
{
LibraryClient client = new LibraryClient("WSHttpBinding_ILibrary");
PrimaryColor color = client.GetColor();
}
}
}
Run Code Online (Sandbox Code Playgroud)
ClientApp和Library中的app.config文件是自动生成的,我没有修改它们,我没有更改ClientApp中LibraryServiceReference的默认配置.
编译此解决方案时,我在ClientApp项目中收到以下错误:
错误1
'PrimaryColor' is an ambiguous reference …
Run Code Online (Sandbox Code Playgroud) 我需要通过NLog将日志条目的源代码行号.
请让我知道其他方法.
<<Log entry>> Line 23
<<Log entry>> Line 391
Run Code Online (Sandbox Code Playgroud)
PS-23,391是源代码行号.谢谢
我想将kendo multiselect限制为2项选择.我看到maxSelectedItems选项可以帮助我,但不知道在下面的标签中添加它的位置.任何帮助,将不胜感激.
<select class="k-widget multiselect" data-role="multiselect" id="CompSelect"
data-placeholder=""
data-value-primitive="true"
data-text-field="CompNameId"
data-value-field="CompId"
data-bind="value: SelectedComps,
source: CompaniesList,
events: {
change: onChange,
}">
</select>
Run Code Online (Sandbox Code Playgroud)