我正在使用C#.NET.
在我的软件中,我提供了设置对话框,用户可以通过该对话框设置我要保存到文件的应用程序设置.
要求(典型):
我想知道最好的方法是什么?另外,将这些设置保存到磁盘的最佳方法是什么?我的意思是我应该创建一个Settings类对象并将其序列化为'settings.dat'或提供结构化文件,如XML/JSON
几乎所有其他软件都需要这样做.那么,是不是有任何设计模式呢?
编辑:
好吧,那是我不知道的事情.这真好 :).但是,当用户在中间使用软件时,他会更改设置,然后应该更改使用这些全局Properties.Settings.Default.*的所有其他对象.有什么样的通知机制吗?某种事件?
System.Array充当公共语言运行时(CLR)中所有数组的基类.根据这篇文章:
对于每个具体的数组类型,[]运行时添加了三种特殊方法:
Get/Set/Address.
事实上,如果我反汇编这个C#代码,
int[,] x = new int[1024,1024];
x[0,0] = 1;
x[1,1] = 2;
x[2,2] = 3;
Console.WriteLine(x[0,0]);
Console.WriteLine(x[1,1]);
Console.WriteLine(x[2,2]);
Run Code Online (Sandbox Code Playgroud)
进入CIL我得到了,
IL_0000: ldc.i4 0x400
IL_0005: ldc.i4 0x400
IL_000a: newobj instance void int32[0...,0...]::.ctor(int32,
int32)
IL_000f: stloc.0
IL_0010: ldloc.0
IL_0011: ldc.i4.0
IL_0012: ldc.i4.0
IL_0013: ldc.i4.1
IL_0014: call instance void int32[0...,0...]::Set(int32,
int32,
int32)
IL_0019: ldloc.0
IL_001a: ldc.i4.1
IL_001b: ldc.i4.1
IL_001c: ldc.i4.2
IL_001d: call instance void int32[0...,0...]::Set(int32,
int32,
int32)
IL_0022: ldloc.0
IL_0023: ldc.i4.2
IL_0024: ldc.i4.2 …Run Code Online (Sandbox Code Playgroud) 我有一个有很多观点的应用程序.我希望只有几个视图能够在旋转设备时旋转到横向.我发现我无法使用,(BOOL)shouldAutorotateToInterfaceOrientation因为这会旋转我的应用中的每个视图.我在Stack Overflow上找到了解决这个问题的方法,但现在我还有另外一个问题要处理.
当我转动设备时视图会旋转但它仍然显示视图,就好像它仍处于纵向模式(直线向上和向下).视图的顶部和底部被切断.有没有办法让视图旋转并调整其大小以适应新的方向?我也发现了这个,但无法让它发挥作用.
这是我对该视图的代码:
@implementation businessBank
@synthesize webView, activityIndicator;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlAddress = @"website_url";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[notification object] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft) {
[self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
} else if (orientation == UIDeviceOrientationLandscapeRight) {
[self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) …Run Code Online (Sandbox Code Playgroud) 我只是想弄清楚为什么以下代码泄漏内存,我有一种有趣的感觉,我没有正确释放阵列内存.这是一个更广泛的Objective-c应用程序中的C函数,我不是C的原生...我曾尝试在数组上使用free(),但感觉这不是整个故事......
有人可以看一看,看看我在这里缺少什么.谢谢!
CFIndex theNumberOfSettings = 3;
CTParagraphStyleSetting theSettings[3] =
{
{kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment},
{kCTParagraphStyleSpecifierLineSpacing, sizeof(lineSpacing), &lineSpacing},
{kCTParagraphStyleSpecifierHeadIndent, sizeof(headIndent), &headIndent}
};
CTParagraphStyleRef theParagraphRef = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
CFAttributedStringSetAttribute(attrString, CFRangeMake(0, CFAttributedStringGetLength(attrString)-1), kCTParagraphStyleAttributeName, theParagraphRef);
CFRelease(theParagraphRef);
free(theSettings);
Run Code Online (Sandbox Code Playgroud) 我有一个类型的泛型类T.在这个类中,我有一个方法,我需要将一个类型T与另一个类型进行比较,T例如:
public class MyClass<T>
{
public T MaxValue
{
// Implimentation for MaxValue
}
public T MyMethod(T argument)
{
if(argument > this.MaxValue)
{
// Then do something
}
}
}
Run Code Online (Sandbox Code Playgroud)
内部的比较操作MyMethod因编译器错误CS0019而失败.是否可以添加约束T来使其工作?我尝试where T: IComparable<T>在类定义中添加一个无效.
我需要拆分一个总是这样的字符串:
某事 - something_else.
我需要将"something_else"放在另一个输入字段中.目前,这个字符串示例正在动态添加到HTML表格行中,如下所示:
tRow.append($('<td>').text($('[id$=txtEntry2]').val()));
Run Code Online (Sandbox Code Playgroud)
我觉得"拆分"是要走的路,但我找不到很少的文档.
我目前正在研究一个红宝石项目,我就如何继续下去了.在项目中,我使用Dir.glob搜索目录及其所有子目录中的某些文件类型并将它们放入数组中.我正在使用的文件类型都具有相同的文件名,并通过扩展名进行区分.例如,
txt_files = Dir.glob("**/*.txt")
doc_files = Dir.glob("**/*.doc")
rtf_files = Dir.glob("**/*.rtf")
Run Code Online (Sandbox Code Playgroud)
会返回类似的东西,
FILECON.txt ASSORTED.txt FIRST.txt
FILECON.doc ASSORTED.doc FIRST.doc
FILECON.rtf ASSORTED.rtf FIRST.rtf
所以,我的问题是如何有效地分解这些数组(处理数千个文件)并将具有相同文件名的所有文件放入数组中.新阵列看起来像,
FILECON.txt FILECON.doc FILECON.rtf
ASSORTED.txt ASSORTED.doc ASSORTED.rtf
等等
我甚至不确定glob是否是正确的方法(所有具有相同文件名的文件都在相同的文件夹中).任何帮助将不胜感激!
我测试通过C#发送了一些邮件,但我不能告诉特效设置IsBodyHtml到true了.无论价值如何,我在Body中发送的内容都显示内容类型为"text/plain",而我的HTML显示标签以及所有在我的电子邮件客户端(gmail)中.那个标志究竟应该做什么?
注意:我可以通过创建AlternateView内容类型为"text/html" 来发送HTML电子邮件,我只想了解设置正文的工作方式.
这是我的标题:
#ifndef BARELYSOCKET_H
#define BARELYSOCKET_H
#include <QObject>
//! The First Draw of the BarelySocket!
class BarelySocket: public QObject
{
Q_OBJECT
public:
BarelySocket();
public slots:
void sendMessage(Message aMessage);
signals:
void reciveMessage(Message aMessage);
private:
// QVector<Message> reciveMessages;
};
#endif // BARELYSOCKET_H
Run Code Online (Sandbox Code Playgroud)
这是我的班级:
#include <QTGui>
#include <QObject>
#include "type.h"
#include "client.h"
#include "server.h"
#include "barelysocket.h"
BarelySocket::BarelySocket()
{
//this->reciveMessages.clear();
qDebug("BarelySocket::BarelySocket()");
}
void BarelySocket::sendMessage(Message aMessage)
{
}
void BarelySocket::reciveMessage(Message aMessage)
{
}
Run Code Online (Sandbox Code Playgroud)
我收到链接器错误:
undefined reference to 'vtable for BarelySocket'
Run Code Online (Sandbox Code Playgroud)
Message是一个复杂的struct …假设您已经在使用m2eclipse插件,那么您可以做什么不会将依赖项更新为您的repo中的最新版本.
例如,在命令行上,您只需添加-U标志,如下所示:
mvn clean install -U
Run Code Online (Sandbox Code Playgroud)
...强制更新依赖项.Eclipse中有这样的东西吗?(它似乎并不总能获得最新的更新.)