我试图说服一位同事,一个函数应该将接口作为参数,而不是对象本身.我认为小对象可以很好地传递,但对于大对象,我会给它们一个接口,只是通过i/f,而不是整个事情.
请注意,只会出现其中一个大类 - i/f永远不会用于其他对象.这仅仅是为了隐藏对象的实现.
你是否同意将大型课程分成界面是一种好习惯?
这样做有什么不利之处吗?
例:
public interface class IVeryLargeClass
{
void DoSomething();
...
};
public ref class VeryLargeClass : public IVeryLargeClass
{
public:
virtual void DoSomething() { ... }
...
};
public ref class AnotherClass
{
public:
AnotherClass(VeryLargeClass^ vlc) { vlc->DoSomething(); }
// OR
AnotherClass(IVeryLargeClass^ vlc) { vlc->DoSomething(); }
};
Run Code Online (Sandbox Code Playgroud) language-agnostic oop parameters information-hiding interface
假设我们有这个课程:
public class Moo
{
string _value;
public Moo(string value)
{
this._value = value;
}
public static implicit operator string(Moo x)
{
return x._value;
}
public static implicit operator Moo(string x)
{
return new Moo(x);
}
public override bool Equals(object obj)
{
if (obj is string)
return this._value == obj.ToString();
else if (obj is Moo)
return this._value == ((Moo)obj)._value;
return base.Equals(obj);
}
public override int GetHashCode()
{
return _value.GetHashCode();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我将这种类型的对象添加到Hashtable,那么我可以使用相同的字符串找到该对象.
但是如果Hashtable包含字符串而不是对象,则在传递对象时无法找到它.
Moo moo = new Moo("abc");
bool result1 …Run Code Online (Sandbox Code Playgroud) 我想删除AssemblyInfo.cpp,因为有时会出现一些元数据错误.
AssemblyInfo.cpp对什么有用吗?或者它可以删除没有任何问题?
我在尝试将数据集合发送到我们的服务时收到错误.但是,如果我只将一个项目添加到集合中,那么它会产生罚款.一旦我添加了多个项目,我就会收到以下错误
NetDataContractSerializer不支持使用类型"SmartTrade.Shared.Common.PaymentTerm"作为只获取集合.请考虑使用CollectionDataContractAttribute属性或SerializableAttribute属性标记类型,或者向属性添加setter.
所以这里需要注意的关键是我可以使用单个项目发送集合(IList <>).我已将MaxReceivedMessageSize和MaxArrayLength增加到我认为更合理的范围.
任何人都可以帮助我
我刚刚安装了VS2015,同时安装了.NET Framework 4.6,突然AutoFixture 3.30.8无法创建Claim对象。我猜新的 .NET Framework 4.6 版会导致 AutoFixture 出现一些问题。
我在 VS2013 中创建了一个包含以下代码的测试项目(针对 .NET Framework 4.5.1):
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ploeh.AutoFixture;
namespace AutoFixtureTester
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void CanCreateClaim()
{
var fixture = new Fixture();
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
var claim = fixture.Create<System.Security.Claims.Claim>(); // exception here
Assert.IsNotNull(claim);
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误如下:
Ploeh.AutoFixture.ObjectCreationException: AutoFixture was unable to create an instance from System.IO.Stream, most likely because it has no public constructor, is an abstract or non-public type. …Run Code Online (Sandbox Code Playgroud) 我有一个C++/CLI项目,它使用CWinFormsControl和CWinFormsView在我的MFC视图中创建.NET控件.要做到这一点,我需要#include"afxwinforms.h".
当我在项目上运行代码分析时,我总是得到关于我所包含的一些MFC类的警告.例子:
3>Running Code Analysis...
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.h(87) : warning: CA1704 : Microsoft.Naming : In method 'CWin32Window::CWin32Window(HWND__*)', correct the spelling of 'Wnd' in parameter name 'hWnd' or remove it entirely if it represents any sort of Hungarian notation.
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.h(87) : warning: CA1704 : Microsoft.Naming : In method 'CWin32Window::CWin32Window(HWND__*)', correct the spelling of 'h' in parameter name 'hWnd' or remove it entirely if it represents any sort of Hungarian notation.
3>warning: CA1051 : Microsoft.Design : …Run Code Online (Sandbox Code Playgroud) mfc code-analysis c++-cli suppress-warnings visual-studio-2008
我想在我的应用程序中提供多显示器支持.
在过去,我有一种简单的观点,即多显示器支持只是缺乏开放的多显示器相关错误.如果它似乎适用于多显示器设置,那么它支持多显示器,对吧?
但我想对此提出一些明确的要求.
我需要遵守哪些基本要求,以满足大多数用户的期望,以便他们可以说"是这个应用程序支持多显示器"?
例如,一个明显的要求是所有窗口/消息框/工具提示等必须在应用程序所在的同一监视器上打开.这些窗户的任何孩子都必须在父母的同一台监视器上打开.
你还能想到吗?在任何地方都有任何指导方针吗?
使用DataContracts,您可以从IExtensibleDataObject派生,以允许往返工作,而不会丢失XML文件中的任何未知的其他数据.
我不能使用DataContract,因为我需要控制输出XML的格式.但我还需要能够在旧版本的应用程序中读取未来版本的XML文件,而不会丢失XML文件中的任何数据.
例如
XML v1:
<Person>
<Name>Fred</Name>
</Person>
Run Code Online (Sandbox Code Playgroud)
XML v2:
<Person>
<Name>Fred</Name>
<Age>42</Age>
</Person>
Run Code Online (Sandbox Code Playgroud)
如果从我的应用程序的v1读取XML v2文件,则反序列化并将其再次序列化将其转换为XML v1文件.即"年龄"字段被删除.
是否有类似于IExtensibleDataObject的东西,我可以使用XmlSerializer来避免Age字段消失?
添加功能区项目或调用更新项目的方法后,功能区无法正确刷新.有时在调整窗口大小后可以,但大多数时候面板处于折叠状态.
我尝试了所有我能想到的功能,ReposPanels,RecalcWidths,RecalcLayout等等,但没有任何效果......
我有一个顽固的(或者可能没有经验可能是一个更好的词)Windows主机,我正在尝试安装Magento.它们有一个Plesk接口,允许我安装Magento 1.4.1或1.5.1.但是由于我已经修复了1.6中已修复的1.5的图像上传问题,我想明显使用1.6.
主机的支持是有帮助的,但不愿意为我安装1.6,他们的Web应用程序由第三方提供,所以我猜他们需要为1.6安装程序支付它们.我不明白......他们也没办法让我通过SSH连接.
无论如何我在主机上安装了一个新的Magento 1.5,在家用PC上安装了Magento 1.6,尝试导出1.6数据库并将其导入1.5数据库,但无法导入.我将1.6文件复制到主机并导航到URL给我一个"服务不可用".信息.
太痛苦了.Magento网站上有很多线程关于将1.5安装升级到1.6但主要涉及Pear或Mage或SSH或......当然必须有一个更简单的方法!?
有没有人有一个简单的方法来安装Magento 1.6的想法?
编辑:
我试过@clockworkgeek建议使用'下载器'.
从1.5的干净安装,我去/下载并登录,键入扩展键"http://connect20.magentocommerce.com/community/Mage_All_Latest",然后单击继续.
它开始安装并且看起来很棒.但接下来:
CONNECT ERROR: Package community/Lib_Varien 1.6.1.0 depends on PHP extensions: Array
Fatal error: Call to undefined method Varien_Db_Adapter_Pdo_Mysql::isTableExists()
Run Code Online (Sandbox Code Playgroud)
嘎,臭.然后当我再次导航到/下载器时,我得到了这个:
dbModel read resource does not implement Zend_Db_Adapter_Abstract
Run Code Online (Sandbox Code Playgroud)
它现在完全坏了.呜咽:(
有任何想法吗?
我正在使用ASP.NET MVC Razor View将对象序列化为JSON.调试器中的输出是正确的,但因为它逃脱了每个引用,我认为MVC可能正在尝试对其进行编码,因为最终输出最终会像这样:
{"label":"Blowby","value":17},{"label":"BlownInsert","value":11},{"label":"Blowout","value":13},{"label":"Contamination","value":7},{"label":"CrushedInsert","value":3},{"label":"Reclaim","value":8},{"label":"ShortShot","value":4},{"label":"Sinks","value":10}
Run Code Online (Sandbox Code Playgroud)
json格式正是我想要的,但不是"它需要实际的引号".我没试过HtmlUtilites.HtmlDecode().我该如何修复输出?
如果它有帮助,这里有更多的代码,这是在.cshtml/Razor文件中.
List<LightSwitchApplication.Models.GraphData> DonutGraphData = (List<LightSwitchApplication.Models.GraphData>)ViewData["DonutGraphData"];
string donutSerialized = Newtonsoft.Json.JsonConvert.SerializeObject(DonutGraphData);
Run Code Online (Sandbox Code Playgroud)
和GraphData类:
namespace LightSwitchApplication.Models
{
public class GraphData
{
public string label { get; set; }
public int value { get; set; }
public GraphData(string label, int value)
{
this.label = label;
this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
}
并且实际变量输出到View:
if ($('#donut-graph').length) {
Morris.Donut({
element: 'donut-graph',
data: @donutSerialized,
formatter: function (x) {
return x
}
});
}
Run Code Online (Sandbox Code Playgroud)
以下是调试器中donutSerialized的输出:
"[{\"label\":\"Blowby\",\"value\":17},{\"label\":\"BlownInsert\",\"value\":11},{\"label\":\"Blowout\",\"value\":13},{\"label\":\"Contamination\",\"value\":7},{\"label\":\"CrushedInsert\",\"value\":3},{\"label\":\"Reclaim\",\"value\":8},{\"label\":\"ShortShot\",\"value\":4},{\"label\":\"Sinks\",\"value\":10}]"
Run Code Online (Sandbox Code Playgroud) c# ×5
c++-cli ×2
.net-4.6 ×1
asp.net ×1
asp.net-mvc ×1
assemblyinfo ×1
autofixture ×1
hashtable ×1
hosting ×1
interface ×1
json ×1
json.net ×1
magento ×1
metadata ×1
mfc ×1
oop ×1
parameters ×1
refresh ×1
requirements ×1
upgrade ×1
windows ×1
xml ×1