我试图从URL字符串中提取域名.我几乎拥有它......我正在使用URI
我有一个字符串..我的第一个想法是使用正则表达式,但后来我决定使用URI类
我需要将上面的内容转换为google.com和google而不使用www
我做了以下
Uri test = new Uri(referrer);
log.Info("Domain part : " + test.Host);
Run Code Online (Sandbox Code Playgroud)
基本上这会返回www.google.com ....如果可能的话,我想尝试返回2个表单......如上所述...
google.com和谷歌
这有可能与URI?
我在观看Scott Hanselman 关于网络部署的视频后,刚刚在VS2010 RC的.NET 3.5项目中启用了配置转换.不幸的是每次我发布我现在都会收到以下错误:
"TransformXml"任务意外失败.System.UriFormatException:无效的URI:URI为空.在System.Uri.CreateThis(String uri,Boolean dontEscape,UriKind uriKind)
,位于Microsoft.Build.BackEnd.TaskExecutionHost的Microsoft.Web.Publishing.Tasks.TransformXml.Execute()的System.Uri..ctor(String uriString).微软.Build.BackEnd.ITaskExecutionHost.Execute()在Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost,TaskLoggingContext taskLoggingContext,TaskHost taskHost,ItemBucket bucket,TaskExecutionMode howToExecuteTask,Boolean&taskResult)
如果我采用一个全新的VS2010 Web应用程序,默认情况下我已经有配置转换,我没有问题,所以我怀疑我的问题与项目有关.有没有人遇到过这个问题或对修复有任何想法?
asp.net configuration publishing visual-studio-2010 visual-studio
对于我所拥有的各种代码,我厌倦了这样的代码块:
if (dict.ContainsKey[key]) {
dict[key] = value;
}
else {
dict.Add(key,value);
}
Run Code Online (Sandbox Code Playgroud)
和查找(即键 - >值列表)
if (lookup.ContainsKey[key]) {
lookup[key].Add(value);
}
else {
lookup.Add(new List<valuetype>);
lookup[key].Add(value);
}
Run Code Online (Sandbox Code Playgroud)
是否存在另一个集合库或扩展方法,无论键和值类型是什么,我都应该在一行代码中执行此操作?
例如
dict.AddOrUpdate(key,value)
lookup.AddOrUpdate(key,value)
Run Code Online (Sandbox Code Playgroud) ......它在哪里记录?
我在这个地方看过这样的例子:
class MyThing {
private _layers: { [id: string] : SimpleLayer } = {};
...
}
Run Code Online (Sandbox Code Playgroud)
......这很有用,这很棒,但语法让我感到困惑.
什么是'id'?为什么语法不仅仅是blah:{string:SimpleLayer},它不起作用.我还看到{[name:string]:Type}和{[index:string]:Type}.
我一直在寻找typescriptlang.org试图找到实际记录的位置,但我似乎根本找不到它.
给定以下结构:
public struct Foo<T>
{
public Foo(T obj) { }
public static implicit operator Foo<T>(T input)
{
return new Foo<T>(input);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码编译:
private Foo<ICloneable> MakeFoo()
{
string c = "hello";
return c; // Success: string is ICloneable, ICloneable implicitly converted to Foo<ICloneable>
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码没有编译 - 为什么?
private Foo<ICloneable> MakeFoo()
{
ICloneable c = "hello";
return c; // Error: ICloneable can't be converted to Foo<ICloneable>. WTH?
}
Run Code Online (Sandbox Code Playgroud) 我想对对象进行二进制序列化,并将结果保存到数据库中.
Person person = new Person();
person.Name = "something";
MemoryStream memorystream = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(memorystream, person);
Run Code Online (Sandbox Code Playgroud)
如何将字符串类型中的memorystream转换为保存在数据库中,之后能够反序列化对象?
不知道如何调用它,但是说你有一个类似下面的类:
class Person
{
public string Name;
public IEnumerable<Person> Friends;
}
Run Code Online (Sandbox Code Playgroud)
然后你有一个人,你想要递归地"展开"这个结构,所以你最终得到一个没有重复的所有人的列表.
你会怎么做?我已经做了一些似乎有用的东西,但我很想知道其他人会怎么做,特别是如果Linq内置了一些内容你可以巧妙地使用它来解决这个小问题:)
这是我的解决方案:
public static IEnumerable<T> SelectRecursive<T>(this IEnumerable<T> subjects, Func<T, IEnumerable<T>> selector)
{
// Stop if subjects are null or empty
if(subjects == null)
yield break;
// For each subject
foreach(var subject in subjects)
{
// Yield it
yield return subject;
// Then yield all its decendants
foreach (var decendant in SelectRecursive(selector(subject), selector))
yield return decendant;
}
}
Run Code Online (Sandbox Code Playgroud)
将使用这样的东西:
var people = somePerson.SelectRecursive(x => x.Friends);
Run Code Online (Sandbox Code Playgroud) 我想检查文件是否存在,如果存在,我想打开它并阅读第1行,
如果文件不存在或文件没有内容,那么我想静默失败而不让任何人知道发生了错误.
我对此感到困惑:我有一个动作,比如说Parent,在相应的视图文件中,我调用了一个子动作,比如Child,父动作和子动作都在同一个控制器中.
我需要Child动作和Parent动作来共享ViewBag.Now中的一些数据,我应该怎么做?这是我的问题:
当我在父视图文件中调用Child动作时,我将viewbag传递给它:@ Html.Action(ViewBag).在我的孩子行动中,我这样做:
public PartialViewResult Child(Object ViewBag)
{
//using the data in ViewBag
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?viewbag对象是通过引用传递的还是与原始viewbag不同的对象(需要更多内存)?
或者,如果Child操作默认情况下与其调用父Action共享viewbag?
从Darin Dimitrov的回答中,我知道我做不到这样的事情:@ Html.Action(ViewBag)
但我真的需要通过子动作多参数,我该怎么办?
我正在尝试在Android v21中设置状态栏文本颜色,但我没有看到它的API方法.这是我到目前为止的背景
MyActivity.java> onCreate:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.white));
}
Run Code Online (Sandbox Code Playgroud)
显然白色背景上的白色文字将无法正常工作.我正在寻找类似的东西
window.setStatusBarTextColor(getResources().getColor(R.color.orange));
Run Code Online (Sandbox Code Playgroud) c# ×5
android ×1
asp.net ×1
collections ×1
ienumerable ×1
publishing ×1
recursion ×1
string ×1
typescript ×1
uri ×1
vbscript ×1
viewbag ×1
wsh ×1