本文整理汇总了C#中Uri.MakeRelativeUri方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.MakeRelativeUri方法的具体用法?C# Uri.MakeRelativeUri怎么用?C# Uri.MakeRelativeUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri.MakeRelativeUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DocumentationIndexIsUpToDate
public void DocumentationIndexIsUpToDate()
{
var documentationIndexFile = ReadDocumentationFile("../mkdocs.yml");
var docsDirectoryPath = new Uri(docsDirectory.FullName, UriKind.Absolute);
Console.WriteLine(docsDirectoryPath);
foreach (var markdownFile in docsDirectory.EnumerateFiles("*.md", SearchOption.AllDirectories))
{
var fullPath = new Uri(markdownFile.FullName, UriKind.Absolute);
var relativePath = docsDirectoryPath
.MakeRelativeUri(fullPath)
.ToString()
.Replace("docs/", string.Empty);
// The readme file in the docs directory is not supposed to be deployed to ReadTheDocs;
// it's only there for the convenience of contributors wanting to improve the documentation itself.
if (relativePath == "readme.md")
{
continue;
}
documentationIndexFile.ShouldContain(relativePath, () => string.Format("The file '{0}' is not listed in 'mkdocs.yml'.", relativePath));
}
}
示例2: Uri_MakeRelativeUri_NullParameter_ThrowsArgumentException
public void Uri_MakeRelativeUri_NullParameter_ThrowsArgumentException()
{
Assert.Throws<ArgumentNullException>(() =>
{
Uri baseUri = new Uri("http://localhost/");
Uri rel = baseUri.MakeRelativeUri((Uri)null);
});
}
示例3: MakeRelative
public void MakeRelative(Uri baseUri, Uri uri, Uri expected)
{
Uri relativeUri = baseUri.MakeRelativeUri(uri);
Assert.Equal(expected, relativeUri);
if (!expected.IsAbsoluteUri)
{
UriCreateStringTests.VerifyRelativeUri(relativeUri, expected.OriginalString, expected.ToString());
}
}
示例4: MakeRelativePath
public static String MakeRelativePath(String fromPath, String toPath)
{
Uri fromUri = new Uri(fromPath);
Uri toUri = new Uri(toPath);
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
return relativePath.Replace('/', Path.DirectorySeparatorChar);
}
示例5: MakeDataRelativePath
string MakeDataRelativePath(string path)
{
if (path.Length > 0)
{
Uri baseUri = new Uri(Application.dataPath + "/");
return baseUri.MakeRelativeUri(new Uri(path)).ToString();
}
else
{
return path;
}
}
示例6: MakeRelativePath
public static string MakeRelativePath(string fromPath, string toPath)
{
if (fromPath.Last() != Path.DirectorySeparatorChar)
{
fromPath += Path.DirectorySeparatorChar;
}
if (toPath.Last() != Path.DirectorySeparatorChar)
{
toPath += Path.DirectorySeparatorChar;
}
var fromUri = new Uri(fromPath);
var toUri = new Uri(toPath);
var relativeUri = fromUri.MakeRelativeUri(toUri);
var relativePath = Uri.UnescapeDataString(relativeUri.ToString());
return relativePath.Replace('/', Path.DirectorySeparatorChar);
}
示例7: MakeRelativePath
public static string MakeRelativePath(string directory, string target)
{
if (string.IsNullOrEmpty(directory)) throw new ArgumentNullException("fromPath");
if (string.IsNullOrEmpty(target)) throw new ArgumentNullException("toPath");
Uri fromUri = new Uri(directory + "/");
Uri toUri = new Uri(target);
if (fromUri.Scheme != toUri.Scheme)
return target; // Path can't be made relative.
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
string relativePath = Uri.UnescapeDataString(relativeUri.ToString());
if (toUri.Scheme.ToUpperInvariant() == "FILE")
relativePath = relativePath.Replace(System.IO.Path.AltDirectorySeparatorChar, System.IO.Path.DirectorySeparatorChar);
return relativePath;
}
示例8: ResolveContentId
private static Uri ResolveContentId(Uri uri, ODataDeserializerContext readContext)
{
if (uri != null)
{
IDictionary<string, string> contentIDToLocationMapping = readContext.Request.GetODataContentIdMapping();
if (contentIDToLocationMapping != null)
{
Uri baseAddress = new Uri(readContext.Request.GetUrlHelper().ODataLink());
string relativeUrl = uri.IsAbsoluteUri ? baseAddress.MakeRelativeUri(uri).OriginalString : uri.OriginalString;
string resolvedUrl = ContentIdHelpers.ResolveContentId(relativeUrl, contentIDToLocationMapping);
Uri resolvedUri = new Uri(resolvedUrl, UriKind.RelativeOrAbsolute);
if (!resolvedUri.IsAbsoluteUri)
{
resolvedUri = new Uri(baseAddress, uri);
}
return resolvedUri;
}
}
return uri;
}
示例9: DocumentationIndexIsUpToDate
public void DocumentationIndexIsUpToDate()
{
var documentationIndexFile = ReadDocumentationFile("../mkdocs.yml");
var docsDirectoryPath = new Uri(docsDirectory.FullName, UriKind.Absolute);
Console.WriteLine(docsDirectoryPath);
foreach (var markdownFile in docsDirectory.EnumerateFiles("*.md", SearchOption.AllDirectories))
{
var fullPath = new Uri(markdownFile.FullName, UriKind.Absolute);
var relativePath = docsDirectoryPath
.MakeRelativeUri(fullPath)
.ToString()
.Replace("docs/", string.Empty);
Console.WriteLine(fullPath);
Console.WriteLine(relativePath);
documentationIndexFile.ShouldContain(relativePath, () => string.Format("The file '{0}' is not listed in 'mkdocs.yml'.", relativePath));
}
}
示例10: UriMakeRelative_ExplicitDosFileVsUncFile_ReturnsSecondUri
public void UriMakeRelative_ExplicitDosFileVsUncFile_ReturnsSecondUri()
{
Uri baseUri = new Uri(@"file:///unc/stuff");
Uri test = new Uri(@"file:///u:/hi:there/", UriKind.Absolute);
Uri rel = baseUri.MakeRelativeUri(test);
Uri result = new Uri(baseUri, rel);
Assert.Equal<String>(test.LocalPath, result.LocalPath); //"Transitivity failure"
}
示例11: UriMakeRelative_ExplicitDosFileContainingImplicitDosPath_AddsDotSlash
public void UriMakeRelative_ExplicitDosFileContainingImplicitDosPath_AddsDotSlash()
{
Uri baseUri = new Uri(@"file:///u:/stuff/file");
Uri test = new Uri(@"file:///u:/stuff/h:there/", UriKind.Absolute);
Uri rel = baseUri.MakeRelativeUri(test);
Uri result = new Uri(baseUri, rel);
Assert.Equal<String>(test.LocalPath, result.LocalPath); //"Transitivity failure"
}
示例12: UriMakeRelative_ExplicitFileDifferentBaseWithColon_ReturnsSecondUri
public void UriMakeRelative_ExplicitFileDifferentBaseWithColon_ReturnsSecondUri()
{
Uri baseUri = new Uri(@"file://c:/stuff");
Uri test = new Uri(@"file://d:/hi:there/", UriKind.Absolute);
Uri rel = baseUri.MakeRelativeUri(test);
Assert.False(rel.IsAbsoluteUri, "Result should be relative");
Assert.Equal<String>("d:/hi:there/", rel.ToString());
Uri result = new Uri(baseUri, rel);
Assert.Equal<String>(test.LocalPath, result.LocalPath); // "Transitivity failure"
Assert.Equal<String>(test.ToString(), result.ToString()); // "Transitivity failure"
}
示例13: UriMakeRelative_ExplicitUncFileVsDosFile_ReturnsSecondPath
public void UriMakeRelative_ExplicitUncFileVsDosFile_ReturnsSecondPath()
{
Uri baseUri = new Uri(@"file:///u:/stuff");
Uri test = new Uri(@"file:///unc/hi:there/", UriKind.Absolute);
Uri rel = baseUri.MakeRelativeUri(test);
Uri result = new Uri(baseUri, rel);
// This is a known oddity when mix and matching Unc & dos paths in this order.
// The other way works as expected.
Assert.Equal<string>("file:///u:/unc/hi:there/", result.ToString());
}
示例14: GetBaseUriToWrite
internal static Uri GetBaseUriToWrite(Uri rootBase, Uri currentBase)
{
Uri uriToWrite;
if (rootBase == currentBase || currentBase == null)
{
uriToWrite = null;
}
else if (rootBase == null)
{
uriToWrite = currentBase;
}
else
{
// rootBase != currentBase and both are not null
// Write the relative base if possible
if (rootBase.IsAbsoluteUri && currentBase.IsAbsoluteUri && rootBase.IsBaseOf(currentBase))
{
uriToWrite = rootBase.MakeRelativeUri(currentBase);
}
else
{
uriToWrite = currentBase;
}
}
return uriToWrite;
}
示例15: Run
private void Run()
{
string fileData = File.ReadAllText (json_location);
JSONObject data = new JSONObject (fileData);
Uri assetsPath = new Uri (Application.dataPath);
Uri jsonPath = new Uri (System.IO.Path.GetDirectoryName (json_location));
Uri diff = assetsPath.MakeRelativeUri (jsonPath);
string wd = diff.OriginalString+System.IO.Path.DirectorySeparatorChar;
//test data
if(!data.HasFields(new string[]{"framerate","images","frames","animations"}))
{
Debug.LogError("Error: json file must contain framerate, images, frames, and animations.");
return;
}
//generate sprite frames
List<JSONObject> frames_data = data.GetField ("frames").list;
List<JSONObject> images_data = data.GetField ("images").list;
// load textures
List<Texture2D> images = new List<Texture2D>();
List<List<SpriteMetaData>> sprite_metadata = new List<List<SpriteMetaData>> ();
for(int i=0; i<images_data.Count; i++)
{
string path = wd+images_data[i].str;
Texture2D tex = AssetDatabase.LoadMainAssetAtPath(path) as Texture2D;
images.Add(tex);
sprite_metadata.Add (new List<SpriteMetaData> ());
}
//set meta data based on frames
for(int i=0; i<frames_data.Count; i++)
{
List<JSONObject> frame = frames_data[i].list;
float x = frame[0].f;
float y = frame[1].f;
float w = frame[2].f;
float h = frame[3].f;
int img = (int)frame[4].f;
float rx = frame[5].f;
float ry = frame[6].f;
float imgHeight = (float)images[img].height;
SpriteMetaData meta = new SpriteMetaData{
alignment = (int)SpriteAlignment.Custom,
border = new Vector4(),
name = prefix+"_"+(i).ToString(),
pivot = new Vector2(rx/w,1-(ry/h)),
rect = new Rect(x, imgHeight - y - h, w, h)
};
sprite_metadata[img].Add(meta);
}
//save data back
for(int i=0; i<images.Count; i++)
{
TextureImporter importer = TextureImporter.GetAtPath(wd+images_data[i].str) as TextureImporter;
//importer.assetPath = images_data[i].str;
importer.mipmapEnabled = false;
importer.textureType = TextureImporterType.Sprite;
importer.spriteImportMode = SpriteImportMode.Multiple;
importer.spritesheet = sprite_metadata[i].ToArray();
try
{
AssetDatabase.StartAssetEditing();
AssetDatabase.ImportAsset(importer.assetPath);
}
finally
{
AssetDatabase.StopAssetEditing();
}
}
//load sprite dictionary
Dictionary<String,Sprite> sprites = new Dictionary<string, Sprite> ();
for(int i=0; i<images_data.Count; i++)
{
Sprite[] sp = AssetDatabase.LoadAllAssetsAtPath( wd+images_data[i].str ).OfType<Sprite>().ToArray();
for(int j=0; j<sp.Length; j++)
{
sprites[sp[j].name] = sp[j];
}
}
//create animations
int fps = (int)data.GetField ("framerate").f;
List<string> animation_names = data.GetField ("animations").keys;
foreach(string animationName in animation_names)
{
JSONObject animationJson = data.GetField("animations").GetField(animationName);
List<JSONObject> frame_Data = animationJson.GetField("frames").list;
float fpsinc = 1/(float)fps;
EditorCurveBinding curveBinding = new EditorCurveBinding();
curveBinding.type = typeof(SpriteRenderer);
//.........这里部分代码省略.........