I am using the RazerEngine at https://github.com/Antaris/RazorEngine
I am wondering how and if it is possible to pass an assembly reference to the engine?
Say I have some logic in an external DLL - how can I call a method in a custom DLL?
string template = "#using ClassLibrary1 #ClassLibrary1.Class1.SomethingFromADLL() ";
string result = Razor.Parse(template, m);
This results in an exception
Unable to compile template. The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?)
you have to find your necessary method and just write its name. For example:
String.Trim();
and
string template="String.Trim()";
I found that if I add the following line prior to the Razor.Parse method it now has access to the ClassLibrary1
Assembly a = Assembly.LoadWithPartialName("ClassLibrary1");
string template = "#using ClassLibrary1 #ClassLibrary1.Class1.SomethingFromADLL() ";
string result = Razor.Parse(template, m);
Related
I am using to get the assembly for following
Assembly assembly = Application.Current.GetType().GetTypeInfo().Assembly;
and i get the ResourceNames form that assembly for using
var resources=assembly.GetManifestResourceNames()
but it gives no resource names in assembly.
Please help me how to achieve it?
In VB.NET, I do that:
Public Function LoadResourceStr(sResID As String) As String
Dim ctx As Windows.ApplicationModel.Resources.Core.ResourceContext = New Windows.ApplicationModel.Resources.Core.ResourceContext()
ctx.Languages = {Globalization.CultureInfo.CurrentUICulture.Name}
Dim rmap As Windows.ApplicationModel.Resources.Core.ResourceMap = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.MainResourceMap.GetSubtree("Resources")
Return rmap.GetValue(sResID, ctx).ValueAsString
End Function
The MainResourceMap is a collection of all resources of application. Important: the files into directories of app (embedded compiled) need is configured to "Content", not "embedded resource". In this case, you can change string ID from "Resources" to "Files".
The sample above show the resource strings into xml files, to translate your app.
I try to get the std strings keys from CCDictionary allKeys() method
but i got stack when i try to get the key from the CCArray
this is what i have :
CCArray* pAllkeys = CCArray::create();
pAllkeys->addObjectsFromArray(GameSingleTone::getInstance()->getGemsDictionary()->allKeys());
pAllkeys->retain();
here i try to get the keys but im getting compilation error:
int gemsToRemoveCount = pAllkeys ->count();
for(int i=0;i<gemsToRemoveCount;i++)
{
std::string gemKey = pAllkeys->objectAtIndex(i);
}
this is the compilation error im getting :
4
IntelliSense: no suitable constructor exists to convert from "cocos2d::CCObject *" to "std::basic_string<char, std::char_traits<char>, std::allocator<char>>"
update
found the solution after diggings the headers
CCString* name = dynamic_cast<CCString*>(pAllkeys->objectAtIndex(i));
std::string newkey = name->m_sString;
CCArray is a container that can contain only CCObject classes. By adding std::string objects you violated that, but this really isn't your fault - the CCArray class should have type-checked on add and failed at that point.
As it is now it reports the error because objectAtIndex returns a CCObject* but you're assuming that it contains and returns objects of type std::string.
Solution: use a std::vector<std::string> instead of CCArray to store strings.
I have an application that uses DynamicProxy 3.1 to do runtime interception. I have a test assembly that uses NSubstitute for mocking. I just wrote some "integration" tests against my fully bootstrapped container (StructureMap using InterceptWith to do the interception) so that I can assert that certain types coming out of the container are proxied properly.
[Subject(typeof(RobotBoard))]
public class When_resolving_an_intercepted_type : WithContainer<IRobotBoard>
{
It should_have_recovery = () => Subject.ShouldHaveInterceptor<RecoveryInterceptor>();
}
public static class TestExtensions
{
public static void ShouldHaveInterceptor<T>(this object obj)
where T : IInterceptor
{
((IProxyTargetAccessor)obj)
.GetInterceptors()
.ToList()
.Exists(x => x is T)
.ShouldBeTrue();
}
}
However, I get this error, indicating that DynamicProxy references are inside the NSubstitute assembly, too! (it appears to be ilmerged).
Error 11 MyCompany.MyModule.Specifications D:\code\source\tests\When_resolving_an_intercepted_type.cs
The type 'Castle.DynamicProxy.IProxyTargetAccessor' exists in both 'd:\code\packages\Castle.Core.3.1.0\lib\net40-client\Castle.Core.dll' and 'd:\code\packages\NSubstitute.1.4.2.0\lib\NET40\NSubstitute.dll'
Is there anyway around this conflict?
You could grab the NSubstitute source code and remove the ilmerge commands from the project's targets. I've opened issue 86 on their repository to address this.
<exec command=""$(MSBuildProjectDirectory)\..\..\ThirdParty\Ilmerge\ILMerge.exe" /internalize:"$(MSBuildProjectDirectory)\ilmerge.exclude" /keyfile:$(AssemblyOriginatorKeyFile) /out:#(MainAssembly) "#(IntermediateAssembly)" #(AssembliesToMerge->'"%(FullPath)"', ' ')" Condition=" '$(TargetFrameworkVersion)' == 'v3.5'" />
<exec command=""$(MSBuildProjectDirectory)\..\..\ThirdParty\Ilmerge\ILMerge.exe" /internalize:"$(MSBuildProjectDirectory)\ilmerge.exclude" /keyfile:$(AssemblyOriginatorKeyFile) /out:#(MainAssembly) /targetplatform:"v4,$(FrameworkReferenceAssemblyPath)." "#(IntermediateAssembly)" #(AssembliesToMerge->'"%(FullPath)"', ' ')" Condition=" '$(TargetFrameworkVersion)' == 'v4.0'" />
You could try using an alias to reference the NSubstitute or DynamicProxy assemblies.
See MSDN How to: Use the Global Namespace Alias (C# Programming Guide) for more info.
You can use the 'extern alias' directive as explained here:
http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx
basically
(1) in VS, go to the assembly reference for FooVersion1, and right click > Properties.
(2) change 'aliases' value to 'FooVersion1'
(3) in your .cs file use:
extern alias FooVersion1;
using foo = FooVersion1::FooVersion1;
...
var something = foo.FooClass();
I am getting an error on TransactionScope() and datacontext as below.
The type or namespace name 'TransactioScope' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'HRPaidTimeOffDataContext' could not be found (are you missing a using directive or an assembly reference?)
What must I do to fix this issue in the code below.
using ( TransactioScope ts = new TransactionScope())
{
// Create the data context
using (HRPaidTimeOffDataContext db = new HRPaidTimeOffDataContext())
{
//Now save the record
if (this.Save(db, ref validationErrors, userAccountId))
{
// Commit transaction if update was successful
ts.Complete();
return true;
}
else
{
return false;
}
}
}
are you missing a using directive or an assembly reference?
Yes, you are missing that. Two actually...
The first: TransactionScope.
In the documentation (http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx) you wil find:
Namespace: System.Transactions
Assembly: System.Transactions (in
System.Transactions.dll)
So you need to include this line in the top of your code:
using System.Transactions;
The other one is one of your own
HRPaidTimeOffDataContext
So I cannot tell you what to type, but I guess you will manage by now.
I've got a string which, in run-time, contains the name of a class that I want to instantiate. How would I do that?
I read suggestions to use flash.utils.getDefinitionByName():
var myClass:Class = getDefinitionByName("package.className") as Class;
var myInstance:* = new myClass();
However, that gives me the following error:
[Fault] exception, information=ReferenceError: Error #1065: Variable className is not defined.
The easiest method I've come up with is to simply write the classnames out, separated by semicolons, anywhere in your project.
e.g. I create an Assets.as file with this in it:
package {
public class Assets {
// To avoid errors from the compiler when calling getDefinitionByName
// just list all of the classes that are not otherwise referenced in code:
Balloon;
Cloud;
FlyingHorse;
FlyingPig;
UFO;
Zeppelin;
}
}
Full code example/tutorial on this is here: http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6/
The other option is to use the mxmlc -includes compiler argument like this:
-includes=com.mydomain.package.MyClass
http://blogs.adobe.com/cantrell/archives/2010/09/loading-classes-dynamically-in-actionscript-3.html