我尝试以下列方式实现单例类(我使用VS2008 SP1):
namespace firstNamespace
{
class SingletonClass
{
private SingletonClass() {}
public static readonly SingletonClass Instance = new SingletonClass();
}
}
Run Code Online (Sandbox Code Playgroud)
当我想从不同命名空间中的类访问它时(似乎这是问题,在它工作的同一命名空间中),如:
namespace secondNamespace
{
...
firstNamespace.SingletonClass inst = firstNamespace.SingletonClass.Instance;
...
}
Run Code Online (Sandbox Code Playgroud)
我收到编译器错误:
error CS0122: 'firstNamespace.SingletonClass' is inaccessible due to its protection level
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
提前谢谢了!
c# singleton namespaces compiler-errors visual-studio-2008-sp1
我正在努力学习Gson,而我正在努力进行场上排斥.这是我的课程
public class Student {
private Long id;
private String firstName = "Philip";
private String middleName = "J.";
private String initials = "P.F";
private String lastName = "Fry";
private Country country;
private Country countryOfBirth;
}
public class Country {
private Long id;
private String name;
private Object other;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用GsonBuilder并添加ExclusionStrategy像一个字段名称firstName或country,但我似乎无法管理排除像某些领域的性能country.name.
使用该方法public boolean shouldSkipField(FieldAttributes fa),FieldAttributes不包含足够的信息来匹配具有过滤器的字段country.name.
对于这个问题的解决方案,我将不胜感激.
PS:我想避免注释,因为我想对此进行改进并使用RegEx来过滤字段.
谢谢
编辑:我试图看看是否可以模拟Struts2 JSON插件的行为
使用Gson
<interceptor-ref name="json">
<param name="enableSMD">true</param>
<param name="excludeProperties">
login.password, …Run Code Online (Sandbox Code Playgroud) 我是UI设计的新手 - 想知道在定位各种HTML元素时,处理不同屏幕分辨率的最佳方法是什么?我认为使用%age会是前进的方向但事实并非如此!
所有!也许有人知道为什么这样:
def index_link(object, content = t("#{object.to_s.pluralize}.index"))
#link_to(content, {:controller=>object.to_s.pluralize}, :scope=>"") if can?(:read, p(object)) #this doesn't work too
link_to(content, :controller=>"trademarks")
#link_to(content, trademarks_path) #this do work, but I need to set path from object
end
Run Code Online (Sandbox Code Playgroud)
像这样的例外:
No route matches {:controller=>"devise/trademarks"}
Run Code Online (Sandbox Code Playgroud)
堆:
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:424:in `raise_routing_error'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:406:in `generate'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:453:in `generate'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:481:in `url_for'
actionpack (3.0.3) lib/action_dispatch/routing/url_for.rb:131:in `url_for'
actionpack (3.0.3) lib/action_view/helpers/url_helper.rb:99:in `url_for'
actionpack (3.0.3) lib/action_view/helpers/url_helper.rb:236:in `link_to'
app/helpers/application_helper.rb:53:in `index_link'
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___741328535__615736668_0'
actionpack (3.0.3) lib/action_view/template.rb:135:in `send'
actionpack (3.0.3) lib/action_view/template.rb:135:in `render'
Run Code Online (Sandbox Code Playgroud)
以及如何使它工作?
这可能看起来像一个愚蠢的问题,甚至是主观的,但我不确定这样做的正确方法是什么.
我有一个接收类并改变它的方法(特别是,它向DataTable添加了一个新列).我理解,使用引用类型,我可以通过值或按引用传递它,在这种情况下行为不会改变.
一方面,我不喜欢添加比需要更多的间接.如果by-val有效,我喜欢使用它.
另一方面,by-ref使我的意图更清晰(虽然方法的名称应该足够了).
我应该使用哪个,为什么?
我现在有一个相当复杂的应用程序,我想要包含一个应用程序小部件.到目前为止工作正常,一切都是使用内容提供商,服务和配置实用程序设置的.
现在......我希望能够在第一次初始配置后再次重新配置我的小部件.所以我的猜测只是使用PendingIntent和.getActivity()再次启动我的配置活动.到目前为止工作正常!
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_news_layout);
Intent config_intent = new Intent(context.getApplicationContext(), NewsWidgetConfigure.class);
config_intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mappWidgetId);
config_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent conf_penIntent = PendingIntent.getActivity(context, mappWidgetId, config_intent,
PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.settings_button, conf_penIntent);
Run Code Online (Sandbox Code Playgroud)
现在......问题是,我的配置活动重新启动会带回整个应用程序,这意味着在"返回"之后 - 按下,以及在我的Configuration.finish()之后,用户返回到应用程序,而不是主屏幕.
我确信这个问题与launchModes或Intent Flags有关......但我现在无法掌握它并且它让我烦恼了好几个小时.
在此先感谢您的帮助.
我已经在F#中定义了以下类,具有Linq到SQL的映射属性:
[<Table(Name="Expense")>]
type public Expense(datetime : Nullable<DateTime>, value, category, comment) =
let mutable id = 0
let mutable datetime = if datetime.HasValue then datetime.Value else DateTime.Now
let mutable value = value
let mutable category = category
let mutable comment = comment
[<Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)>]
member x.ExpenseID with get() = id and set v = id <- v
[<Column>]
member x.DateTime with get() = datetime and set v = datetime <- v
[<Column>]
member x.Value with get() = value and set …Run Code Online (Sandbox Code Playgroud) 我有一些在mssql 2005服务器中创建的表.由于我当时缺乏经验,因此创建的表没有主键或无法识别列.
如何将具有唯一ID(自动增量?)的列添加到具有现有数据(大约600k行)的表中?
我需要这是一个主键,以便我可以开始使用SQL Analysis服务.
非常感谢,
亚当
我有一个私有静态字段,我用它来进行同步(锁定).现在我有两个函数,我不想同时执行.所以我这样做了:
public class Synchronization
{
private static object _lock = new object();
public void MethodA()
{
lock (_lock)
{
Console.WriteLine("I shouldn't execute with MethodB");
}
}
public void MethodB()
{
lock (_lock)
{
Console.WriteLine("I shouldn't execute with MethodA");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道锁定一个对象会阻止单个函数的并行执行,但如果我在同时运行的不同方法中使用相同的锁对象,那么同样的工作吗?简单地说,put可以任何其他线程获取锁定另一个函数中已经锁定的对象吗?
我的问题是关于如何杀死已经加载的重定向.
我有一个页面打开,在到达目的地之前设置了10秒的延迟:
var strUrl = /*from query string, or somewhere else..*/
window.onload = function()
{
window.setTimeout('redirect(strUrl)', 10000);
}
function redirect(strUrl)
{
document.location=strUrl;
}
Run Code Online (Sandbox Code Playgroud)
现在在HTML体中我有一些UI元素,2个按钮(继续,书签),1个复选框(不再显示,..)
就像是:
<body onOrientationChange="smartOrientation();">
<div id="img_logo">
<img src="#">
</div>
<div id="txt">
<p>
...blabla...
</p>
</div>
<div id="btn_bookmark">
<a href=""
class="button green"
name="name"
type="submit"
value="Bookmark">Bookmark
</a>
</div>
<!-- checkboxes,..etc -->
</body>
Run Code Online (Sandbox Code Playgroud)
现在我想要的是始终将setTimeout重定向激活,但是如果在那10秒内.用户点击复选框或书签按钮,我希望它打破/停止.
伪:
onload:setTimeOut(URL,10sec); - 1,.. 2,.. 3,..
监听器:if(#div1 ||#div2 || ..#divN)被点击? - >立即停止/ BREAK setTimeout(杀掉10秒炸弹)
ps(Q面):我使用jquery,并在dom.ready()之后设置了onload,因为在那个whay dom.ready总是比onload快一点.因为这会有种族问题吗?
c# ×2
.net ×1
css ×1
database ×1
f# ×1
gson ×1
helpers ×1
html ×1
java ×1
javascript ×1
jquery ×1
json ×1
linq-to-sql ×1
locking ×1
namespaces ×1
redirect ×1
resolution ×1
settimeout ×1
singleton ×1
sql ×1
ssis ×1
t-sql ×1
url-routing ×1