本文整理汇总了C#中ModuleWeaver类的典型用法代码示例。如果您正苦于以下问题:C# ModuleWeaver类的具体用法?C# ModuleWeaver怎么用?C# ModuleWeaver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModuleWeaver类属于命名空间,在下文中一共展示了ModuleWeaver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModuleWeaverOrdinalTests
public ModuleWeaverOrdinalTests()
{
beforeAssemblyPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"));
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
#endif
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
#endif
afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "3.dll");
File.Copy(beforeAssemblyPath, afterAssemblyPath, true);
var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath);
var weavingTask = new ModuleWeaver
{
Config = XElement.Parse(@"<Caseless StringComparison="" ordinal ""/>"),
ModuleDefinition = moduleDefinition,
};
weavingTask.Execute();
moduleDefinition.Assembly.Name.Name += "ForOrdinal";
moduleDefinition.Write(afterAssemblyPath);
var assembly = Assembly.LoadFrom(afterAssemblyPath);
var type = assembly.GetType("TargetClass", true);
targetClass = Activator.CreateInstance(type);
}
示例2: IntegrationTests
public IntegrationTests()
{
beforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll");
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
#endif
afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.dll");
File.Copy(beforeAssemblyPath, afterAssemblyPath, true);
var assemblyResolver = new MockAssemblyResolver
{
Directory = Path.GetDirectoryName(beforeAssemblyPath)
};
var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath,new ReaderParameters
{
AssemblyResolver = assemblyResolver
});
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = assemblyResolver,
};
weavingTask.Execute();
moduleDefinition.Write(afterAssemblyPath);
assembly = Assembly.LoadFile(afterAssemblyPath);
}
示例3: True
public void True()
{
var xElement = XElement.Parse("<PropertyChanged InjectOnPropertyNameChanged='true'/>");
var moduleWeaver = new ModuleWeaver {Config = xElement};
moduleWeaver.ResolveOnPropertyNameChangedConfig();
Assert.IsTrue(moduleWeaver.InjectOnPropertyNameChanged);
}
示例4: ModuleWeaverOperandTests
public ModuleWeaverOperandTests()
{
var beforeAssemblyPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"));
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
#endif
var afterAssemblyPath = typeof(ModuleWeaverOperandTests).Name + ".dll";
var moduleDefinition = ModuleDefinition.ReadModule(beforeAssemblyPath);
AddConditionalBranchLong(moduleDefinition, moduleDefinition.Types.Single(t => t.Name == "TargetClass"));
// Offset assignment happens on write
// Having offsets assigned prior to weaving makes tracking down bugs easier
moduleDefinition.Write(afterAssemblyPath);
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
};
weavingTask.Execute();
moduleDefinition.Assembly.Name.Name += "ForOperand";
moduleDefinition.Write(afterAssemblyPath);
var assembly = Assembly.LoadFrom(afterAssemblyPath);
var type = assembly.GetType("TargetClass", true);
targetClass = Activator.CreateInstance(type);
}
示例5: WeaveAssembly
protected static string WeaveAssembly(Type assemblyType)
{
var normalizedPath = assemblyType.Assembly.CodeBase.Replace(@"file:///", string.Empty);
var weaver = new ModuleWeaver();
return WeavedAssemblyPath = weaver.WeaveToShadowFile(normalizedPath);
}
示例6: VerifyRefError
public void VerifyRefError()
{
var errors = new List<string>();
var assemblyPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\AssemblyToProcessWithErrors\bin\Debug\AssemblyToProcessWithErrors.dll"));
#if (!DEBUG)
assemblyPath = assemblyPath.Replace("Debug", "Release");
#endif
var moduleDefinition = ModuleDefinition.ReadModule(assemblyPath, new ReaderParameters
{
//SymbolStream = symbolStream,
ReadSymbols = true
});
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
LogErrorPoint = (s, p) => errors.Add(s)
};
weavingTask.Execute();
Assert.Contains("Method 'ClassUsingOutParam.Method' uses member 'ClassWithField.Member' as a 'ref' or 'out' parameter. This is not supported by Fielder. Please convert this field to a property manually.", errors);
Assert.Contains("Method 'ClassUsingRefParam.Method' uses member 'ClassWithField.Member' as a 'ref' or 'out' parameter. This is not supported by Fielder. Please convert this field to a property manually.", errors);
Assert.AreEqual(2, errors.Count);
}
示例7: Simple
public void Simple()
{
var beforeAssemblyPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\AssemblyWithExcludes\bin\Debug\AssemblyWithExcludes.dll"));
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
#endif
var afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.dll");
File.Copy(beforeAssemblyPath, afterAssemblyPath, true);
var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath);
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
ExcludeNamespaces = new List<string> { "ExcludeNamespace"}
};
weavingTask.Execute();
moduleDefinition.Write(afterAssemblyPath);
var assembly = Assembly.LoadFile(afterAssemblyPath);
var excludeType = assembly.GetType("ExcludeNamespace.ExcludeClass");
Assert.IsFalse(excludeType.GetMethod("Method").IsVirtual);
var includeType = assembly.GetType("IncludeNamespace.IncludeClass");
Assert.IsTrue(includeType.GetMethod("Method").IsVirtual);
var inNamespaceButWithAttributeType = assembly.GetType("IncludeNamespace.InNamespaceButWithAttributeClass");
Assert.IsFalse(inNamespaceButWithAttributeType.GetMethod("Method").IsVirtual);
var notInNamespaceButWithAttributeType = assembly.GetType("ExcludeNamespace.NotInNamespaceButWithAttributeClass");
Assert.IsFalse(notInNamespaceButWithAttributeType.GetMethod("Method").IsVirtual);
#if(DEBUG)
Verifier.Verify(beforeAssemblyPath, afterAssemblyPath);
#endif
}
示例8: AssemblyWeaver
static AssemblyWeaver()
{
BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll");
BeforeAssemblyPathSymbols = Path.ChangeExtension(BeforeAssemblyPath, "pdb");
#if (!DEBUG)
BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release");
BeforeAssemblyPathSymbols = BeforeAssemblyPathSymbols.Replace("Debug", "Release");
#endif
AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll");
AfterAssemblyPathSymbols = Path.ChangeExtension(AfterAssemblyPath, "pdb");
File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true);
File.Copy(BeforeAssemblyPathSymbols, AfterAssemblyPathSymbols, true);
var assemblyResolver = new MockAssemblyResolver();
var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, new ReaderParameters { ReadSymbols = true });
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = assemblyResolver,
LogError = LogError,
LogInfo = LogInfo,
DefineConstants = new[] { "DEBUG" }, // Always testing the debug weaver
};
weavingTask.Execute();
moduleDefinition.Write(AfterAssemblyPath, new WriterParameters { WriteSymbols = true });
Assembly = Assembly.LoadFile(AfterAssemblyPath);
}
示例9: ProcessAssemblyBaseTest
protected ProcessAssemblyBaseTest( string relativePath )
{
BeforeAssemblyPath = Path.GetFullPath( relativePath );
#if !DEBUG
BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release");
#endif
AfterAssemblyPath = BeforeAssemblyPath.Replace( ".dll", "2.dll" );
File.Copy( BeforeAssemblyPath, AfterAssemblyPath, true );
var moduleDefinition = ModuleDefinition.ReadModule( AfterAssemblyPath );
var currentDirectory = AssemblyLocation.CurrentDirectory();
PersistentInfo = PersistentInfo.LoadFromPath( currentDirectory );
StandardInfo = new StandardInfo( PersistentInfo, moduleDefinition );
var moduleWeaver = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AddinDirectoryPath = currentDirectory,
SolutionDirectoryPath = currentDirectory,
AssemblyFilePath = AfterAssemblyPath,
};
moduleWeaver.Execute();
moduleDefinition.Write( AfterAssemblyPath );
moduleWeaver.AfterWeaving();
AfterAssembly = Assembly.LoadFile( AfterAssemblyPath );
}
示例10: False
public void False()
{
var xElement = XElement.Parse("<PropertyChanged InjectOnPropertyNameChanging='false'/>");
var moduleWeaver = new ModuleWeaver { Config = xElement };
moduleWeaver.ResolveOnPropertyNameChangingConfig();
Assert.IsFalse(moduleWeaver.InjectOnPropertyNameChanging);
}
示例11: AssemblyWeaver
public AssemblyWeaver(string assemblyPath, List<string> referenceAssemblyPaths = null)
{
if (referenceAssemblyPaths == null)
{
referenceAssemblyPaths = new List<string>();
}
assemblyPath = FixAssemblyPath(assemblyPath);
var newAssembly = assemblyPath.Replace(".dll", "2.dll");
File.Copy(assemblyPath, newAssembly, true);
var assemblyResolver = new MockAssemblyResolver();
foreach (var referenceAssemblyPath in referenceAssemblyPaths)
{
var directoryName = Path.GetDirectoryName(referenceAssemblyPath);
assemblyResolver.AddSearchDirectory(directoryName);
}
var readerParameters = new ReaderParameters
{
AssemblyResolver = assemblyResolver
};
var moduleDefinition = ModuleDefinition.ReadModule(newAssembly, readerParameters);
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = assemblyResolver,
LogError = LogError,
ReferenceCopyLocalPaths = referenceAssemblyPaths
};
weavingTask.Execute();
moduleDefinition.Write(newAssembly);
Assembly = Assembly.LoadFrom(newAssembly);
}
示例12: FieldToPropertyForwarder
public FieldToPropertyForwarder(ModuleWeaver moduleWeaver, FieldToPropertyConverter fieldToPropertyConverter, MsCoreReferenceFinder msCoreReferenceFinder, MethodFinder methodFinder)
{
this.moduleWeaver = moduleWeaver;
this.msCoreReferenceFinder = msCoreReferenceFinder;
this.methodFinder = methodFinder;
forwardedFields = fieldToPropertyConverter.ForwardedFields;
}
示例13: WeaverHelper
public WeaverHelper(string assemblyToProcess)
{
var assemblyFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
BeforeAssemblyPath = Path.Combine(assemblyFolder, assemblyToProcess);
AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll");
File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true);
var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, new ReaderParameters());
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
LogDebug = s => System.Diagnostics.Debug.WriteLine(s, "Debug"),
LogInfo = s => System.Diagnostics.Debug.WriteLine(s, "Info"),
LogWarning = s => System.Diagnostics.Debug.WriteLine(s, "Warning"),
LogError = s => System.Diagnostics.Debug.WriteLine(s, "Error"),
};
weavingTask.Execute();
moduleDefinition.Write(AfterAssemblyPath);
//ProvideIlStepThrough(AfterAssemblyPath);
Assembly = Assembly.LoadFile(AfterAssemblyPath);
}
示例14: WithIncludesTests
public WithIncludesTests()
{
beforeAssemblyPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory,@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"));
#if (!DEBUG)
beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release");
#endif
afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "3.dll");
File.Copy(beforeAssemblyPath, afterAssemblyPath, true);
var assemblyResolver = new MockAssemblyResolver
{
Directory = Path.GetDirectoryName(beforeAssemblyPath)
};
var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath,new ReaderParameters
{
AssemblyResolver = assemblyResolver
});
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = assemblyResolver,
IncludeNamespaces = new List<string>{"MyNameSpace"},
LogWarning =s => warnings.Add(s)
};
weavingTask.Execute();
moduleDefinition.Write(afterAssemblyPath);
assembly = Assembly.LoadFile(afterAssemblyPath);
}
示例15: Setup
public void Setup()
{
var projectPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\AssemblyToProcess\AssemblyToProcess.csproj"));
assemblyPath = Path.Combine(Path.GetDirectoryName(projectPath), @"bin\Debug\AssemblyToProcess.dll");
#if (!DEBUG)
assemblyPath = assemblyPath.Replace("Debug", "Release");
#endif
newAssemblyPath = assemblyPath.Replace(".dll", "2.dll");
shadowAssemblyPath = assemblyPath.Replace(".dll", "2shadow.dll");
File.Copy(assemblyPath, newAssemblyPath, true);
File.Copy(assemblyPath, shadowAssemblyPath, true);
var moduleDefinition = ModuleDefinition.ReadModule(newAssemblyPath);
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition
};
weavingTask.Execute();
moduleDefinition.Write(newAssemblyPath);
assembly = Assembly.LoadFile(newAssemblyPath);
}