In normal C# programming without designer.cs (UI), shall we use partial class? How shall we use it in this case? - partial-classes

I know the way to write a partial class in C# but i do not know when to use it.
e.g. If i am not developing using Windows Form or UI in C#, how shall i start design my class?
Java: Class
C#: Partial Class, Class
As above in C#, how shall we choose to use partial class and normal class ( assume no UI element in the application) .

Related

wrap a noninheritable class in vb.net

I would like to use a class Cookie in my namespace for convenience, with the same capabilities as System.Web.Cookie, or better be equivalent. I can't derive from System.Web.Cookie because it is noninheritable...
In C, i could simply typedef it to another type, but I don't see any possibility in VB.net other than write a wrapper class that mimics all functions.
Is there another way to "rename" a type in VB.net (Framework 4.0)?
Edit:
I found a solution, to import the class under a different name:
imports Cookie = System.Web.HttpCookie
But I would still be interested in other solutions.
Therefore I didn't add this as answer.

Better to add method to pre-defined class or make subclass?

Say you want to add a lengthOfFirstLine method to the predefined File class. Is it a better practice to modify the existing class, or make a new class that extends the File class with your new method?
EDIT -- Specifically, the situation is that a class is lacking one method in particular. I don't want to completely change the class, but rather augment it with that method.
It depends if the method is applicable to all elements of the class File. For instance, lengthOfFirstLine doesn't apply to binary files, so probably it doesn't belong in a generic File class, but if your class only represent text files, then it should go there.
For .NET languages, there's also the option of using extension methods. This way you don't have to "dirty up" a class by adding helper/utility methods to it, and no inheritance is required as well - you add functionality to a class by simply adding a using statement to your code.
Agree with Luis and Lester. If you are using .Net the extension methods are the way to go for this sort of functionality. But you should try not add LengthOfFirstLine to a base class if you can open all sorts of files such as binary files. You would sub class it to a FileClass and add the method to that.
Remember that the extension methods in .Net are syntactic sugar anyway. You can simulate it in your own language using Static classes and methods. This is what .Net does under the covers anyway.
For example have a static FileHelpers class and have various static helper methods on it. The first parameter for each of these static methods would be the File class. So you could call this using FileHelpers.GetLengthOfFirstLine(myOpenedFile)

Type of Class in C++/CLI

I am working on C++/CLI Wrapper for C Static Library.Static Library has 10 function in it.
THis C++/CLI Wrapper will Expose 10 API to C# Application.The Wrapper Will be in the Form of dll.
The Wrapper Will be Used in C# Application.
Now I am trying to add a class in C++/CLi application which will expose function to C# application I am getting Many Option like
C++ Class
CLR Class
a. Component Class
b.Installer Class
c. Windows Form
d. Installer Class
I am bit confused which I need to select out of it as I am new bee in C++/CLI
You need a
CLR Class - Component
since it can be consumed by .NET clients.
CLR class is declared as follows
ref class Wrapper {....}
However in your scenario you could also write a dynamic library and pinvoke the methods from .NET client.
Not sure if your question has been entirely answered, but a Component class creates a class that implements an IComponent interface for remoting/ inter process communication purposes. Didn't seem like what you were looking for.
I think what you were looking for i just a "template" to create a managed class?
In that case all you need to do is select C++ in the wizard and make sure the "Managed" check box on the right hand side is selected.

BlazeDS - Conversion from ArrayList <BaseClass> on java side to Actionscript

So we have a java class with two ArrayLists of generics. It looks like
public class Blah
{
public ArrayList<ConcreteClass> a;
public ArrayList<BaseClass> b;
}
by using [ArrayElementType('ConcreteClass')] in the actionscript class, we are able to get all the "a"s converted fine. However with "b", since the actual class coming across the line is a heterogeneous mix of classes like BaseClassImplementation1, BaseClassImplementation2 etc, it gets typed as an object. Is there a way to convert it to the specific concrete class assuming that a strongly typed AS version of the java class exists on the client side
thanks for your help!
Regis
To ensure that all of your DTO classes are marshalled across AS and Java, you need to define each remote class as a "remote class" in AS by using the "RemoteClass" attribute pointing to the java class definition like this [RemoteClass(alias="com.myco.class")].
BlazeDS will perform introspection on the class as it is being serialized/de-serialized and convert it appropriately (see doc below). It doesn't matter how the classes are packed or nested in an array, as long as it can be introspected it should work.
If you need special serialization for a class you can create your own serialization proxys (called beanproxy) by extending "AbastractProxy" and loading them into blazeds using the PropertyProxyRegistry register method on startup.
You will find most of this in the Blaze developers guide http://livedocs.adobe.com/blazeds/1/blazeds_devguide/.
Creating your own beanproxy class look here: //livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/io/BeanProxy.html

VB.NET Creating Classes, What is Public Class MyClass(Of Type)?

I'm still learning ASP.NET and I often see code like this throughout parts of our framework:
Public MustInherit Class DBFileManager(Of F As IDBFile, FC As IDBFileContent, FT As IDBFileThumb)
Can anybody tell me what this means? Much thanks!
Its a generic. That means a DBFileManager can be created that acts on 3 classes that implement the 3 named Interfaces
see http://msdn.microsoft.com/en-us/library/w256ka79(VS.80).aspx for more information
To build on what #Jimmy said: It is also an Abstract Class, which means it acts as a base class - you can't use it directly, you must sub class it to use. That subclass must implement the 3 types in the class header.