I'm using VS 2012 with Resharper C++.
Is there a way to look at member functions of the base class that can be overridden, and then generate appropriate code in the header/source files?
Yes, there is - you can either use the "Generate overriding members" context action on the name of a derived class, or invoke the "Overriding members" generate code action from inside it. Once you have the declarations of overriding functions inserted, you can invoke the "Generate definitions by declarations" context action to also add the definitions.
Related
In my project I'm using C++/CLI and Windows Forms. I have two Forms. One is executed in main()
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew FormA);
Another FormB is executed from the instance of FormA
FormB^ fb = gcnew FormB();
fb->Show();
I need to change components of FormB from FormA. Normally they are in private: section of class FormB. Is there any nice way to do that different from simply making them all public? In Native C++ I would use friend class but it's not allowed in C++/CLI.
C++/CLI has an access modifier that native C++ does not have. You are looking for internal:
Empowered by the strong support for modules in .NET. It is broader than friend but you have a pretty hard guarantee that whomever is messing with your private parts is never more than a few cubicles away from yours. Code that accesses internal members must be compiled into the same assembly. So your FormB class must be in the same project as your FormA class. The common case.
If you need the equivalent of friend across modules then you need the [InternalsVisibleTo] attribute. Exposing members with a public property would be another common way.
While providing public access to FormB's members may seem like a quick and easy solution, I would advise you to add some methods on FormB to perform said actions.
This way, you can call those methods from FormA, and at the same time retain proper encapsulation.
Hope this helps.
We're updating code to use Autofac. We'd like to use custom delegate types to define factories instead of Func's. But we also use an obfuscator, which renames parameters. We'd like to tell the Autofac container to match by type instead of name as it does with Func's. Is this possible?
On the official documentation of Autofac, you have this information
By default, Autofac matches the parameters of the delegate to the parameters of the constructor by name. If you use the generic Func types, Autofac will switch to matching parameters by type.
http://docs.autofac.org/en/latest/advanced/delegate-factories.html
Could you customize the obfuscator to use the same name for the parameter name of the delegate and the constructor?
As mentioned, the way to do it right now is to use Func. Even if it were possible with just delegate factories, Autofac won't know what to do when there are two parameters of the same type. Here's my answer to a very similar question.
Thanks guys. We ended up creating a custom registration source using Autofac's source as a guide. In our testing, if there are two parameters of the same type, it appears to fall back to order.
I've been trying to find some info on difference between instantiating form fields through static method and the new keyword. Can somebody tell me what are the practical implications, limitations, between new MyFormField and MyFormField::create() esp. with regards to SilverStripe
Using the create factory method would check for overloads (set via Object::useCustomClass()) and return an instance of the custom class in that case.
This method first for strong class overloads (singletons & DB
interaction), then custom class overloads. If an overload is found, an
instance of this is returned rather than the original class. To
overload a class, use Object::useCustomClass()
So using the create method rather than instantiating the Object yourself would provide a possibility to overload the used Class without altering the code.
see
http://api.silverstripe.org/3.1/class-Object.html#_useCustomClass
http://api.silverstripe.org/3.1/class-Object.html#_create
I have a report which uses a custom assembly for purposes of localization/globalization.
I am creating my translation object (I'll call it "dictionary") and initializing a Dictionary property of this object in the custom code OnInit() override.
Everything works fine in report body, but when I try to reference the object I describe above in either the Report Header or Report Footer- it is not accessible (object ref is not set to instance of obj error..).
Can anyone either tell me why this is or how I might be able to workaround it? I really don't want to have to re-initialize this localization object separately for the Header and Footer. I was under the impression custom code class instances were accessible anywhere within the report definition.
Thanks in advance for any light anyone can shed on this.
I am not sure of your implementation, but the recommendation is to use static methods rather than instances. Understood that this is not always the best case for each design, but in your case, it sounds like you could use a static method and then in that case, when called from your header and footer, the custom assembly static method will initialize all data. It will be easier that putting the implementation or instance creation in the RDL.
This appears to just be by design. A custom class instance is not accessible to the Report Header or Footer. My solution was to simply add a check to the custom code function which the report expressions call (psuedo-code):
If IsNothing(myCustObj)
{
///initialize myCustObj
}
That seems to be the best workaround.
I have a WPF project. When I add a class and a method, and write "this.", I get no intellisense. There is a message in the bottom tab of Visual Studio that an identifier is expected, but that doesn't make sense.
Furthermore, I can't access some methods/objects. Take the following example:
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
When I try to access the variable, no intellisense comes up (get the same message about an identifier).
Does anyone know why this? To make things worse, I have this problem too: http://social.msdn.microsoft.com/Forums/en-US/vswpfdesigner/thread/701934bc-5237-40df-aa54-f768debf4e59
Thanks
Is your class or method static? If so, you won't be able to call any instance members or properties using the "this" keyword. If you want to use members or properties in static methods, they have to be static too.
In my experience Intellisense fails often when the code for the class that you are writing does not compile. So, the cause might be a syntax error in a different line of code or an absent project reference, or using statement.
I cannot help you with the error link you gave. As this sure means that WPF form does not compile, it follows that Intellisense does not work.
Have you tried to restart Visual Studio, I have seen issues with its intellisense like that. If you just go ahead and use the instance, does it compile, if so probably just have to restart the application.
Using "this" if the class is static, the this identifier will not work.
I just typed your exact code in my instance of VS2008 and I got intellisense.