In entity framework T4 templates, I can use class CodeGenerationTools.
For example:
void WriteProperty(**CodeGenerationTools** code, EdmProperty edmProperty)
{
WriteProperty(Accessibility.ForProperty(edmProperty),
code.Escape(edmProperty.TypeUsage),
code.Escape(edmProperty),
code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
}
However, I can't find where this class is defined.
Which assembly does it come from? What are its members?
Thanks
That is not class from assembly. It is included class from another template:
<## include file="EF.Utility.CS.ttinclude"#>
This files is normally stored in VS installation directory:
%VSINSTALLDIR%\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes
Related
I'm creating an aspect to wrap my services but I'm also defining some services under the package
com.foo.arch
My application classes will be instead under
com.foo
Please notice that arch is a subpackage of com.foo but I can't put the "arch" keyword before.Isn't there a pointcut expression to say:
All classess under com.foo not having "arch" as third package?
Consider an interface SampleService
public interface SampleService {
void test();
}
and has 3 implementations in these three package
com
com.foo
com.foo.arch
an aspect to exclude arch package and only advice classes under com and com.foo would be as follows
#Component
#Aspect
public class ExcludeAspect {
#Around("execution(* test()) && !within(com.foo.arch.*)")
public void adviceTestMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("Adviced");
pjp.proceed();
}
}
Reference :
within
Combining Pointcut Expressions
Hope this helps
How about adding this to your pointcut?
within(com.foo..*) && !within(com.foo.arch..*)
This will capture all sub-packages of com.foo except for com.foo.arch and its respective sub-packages.
If you only want com.foo and no sub-packages at all, it would simply be:
within(com.foo.*)
I am new to c#, recently I read the source of code of Oxygen not include(using dnspy), which have some confusing code. I tried google but nothing helpful can be found.
Threr is a class called ElementEntry derived from a template class YamlIO。
what confuse me is that this template take the parameter T same as the class ElementEntry.
I think this may cause some problem. Am I right?
public class YamlIO<T>
{
...
}
public class ElementEntry : YamlIO<ElementEntry>
{
...
}
So i have been designig an application to run on the Zend Framework 1.11 And as any programmer would do when he sees repeated functionalities i wanted to go build a base class with said functionalities.
Now my plan is to build a library 'My' so i made a folder in the library directory in the application. So it looks like this
Project
Application
docs
library
My
public
test
So i created a BaseController class in the My folder and then decided to have the IndexController in my application extend the BaseController.
The Basecontroller looks like this :
class My_BaseController extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->test = 'Hallo Wereld!';
}
}
And the IndexController looks like this :
class WMSController extends My_BaseController
{
public function indexAction()
{
parent::indexAction();
}
}
As adviced by a number of resources i tried adding the namespace for the library in the application.ini using the line
autoloadernamespaces.my = “My_”
But when i try to run this application i recieve the following error
Fatal error: Class 'My_BaseController' not found in
C:\wamp\www\ZendTest\application\controllers\IndexController.php
Am i missing something here? Or am i just being a muppet and should try a different approach?
Thanks in advance!
Your original approach will work for you in application.ini, you just had a couple of problems with your set up.
Your application.ini should have this line:-
autoloadernamespaces[] = "My_"
Also, you have to be careful with your class names, taking your base controller as an example, it should be in library/My/Controller/Base.php and should look like this:-
class My_Controller_Base extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->test = 'Hello World!';
}
}
You can then use it like this:-
class WMSController extends My_Controller_Base
{
public function indexAction()
{
parent::indexAction();
}
}
So, you had it almost right, but were missing just a couple of details. It is worth getting to know how autoloading works in Zend Framework and learning to use the class naming conventions
I don't know about .ini configuration, but I add customer libraries like this (index.php):
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->registerNamespace('My_');
I have a project containing several interfaces and I want to write one template to generate classes which implement these interfaces(e.g: if I have 2 interfaces, the template will generate 2 classes). Generated class is put into a specific folder.
Currently, I have two issue:
1. The my template only generate one file which contain many classes.
2. The class is created below a text template.
Below is my code:
<## template language="C#" #>
<## include file="EF.Utility.CS.ttinclude"#>
<## output extension=".cs"#>
<#
Assembly assembly = Assembly.LoadFrom(#"Example.dll");
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsInterface)
{
string nameSpace = "Example.Client";
string className = type.Name.TrimStart('I')";
string interfaceName = type.Name;
#>
namespace <#= nameSpace #>
{
public class <#= className #> : <#= interfaceName #>
{
}
}
<#
}
}
#>
How can I generate many classes to a specific folder? Can you help me, please?
Thanks,
With your template above you would just put it in the template (.tt file) in that directory. If you want your template file to be in a higher directory look at Oleg's http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/ Note the SaveOutput() method.
check out http://www.olegsych.com/2007/12/text-template-transformation-toolkit/
also http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/
But why bother? If it's generated code then you shouldn't need to touch it.
I have been trying to use the configurable provider model for handling my MEF imports and exports from MEF Contrib (link). I've read the Codeplex documentation and Code Junkie's blog post (link); however, I can't seem to get the container to create the parts. Where am I going wrong?
Program.cs
namespace MEFTest
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.Run();
}
// [ImportMany("command", typeof(IHelp))]
public IEnumerable<IHelp> Commands { get; set; }
void Run()
{
Compose();
foreach(IHelp cmd in Commands)
{
Console.WriteLine(cmd.HelpText);
}
Console.ReadKey();
}
void Compose()
{
var provider = new ConfigurableDefinitionProvider("mef.configuration");
var catalog = new DefinitionProviderPartCatalog<ConfigurableDefinitionProvider>(provider);
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
}
}
TestCommand.cs
namespace MEFTest
{
//[Export("command", typeof(IHelp))]
public class TestCommand : IHelp
{
private string _helpText = "This is a test.";
public string CommandName
{
get { return "Test"; }
}
public string HelpText
{
get { return _helpText; }
}
}
}
App.Config section:
<mef.configuration>
<parts>
<part type="MEFTest.TestCommand, MEFTest">
<exports>
<export contract="IHelp" />
</exports>
</part>
<part type="MEFTest.Program, MEFTest">
<imports>
<import member="Commands" contract="IHelp" />
</imports>
</part>
</parts>
</mef.configuration>
I don't get any build errors and it runs fine if I switch to the typical attribute-based system that is part of the MEF core (with the appropriate catalog too). Program.Commands is always NULL in the above example. I tried to just use a singular property instead of a collection and get the same results.
When I debug I can get the provider.Parts collection so I know it's accessing the configuration information correctly; however, I get an InvalidOperationException whenever I debug and try to drill into catalog.Parts.
Anyone have any experience as to where I'm going wrong here?
As documented here, you also need this in your config file:
<configSections>
<section
name="mef.configuration"
type="MefContrib.Models.Provider.Definitions.Configurable.PartCatalogConfigurationSection, MefContrib.Models.Provider" />
</configSections>
If you already have that, then it might be interesting to show us the stack trace of the InvalidOperationException that you get when accessing provider.Parts.
I had the same problems and could not get it to work, but here are some details:
It seems that ComposeParts() does not work as expected (at least in the version I used) because it uses static methods, based on Reflection to find all required Imports (so it seems that this part cannot be changed from outside of MEF). Unfortunately we want to use xml configuration and not the MEF attributes.
It works if you add [Import] attributes to the members of the class you you use with ComposeParts(). In your case this would be "Programm". In this case all exports defined in the configuration file will be found.
I could not find any documentation or examples on the MEF Contrib page relating to that problem. Also there is no unittest in the MEF contrib projekt that uses ComposeParts().
A workaround would be to use container.GetExportedValues() to retrieve the values, but in this case you have to set the classes members manually.
Hope that helps.