本文整理汇总了C#中TypeInfoProvider类的典型用法代码示例。如果您正苦于以下问题:C# TypeInfoProvider类的具体用法?C# TypeInfoProvider怎么用?C# TypeInfoProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeInfoProvider类属于命名空间,在下文中一共展示了TypeInfoProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ComparisonTest
public ComparisonTest(string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null)
{
Filename = Path.Combine(TestSourceFolder, filename);
var sourceCode = File.ReadAllText(Filename);
switch (Path.GetExtension(filename).ToLower()) {
case ".cs":
Assembly = CompilerUtil.CompileCS(sourceCode, out TemporaryFiles);
break;
case ".vb":
Assembly = CompilerUtil.CompileVB(sourceCode, out TemporaryFiles);
break;
default:
throw new ArgumentException("Unsupported source file type for test");
}
var program = Assembly.GetType("Program");
if (program == null)
throw new Exception("Test missing 'Program' main class");
TestMethod = program.GetMethod("Main");
if (TestMethod == null)
throw new Exception("Test missing 'Main' method of 'Program' main class");
StubbedAssemblies = stubbedAssemblies;
TypeInfo = typeInfo;
}
开发者ID:Caspeco,项目名称:JSIL,代码行数:27,代码来源:Util.cs
示例2: Analyze
public void Analyze(TypeInfoProvider typeInfoProvider) {
if (!Configuration.DeadCodeElimination.GetValueOrDefault(false))
return;
deadCodeInfo.TypeInfoProvider = typeInfoProvider;
stopwatchElapsed = new Stopwatch();
stopwatchElapsed.Start();
var foundEntrypoints = from assembly in assemblyDefinitions
from modules in assembly.Modules
where modules.EntryPoint != null
select modules.EntryPoint;
deadCodeInfo.AddAssemblies(assemblyDefinitions);
foreach (MethodDefinition method in foundEntrypoints)
{
deadCodeInfo.WalkMethod(method);
}
deadCodeInfo.ResolveVirtualMethodsCycle();
stopwatchElapsed.Stop();
Console.WriteLine("// Dead code analysis took {0} ms", stopwatchElapsed.ElapsedMilliseconds);
}
开发者ID:Don191,项目名称:JSIL,代码行数:27,代码来源:DeadCodeAnalyzer.cs
示例3: MakeDefaultProvider
protected TypeInfoProvider MakeDefaultProvider () {
if (DefaultTypeInfoProvider == null)
// Construct a type info provider with default proxies loaded (kind of a hack)
DefaultTypeInfoProvider = (new AssemblyTranslator(MakeConfiguration())).GetTypeInfoProvider();
return DefaultTypeInfoProvider.Clone();
}
开发者ID:BrainSlugs83,项目名称:JSIL,代码行数:7,代码来源:GenericTestFixture.cs
示例4: Analyze
public void Analyze (AssemblyTranslator translator, AssemblyDefinition[] assemblies, TypeInfoProvider typeInfoProvider) {
if (!Configuration.DeadCodeElimination)
return;
assemblyDefinitions.Clear();
assemblyDefinitions.AddRange(assemblies);
deadCodeInfo.TypeInfoProvider = typeInfoProvider;
stopwatchElapsed = new Stopwatch();
stopwatchElapsed.Start();
var foundEntrypoints = from assembly in assemblyDefinitions
from modules in assembly.Modules
where modules.EntryPoint != null
select modules.EntryPoint;
deadCodeInfo.AddAssemblies(assemblyDefinitions);
foreach (MethodDefinition method in foundEntrypoints)
{
deadCodeInfo.WalkMethod(method);
}
deadCodeInfo.FinishProcessing();
stopwatchElapsed.Stop();
Console.WriteLine("// Dead code analysis took {0} ms", stopwatchElapsed.ElapsedMilliseconds);
}
开发者ID:cbsistem,项目名称:JSIL,代码行数:30,代码来源:DeadCodeAnalyzer.cs
示例5: EmulateStructAssignment
public EmulateStructAssignment(TypeSystem typeSystem, IFunctionSource functionSource, TypeInfoProvider typeInfo, CLRSpecialIdentifiers clr, bool optimizeCopies)
{
TypeSystem = typeSystem;
FunctionSource = functionSource;
TypeInfo = typeInfo;
CLR = clr;
OptimizeCopies = optimizeCopies;
}
开发者ID:nateleroux,项目名称:JSIL,代码行数:8,代码来源:EmulateStructAssignment.cs
示例6: EmulateStructAssignment
public EmulateStructAssignment(QualifiedMemberIdentifier member, IFunctionSource functionSource, TypeSystem typeSystem, TypeInfoProvider typeInfo, CLRSpecialIdentifiers clr, bool optimizeCopies)
: base(member, functionSource)
{
TypeSystem = typeSystem;
TypeInfo = typeInfo;
CLR = clr;
OptimizeCopies = optimizeCopies;
}
开发者ID:simon-heinen,项目名称:JSIL,代码行数:8,代码来源:EmulateStructAssignment.cs
示例7: DecomposeMutationOperators
public DecomposeMutationOperators (
TypeSystem typeSystem, TypeInfoProvider typeInfo,
IFunctionSource functionSource, bool decomposeAllMutations
) {
TypeSystem = typeSystem;
TypeInfo = typeInfo;
FunctionSource = functionSource;
DecomposeAllMutations = decomposeAllMutations;
}
开发者ID:cbsistem,项目名称:JSIL,代码行数:9,代码来源:DecomposeMutationOperators.cs
示例8: MakeTest
protected ComparisonTest MakeTest (
string filename, string[] stubbedAssemblies = null,
TypeInfoProvider typeInfo = null,
AssemblyCache assemblyCache = null
) {
return new ComparisonTest(
EvaluatorPool,
Portability.NormalizeDirectorySeparators(filename), stubbedAssemblies,
typeInfo, assemblyCache
);
}
开发者ID:cbsistem,项目名称:JSIL,代码行数:11,代码来源:GenericTestFixture.cs
示例9: Dispose
public void Dispose () {
if (EvaluatorPool != null) {
EvaluatorPool.Dispose();
EvaluatorPool = null;
}
if (DefaultTypeInfoProvider != null) {
DefaultTypeInfoProvider.Dispose();
DefaultTypeInfoProvider = null;
}
}
开发者ID:cbsistem,项目名称:JSIL,代码行数:11,代码来源:GenericTestFixture.cs
示例10: IntroduceEnumCasts
public IntroduceEnumCasts(TypeSystem typeSystem, TypeInfoProvider typeInfo)
{
TypeSystem = typeSystem;
TypeInfo = typeInfo;
LogicalOperators = new HashSet<JSOperator>() {
JSOperator.LogicalAnd,
JSOperator.LogicalOr,
JSOperator.LogicalNot
};
}
开发者ID:Caspeco,项目名称:JSIL,代码行数:11,代码来源:IntroduceEnumCasts.cs
示例11: ComparisonTest
public ComparisonTest(string filename, Regex[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null)
{
Filename = Path.Combine(TestSourceFolder, filename);
var sourceCode = File.ReadAllText(Filename);
Assembly = CSharpUtil.Compile(sourceCode, out TemporaryFiles);
TestMethod = Assembly.GetType("Program").GetMethod("Main");
StubbedAssemblies = stubbedAssemblies;
TypeInfo = typeInfo;
}
开发者ID:robashton,项目名称:JSIL,代码行数:12,代码来源:Util.cs
示例12: AssemblyTranslator
public AssemblyTranslator(TypeInfoProvider typeInfoProvider = null)
{
// Important to avoid preserving the proxy list from previous translations in this process
MemberIdentifier.ResetProxies();
if (typeInfoProvider != null) {
TypeInfoProvider = typeInfoProvider;
} else {
TypeInfoProvider = new JSIL.TypeInfoProvider();
AddProxyAssembly(typeof(JSIL.Proxies.ObjectProxy).Assembly, false);
}
}
开发者ID:nowonu,项目名称:JSIL,代码行数:12,代码来源:AssemblyTranslator.cs
示例13: ComparisonTest
public ComparisonTest(
EvaluatorPool pool,
IEnumerable<string> filenames, string outputPath,
string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null,
AssemblyCache assemblyCache = null
)
{
var started = DateTime.UtcNow.Ticks;
OutputPath = outputPath;
EvaluatorPool = pool;
var extensions = (from f in filenames select Path.GetExtension(f).ToLower()).Distinct().ToArray();
var absoluteFilenames = (from f in filenames select Path.Combine(TestSourceFolder, f));
if (extensions.Length != 1)
throw new InvalidOperationException("Mixture of different source languages provided.");
var assemblyNamePrefix = Path.GetDirectoryName(outputPath).Split(new char[] { '\\', '/' }).Last();
var assemblyName = Path.Combine(
assemblyNamePrefix,
Path.GetFileName(outputPath).Replace(".js", "")
);
switch (extensions[0]) {
case ".cs":
Assembly = CompilerUtil.CompileCS(absoluteFilenames, assemblyName);
break;
case ".vb":
Assembly = CompilerUtil.CompileVB(absoluteFilenames, assemblyName);
break;
case ".exe":
case ".dll":
var fns = absoluteFilenames.ToArray();
if (fns.Length > 1)
throw new InvalidOperationException("Multiple binary assemblies provided.");
Assembly = Assembly.LoadFile(fns[0]);
break;
default:
throw new ArgumentException("Unsupported source file type for test");
}
if (typeInfo != null)
typeInfo.ClearCaches();
StubbedAssemblies = stubbedAssemblies;
TypeInfo = typeInfo;
AssemblyCache = assemblyCache;
var ended = DateTime.UtcNow.Ticks;
CompilationElapsed = TimeSpan.FromTicks(ended - started);
}
开发者ID:xen2,项目名称:JSIL,代码行数:52,代码来源:TestUtil.cs
示例14: IntroduceEnumCasts
public IntroduceEnumCasts (TypeSystem typeSystem, JSSpecialIdentifiers js, TypeInfoProvider typeInfo, MethodTypeFactory methodTypes) {
TypeSystem = typeSystem;
TypeInfo = typeInfo;
MethodTypes = methodTypes;
JS = js;
LogicalOperators = new HashSet<JSOperator>() {
JSOperator.LogicalAnd,
JSOperator.LogicalOr,
JSOperator.LogicalNot
};
BitwiseOperators = new HashSet<JSOperator>() {
JSOperator.BitwiseAnd,
JSOperator.BitwiseOr,
JSOperator.BitwiseXor
};
}
开发者ID:Don191,项目名称:JSIL,代码行数:18,代码来源:IntroduceEnumCasts.cs
示例15: CreateTranslator
static AssemblyTranslator CreateTranslator(
Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache
)
{
TypeInfoProvider typeInfoProvider = null;
if (
configuration.ReuseTypeInfoAcrossAssemblies.GetValueOrDefault(true) &&
(CachedTypeInfoProvider != null)
) {
if (CachedTypeInfoProviderConfiguration.Assemblies.Equals(configuration.Assemblies))
typeInfoProvider = CachedTypeInfoProvider;
}
var translator = new AssemblyTranslator(configuration, typeInfoProvider, manifest, assemblyCache);
translator.Decompiling += MakeProgressHandler("Decompiling ");
translator.Optimizing += MakeProgressHandler ("Optimizing ");
translator.Writing += MakeProgressHandler ("Generating JS ");
translator.AssemblyLoaded += (fn) => {
Console.Error.WriteLine("// Loaded {0}", ShortenPath(fn));
};
translator.CouldNotLoadSymbols += (fn, ex) => {
};
translator.CouldNotResolveAssembly += (fn, ex) => {
Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
};
translator.CouldNotDecompileMethod += (fn, ex) => {
Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
};
if (typeInfoProvider == null) {
if (CachedTypeInfoProvider != null)
CachedTypeInfoProvider.Dispose();
CachedTypeInfoProvider = translator.GetTypeInfoProvider();
CachedTypeInfoProviderConfiguration = configuration;
}
return translator;
}
开发者ID:snuderl,项目名称:JSIL,代码行数:42,代码来源:Program.cs
示例16: FilenameTestSource
protected IEnumerable<TestCaseData> FilenameTestSource(string[] filenames, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
{
var testNames = filenames.OrderBy((s) => s).ToArray();
for (int i = 0, l = testNames.Length; i < l; i++) {
var testName = testNames[i];
bool isIgnored = testName.StartsWith("ignored:", StringComparison.OrdinalIgnoreCase);
var actualTestName = testName;
if (isIgnored)
actualTestName = actualTestName.Substring(actualTestName.IndexOf(":") + 1);
var item = (new TestCaseData(new object[] { new object[] { actualTestName, typeInfo, asmCache, null, i == (l - 1) } }))
.SetName(Path.GetFileName(actualTestName));
if (isIgnored)
item.Ignore();
yield return item;
}
}
开发者ID:Ocelloid,项目名称:JSIL,代码行数:22,代码来源:GenericTestFixture.cs
示例17: RunComparisonTest
private CompileResult RunComparisonTest(
string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null, Action<string, string> errorCheckPredicate = null,
List<string> failureList = null, string commonFile = null, bool shouldRunJs = true, AssemblyCache asmCache = null,
Func<Configuration> makeConfiguration = null, Action<Exception> onTranslationFailure = null,
string compilerOptions = ""
)
{
CompileResult result = null;
Console.WriteLine("// {0} ... ", Path.GetFileName(filename));
filename = Portability.NormalizeDirectorySeparators(filename);
try {
var testFilenames = new List<string>() { filename };
if (commonFile != null)
testFilenames.Add(commonFile);
using (var test = new ComparisonTest(
EvaluatorPool,
testFilenames,
Path.Combine(
ComparisonTest.TestSourceFolder,
ComparisonTest.MapSourceFileToTestFile(filename)
),
stubbedAssemblies, typeInfo, asmCache,
compilerOptions: compilerOptions
)) {
result = test.CompileResult;
if (shouldRunJs) {
test.Run(makeConfiguration: makeConfiguration, onTranslationFailure: onTranslationFailure);
} else {
string js;
long elapsed;
try {
var csOutput = test.RunCSharp(new string[0], out elapsed);
test.GenerateJavascript(new string[0], out js, out elapsed, makeConfiguration, onTranslationFailure);
Console.WriteLine("generated");
if (errorCheckPredicate != null) {
errorCheckPredicate(csOutput, js);
}
} catch (Exception) {
Console.WriteLine("error");
throw;
}
}
}
} catch (Exception ex) {
if (ex.Message == "JS test failed")
Debug.WriteLine(ex.InnerException);
else
Debug.WriteLine(ex);
if (failureList != null) {
failureList.Add(Path.GetFileNameWithoutExtension(filename));
} else
throw;
}
return result;
}
开发者ID:poizan42,项目名称:JSIL,代码行数:62,代码来源:GenericTestFixture.cs
示例18: RunComparisonTests
/// <summary>
/// Runs one or more comparison tests by compiling the source C# or VB.net file,
/// running the compiled test method, translating the compiled test method to JS,
/// then running the translated JS and comparing the outputs.
/// </summary>
/// <param name="filenames">The path to one or more test files. If a test file is named 'Common.cs' it will be linked into all tests.</param>
/// <param name="stubbedAssemblies">The paths of assemblies to stub during translation, if any.</param>
/// <param name="typeInfo">A TypeInfoProvider to use for type info. Using this parameter is not advised if you use proxies or JSIL.Meta attributes in your tests.</param>
/// <param name="testPredicate">A predicate to invoke before running each test. If the predicate returns false, the JS version of the test will not be run (though it will be translated).</param>
protected void RunComparisonTests(
string[] filenames, string[] stubbedAssemblies = null,
TypeInfoProvider typeInfo = null,
Func<string, bool> testPredicate = null,
Action<string, string> errorCheckPredicate = null,
Func<Configuration> getConfiguration = null
)
{
var started = DateTime.UtcNow.Ticks;
string commonFile = null;
for (var i = 0; i < filenames.Length; i++) {
if (filenames[i].Contains(Path.Combine ("", "Common."))) {
commonFile = filenames[i];
break;
}
}
const string keyName = @"Software\Squared\JSIL\Tests\PreviousFailures";
StackFrame callingTest = null;
for (int i = 1; i < 10; i++) {
callingTest = new StackFrame(i);
var method = callingTest.GetMethod();
if ((method != null) && method.GetCustomAttributes(true).Any(
(ca) => ca.GetType().FullName == "NUnit.Framework.TestAttribute"
)) {
break;
} else {
callingTest = null;
}
}
var previousFailures = new HashSet<string>();
MethodBase callingMethod = null;
if ((callingTest != null) && ((callingMethod = callingTest.GetMethod()) != null)) {
try {
using (var rk = Registry.CurrentUser.CreateSubKey(keyName)) {
var names = rk.GetValue(callingMethod.Name) as string;
if (names != null) {
foreach (var name in names.Split(',')) {
previousFailures.Add(name);
}
}
}
} catch (Exception ex) {
Console.WriteLine("Warning: Could not open registry key: {0}", ex);
}
}
var failureList = new List<string>();
var sortedFilenames = new List<string>(filenames);
sortedFilenames.Sort(
(lhs, rhs) => {
var lhsShort = Path.GetFileNameWithoutExtension(lhs);
var rhsShort = Path.GetFileNameWithoutExtension(rhs);
int result =
(previousFailures.Contains(lhsShort) ? 0 : 1).CompareTo(
previousFailures.Contains(rhsShort) ? 0 : 1
);
if (result == 0)
result = lhsShort.CompareTo(rhsShort);
return result;
}
);
var asmCache = new AssemblyCache();
foreach (var filename in sortedFilenames) {
if (filename == commonFile)
continue;
bool shouldRunJs = true;
if (testPredicate != null)
shouldRunJs = testPredicate(filename);
RunComparisonTest(
filename, stubbedAssemblies, typeInfo,
errorCheckPredicate, failureList,
commonFile, shouldRunJs, asmCache,
getConfiguration ?? MakeConfiguration
);
}
if (callingMethod != null) {
try {
using (var rk = Registry.CurrentUser.CreateSubKey(keyName))
rk.SetValue(callingMethod.Name, String.Join(",", failureList.ToArray()));
//.........这里部分代码省略.........
开发者ID:poizan42,项目名称:JSIL,代码行数:101,代码来源:GenericTestFixture.cs
示例19: GenericTest
protected string GenericTest(
string fileName, string csharpOutput,
string javascriptOutput, string[] stubbedAssemblies = null,
TypeInfoProvider typeInfo = null
)
{
long elapsed, temp;
string generatedJs = null;
using (var test = new ComparisonTest(EvaluatorPool, Portability.NormalizeDirectorySeparators(fileName), stubbedAssemblies, typeInfo)) {
var csOutput = test.RunCSharp(new string[0], out elapsed);
try {
var jsOutput = test.RunJavascript(new string[0], out generatedJs, out temp, out elapsed, MakeConfiguration);
Assert.AreEqual(Portability.NormalizeNewLines(csharpOutput), csOutput.Trim(), "Did not get expected output from C# test");
Assert.AreEqual(Portability.NormalizeNewLines(javascriptOutput), jsOutput.Trim(), "Did not get expected output from JavaScript test");
} catch {
Console.Error.WriteLine("// Generated JS: \r\n{0}", generatedJs);
throw;
}
}
return generatedJs;
}
开发者ID:poizan42,项目名称:JSIL,代码行数:25,代码来源:GenericTestFixture.cs
示例20: FolderTestSource
protected IEnumerable<TestCaseData> FolderTestSource(string folderName, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
{
var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, folderName));
var testNames = Directory.GetFiles(testPath, "*.cs")
.Concat(Directory.GetFiles(testPath, "*.vb"))
.Concat(Directory.GetFiles(testPath, "*.fs"))
.OrderBy((s) => s).ToArray();
string commonFile = null;
foreach (var testName in testNames) {
if (Path.GetFileNameWithoutExtension(testName) == "Common") {
commonFile = testName;
break;
}
}
for (int i = 0, l = testNames.Length; i < l; i++) {
var testName = testNames[i];
if (Path.GetFileNameWithoutExtension(testName) == "Common")
continue;
yield return (new TestCaseData(new object[] { new object[] { testName, typeInfo, asmCache, commonFile, i == (l - 1) } }))
.SetName(PickTestNameForFilename(testName))
.SetDescription(String.Format("{0}\\{1}", folderName, Path.GetFileName(testName)))
.SetCategory(folderName);
}
}
开发者ID:poizan42,项目名称:JSIL,代码行数:28,代码来源:GenericTestFixture.cs
注:本文中的TypeInfoProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论