本文整理汇总了C#中Uri.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.ToString方法的具体用法?C# Uri.ToString怎么用?C# Uri.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEntity
// Maps a URI to an Object containing the actual resource.
public override Object GetEntity(Uri uri, string role, Type typeOfObjectToReturn)
{
if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}
if (typeOfObjectToReturn != null && typeOfObjectToReturn != typeof(Stream) && typeOfObjectToReturn != typeof(Object))
{
throw new XmlException(SR.Xml_UnsupportedClass, string.Empty);
}
string filePath = uri.OriginalString;
if (uri.IsAbsoluteUri)
{
if (!uri.IsFile)
throw new XmlException(SR.Format(SR.Xml_SystemPathResolverCannotOpenUri, uri.ToString()));
filePath = uri.LocalPath;
}
try
{
return new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
catch (ArgumentException e)
{
throw new XmlException(SR.Format(SR.Xml_SystemPathResolverCannotOpenUri, uri.ToString()), e);
}
}
示例2: UriIsWellFormed_NewRelativeWithKnownSchemeAndQuery_SuccessButNotWellFormed
public void UriIsWellFormed_NewRelativeWithKnownSchemeAndQuery_SuccessButNotWellFormed()
{
Uri test = new Uri("http:?foo", UriKind.Relative);
Assert.False(Uri.IsWellFormedUriString(test.ToString(), UriKind.Relative), "Not well formed");
Assert.False(Uri.IsWellFormedUriString(test.ToString(), UriKind.Absolute), "Should not be well formed");
Assert.True(Uri.TryCreate(test.ToString(), UriKind.Relative, out test), "TryCreate Mismatch");
Uri result = new Uri(new Uri("http://host.com"), test);
Assert.True(Uri.IsWellFormedUriString(result.ToString(), UriKind.Absolute), "Not well formed");
}
示例3: IdnDnsSafeHost_IdnOffWithUnregisteredScheme_Success
public void IdnDnsSafeHost_IdnOffWithUnregisteredScheme_Success()
{
Uri test = new Uri("any://www.\u30AF.com/");
string dns = test.DnsSafeHost;
Assert.True(dns.IndexOf('%') < 0, "% found");
Assert.True(test.AbsoluteUri.IndexOf('%') < 0, "% found: " + test.AbsoluteUri);
Assert.True(test.ToString().IndexOf('%') < 0, "% found: " + test.ToString());
}
示例4: GetResourceStream
public static StreamResourceInfo GetResourceStream(Uri uriResource)
{
if (!Resources.ContainsKey(uriResource.ToString()))
{
return null;
}
var arrayBuffer = Resources[uriResource.ToString()];
var stream = new Stream(arrayBuffer);
return new StreamResourceInfo(stream, null);
}
示例5: MapUri
public override Uri MapUri(Uri uri) {
string uriStr = uri.ToString();
if (uriStr.Contains("/FileTypeAssociation")) {
int fileIDIndex = uriStr.IndexOf("fileToken=") + 10;
string fileID = uriStr.Substring(fileIDIndex);
string incommingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
// Path.GetExtension will return String.Empty if no file extension found.
int extensionIndex = incommingFileName.LastIndexOf('.') + 1;
string incomingFileType = incommingFileName.Substring(extensionIndex).ToLower();
if (incomingFileType == WeChat.appId) {
return new Uri("/WeChatCallbackPage.xaml?fileToken=" + fileID, UriKind.Relative);
}
}
if (upper != null) {
var upperResult = upper.MapUri(uri);
if (upperResult != uri) {
return upperResult;
}
}
return new Uri("/MainPage.xaml", UriKind.Relative);
}
示例6: Uri_Relative_BaseVsAbsolute_ReturnsFullAbsolute
public void Uri_Relative_BaseVsAbsolute_ReturnsFullAbsolute()
{
string absolute = "http://username:[email protected]:8080/p1/p2/p3/p4/file1?AQuery#TheFragment";
Uri resolved = new Uri(_fullBaseUri, absolute);
Assert.Equal(absolute, resolved.ToString());
}
示例7: Set
// Initially from http://stackoverflow.com/a/1061682
public static void Set(Uri uri, Style style)
{
System.IO.Stream s = new System.Net.WebClient().OpenRead(uri.ToString());
System.Drawing.Image img = System.Drawing.Image.FromStream(s);
string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");
img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp);
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
if (style == Style.Stretched)
{
key.SetValue(@"WallpaperStyle", 2.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Centered)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Tiled)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 1.ToString());
}
SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,
tempPath,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
示例8: getAttributes
public void getAttributes(string audience_email)
{
try{
System.Net.ServicePointManager.ServerCertificateValidationCallback += (s,ce,ca,p) => true;
/*------------------------------- Edit the information below ------------------------*/
string CONDUCTTR_PROJECT_ID = "";
string CONDUCTTR_CONSUMER_KEY = "";
string CONDUCTTR_CONSUMER_SECRET = "";
string CONDUCTTR_CONSUMER_ACCESS_TOKEN = "";
string CONDUCTTR_CONSUMER_ACCESS_TOKEN_SECRET = "";
string CONDUCTTR_API_GET_METHOD = "";
/*------------------------------- Edit the information above ------------------------*/
Uri URL = new Uri("https://api.conducttr.com/v1/project/" + CONDUCTTR_PROJECT_ID + "/" + CONDUCTTR_API_GET_METHOD + "?audience_email=" + audience_email);
var config = new OAuthConfig() { ConsumerKey=CONDUCTTR_CONSUMER_KEY, ConsumerSecret=CONDUCTTR_CONSUMER_SECRET };
OAuthAuthorizer auth = new OAuthAuthorizer(config);
auth.AccessToken = CONDUCTTR_CONSUMER_ACCESS_TOKEN;
auth.AccessTokenSecret = CONDUCTTR_CONSUMER_ACCESS_TOKEN_SECRET;
//string json = "";
WWW www=GET(URL.ToString()+"&"+OAuthAuthorizer.AuthorizeRequest2(config, CONDUCTTR_CONSUMER_ACCESS_TOKEN, CONDUCTTR_CONSUMER_ACCESS_TOKEN_SECRET, "GET", URL, null));
}
catch(Exception e){
Debug.Log (e.Message + " : " + e.StackTrace);
//status.text = e.Message;
}
}
示例9: GetEntityAsync
public override Task<Object> GetEntityAsync(Uri absoluteUri,
string role,
Type ofObjectToReturn) {
if (absoluteUri == null) {
throw new ArgumentNullException("absoluteUri");
}
PreloadedData data;
if (!mappings.TryGetValue(absoluteUri, out data)) {
if (fallbackResolver != null) {
return fallbackResolver.GetEntityAsync(absoluteUri, role, ofObjectToReturn);
}
throw new XmlException(Res.GetString(Res.Xml_CannotResolveUrl, absoluteUri.ToString()));
}
if (ofObjectToReturn == null || ofObjectToReturn == typeof(Stream) || ofObjectToReturn == typeof(Object)) {
return Task.FromResult<Object>(data.AsStream());
}
else if (ofObjectToReturn == typeof(TextReader)) {
return Task.FromResult<Object>(data.AsTextReader());
}
else {
throw new XmlException(Res.GetString(Res.Xml_UnsupportedClass));
}
}
示例10: FileDB
public FileDB(Uri _url)
{
CurrTime = DateTime.Now;
string randnum = CurrTime.Year.ToString() + CurrTime.Month.ToString() + CurrTime.Day.ToString() + CurrTime.Hour.ToString() + CurrTime.Minute.ToString() + CurrTime.Second.ToString();
string _file = "FILE" + randnum;
DownloadFile(_file, _url.ToString());
temporary = true;
}
示例11: UriMailTo_SchemeOnly_Success
public void UriMailTo_SchemeOnly_Success()
{
Uri uri = new Uri("mailto:");
Assert.Equal("mailto", uri.Scheme);
Assert.Equal("mailto:", uri.AbsoluteUri);
Assert.Equal("mailto:", uri.ToString());
Assert.Equal("", uri.Host);
}
示例12: Uri_Relative_BaseVsAuthority_ReturnsBaseSchemePlusAuthority
public void Uri_Relative_BaseVsAuthority_ReturnsBaseSchemePlusAuthority()
{
string authority = "//username:[email protected]:8080/p1/p2/p3/p4/file1?AQuery#TheFragment";
Uri resolved = new Uri(_fullBaseUri, authority);
String expectedResult = _fullBaseUri.Scheme + ":" + authority;
Assert.Equal(expectedResult, resolved.ToString());
}
示例13: Uri_Relative_BaseVsFragment_ReturnsBasePlusFragment
public void Uri_Relative_BaseVsFragment_ReturnsBasePlusFragment()
{
string fragment = "#TheFragment";
Uri resolved = new Uri(_fullBaseUri, fragment);
String expectedResult = FullBaseUriGetLeftPart_Query + fragment;
Assert.Equal(expectedResult, resolved.ToString());
}
示例14: Uri_Relative_BaseVsFullPath_ReturnsBaseAuthorityPlusFullPath
public void Uri_Relative_BaseVsFullPath_ReturnsBaseAuthorityPlusFullPath()
{
string fullPath = "/p1/p2/p3/p4/file1?AQuery#TheFragment";
Uri resolved = new Uri(_fullBaseUri, fullPath);
String expectedResult = FullBaseUriGetLeftPart_Authority + fullPath;
Assert.Equal(expectedResult, resolved.ToString());
}
示例15: ValueToSurrogate
static MyUriSurrogate ValueToSurrogate(Uri uri)
{
MyUriSurrogate surrogate = new MyUriSurrogate();
surrogate.Address = uri.ToString();
return surrogate;
}