Hi, and sorry for the title, I don't really know what else to call it, so I'll get right to my point.

I've recently decided to use most of my coding time with C# after having tried a few others over the years on and off.

I want to start doing things in a structured fashion and stick to it as I go along after lessons learned in the passed, where I've lost track of what my code is actually doing, etcetera.

I don't know what that structure will be and it probably will not conform to some wide standard as I am lousy at learning them.

I do though, for the time being want to make a sort of base class that all my projects might derive from, or is it inherit from?

For example all my projects hence forth will need a generic logging and settings class, maybe more.

By settings I mean like my projects will have settings for user and application and I'd sonner not write these over and over for each project as I enter into it.

What I'm looking for here, so suggestions, like do I make a dll file I can use in future work or just copy and paste source files each time, if I use a dll do I have both classes in the same library, and things like that.

Thanks for reading.

All suggestions are welcome.

Edited 1 Year Ago by Suzie999

I took a class once where we wrote our own personal heading class for our assignments, it included information such as the developer name, the date the program was run, etc. Information included the following;

First name,
last name,
assignment, //could probably just use a creative naming convention and reflection for this part
Current date,
etc.

Apparenty it has to print everything in a useful format. I am not going to include the java code associated with it, it has my real name associated with it in multiple places, and the instructor made a lot of arbitrary and rediculous coding conventions that quite frankly made the code ugly. We had to code around these rediculous conventions lest we loose points. We even had to cite our textbook in our computer programs, and put the teachers name in the program, and only after we cite the teacher as the "main" useless coder could we put "modified by" and our name. So even though the teacher did absolutely nothing, and was more a hinderance to our getting our coding exercises done, we had to "pretend" that he was the main coder of our assignment. I didn't realize how much I despised him until my rant just now. sorry.

Anyway your name, the program name, and the current date seem the most logical fields for something like this, and if it is a console application you may need a seperate program for a GUI application, or you could just make a ToString for a special class, and print it to a text box or something. Your categorization idea seems like a good one, I may have some time later to port something to C#, with clearer coding conventions.

This is kinda what we did, not exactly what we did, but it should give you some ideas. As far as logging, and having all projects inherit, I am unsure of that. You could have them all inherit from heading I suppose, or make something completely different.

/*Author: overwraith*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Heading {

    class Program {

        static void Main(string[] args) {
            Heading heading = new Heading();

            Console.WriteLine(heading.ToString());

            Console.Write("Press any key to continue... ");
            Console.ReadLine();
        }//end main

    }//end class

    public class Heading {
        private const String firstName = "Joe";
        private const char MI = 'J';//middle initial
        private const String LastName = "Schmoe";

        public String getAssemblyName(){
            return System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
        }//end method

        public override string ToString() {
            StringBuilder str = new StringBuilder();

            //append name info
            str.AppendFormat("Programmer: {0,6} {1}. {2}\n", firstName, MI, LastName);
            str.AppendFormat("Assembly Name: {0,5}\n", this.getAssemblyName());
            str.AppendFormat("Date: {0, 28}", DateTime.Now);

            return str.ToString();
        }//end method

    }//end class

}//end namespace

Probably one of the simplest ways is to design the class the way you want it, then put it into a new project. Now export that project as a template(File-Export Template). Any time you want to make a project that uses that class, that template should show up in the list when you start a new project.

Hi Suzie

If I have read things right you are asking for a good way to reuse some code library you have written right? Eg a logging utility for example.

I can show you a few ways of doing this but have you also considered using nuget with third party code as well? If you don't use nuget I can happily explain what it is an how to use it.

Thanks for the input guys, I'll have a read up on nuget, I thought it was just a mechanism for downloading on using other peoples code.

I like the idea of exporting as a template, if it's what I thing it is, where I start each project and all the stuff is already in it that are consistent throuout all my projects.

I'll have a try of that now.

Thanks again.

Hi Suzie, It's nice that you decided to focus on a language, and it really saves time when you already got a lot done. But "base classes" are just the tip of the iceberg if you really want structured and reusable code.

Just a quick example of why, in my opnion, base classes are not enough: Imagine that you create an base class that adds DataBase and Log functions to all your WebPages. What happens when you need to create a Windows Form, WPF or Console app? Or even a WebService?

So, before the base class, you need to create your libraries or choose open source ones, and I'd even say: you need both.
Then, you can create base classes that implement those libs in a easy to use fashion way, so you need to write even less code into your custom projects.
And you can go even further by creating templates that already use your base class and alrady display the code that you usually customize in your projects.

I don't know the opnion of anybody else on this, but when using Open Source or 3rd party libs I usually create an class to make a "proxy interface" for it, so it's easier to update it if there's a certain revision that needs code ajustment or even if I decide to change the lib for another one later.

Given my opnion, this is basically the current set that I've been building and using for the last couple of years (and also a little things that I need to yet do):

Ale.Exceptions  (default exceptions for the libs)  
Ale.Interfaces  (to keep it organized and avoid cyclic references between dlls)
Ale.SessionControl (user session control)
Ale.UserControl (user management)
Ale.DataBase (DB connections and ModelBase(CRUD))
Ale.SimpleWebService (lib for creating web services)
Ale.Lib (Utilities or Interface for Open Source Projects)
    - Excel (interface to EPPlus)
    - Log (interface for log4net)
    - Cripto
    - TextUtils
    - HtmlUtils
    - SMPTUtils

Ale.Lib.Web (Base classes for web apps)
    - WebPageBase
    - WebMasterPageBase
    - WebControlBase
    - WebConfigUtils
    - FileUpload

And I sure am open to suggetions =)

Comments
Good opinion

Greetings Suzie999!
I think what you meant for the title of this thread was "Class Library (.dll) " :D

Yep, using a .dll is a good way to go, (although I'm not certain how to set your environment to automatically load it for all your projects; but I bet there IS a way ;) ). Now my curiosity is piqued and I will go home and investigate that after my shift. ;)

By the way DaveAmour, I'd also be interested in learning how to use NuGet in this manner. You think you might write and article and post it here (presuming you don't already have one posted on one of the other developer sites)?

Tekkno

Hi TekknoDraykko

I wasn't really suggesting the use of Nuget in the way you think. I was just asking if Suzie used it to load other 3rd party libraries.

However you can use Nuget to load components from your own private repository. This would probably most useful in a corporate environment.

There are articles out there already so no point in me re-inventing the wheel.

This looks like a good article:

https://docs.nuget.org/create/hosting-your-own-nuget-feeds

This article has been dead for over six months. Start a new discussion instead.