Do you have your own utils dll and what do you keep there?

I can start with my own .NET DLL. I have a dll that I use in all of my web projects (about 10) and I have classes for FTP, zip, imageresizing, extensionmethods and a common singleton class.

I think this is common practice, and I just thought it would be interesting to hear people put Utils files into their DLLs

EDIT: What are your little stones that made you much more productive with less code?

These extension methods are pretty useful for me when parsing form input using NULL before being put into the database

public static int? ToInt(this string input) { int val; if (int.TryParse(input, out val)) return val; return null; } public static DateTime? ToDate(this string input) { DateTime val; if (DateTime.TryParse(input, out val)) return val; return null; } public static decimal? ToDecimal(this string input) { decimal val; if (decimal.TryParse(input, out val)) return val; return null; } 
+3
source share
5 answers

I think that moving assembly assemblies beyond the current version of your language does more harm than good.

The main reason is that as new methods appear in the language, more efficient ways of doing things are built in. By assembling the utilities, you will quickly get a lot of dead weight, which can cause security problems.

An example is the list of functions. A quick glance will show that .Net (like most other languages) already covers at least 75% of this code.

+7
source

I have been going for years. It began as a set of VBScript routines , which has since been converted to VB6. This is a COM library, so I can use it almost anywhere in almost any language. I saved you from the boredom of all the listings.

EDIT: I basically agree with Chris Lively's comment on a previous post in this section. However, as I said in the comments, if the work I'm doing is related to .NET, I will of course throw my stuff at what I think is the best breed. However, in my case, .NET is decompiling too easily (which makes it a kind of ersatz open source), and my employer wants to protect their intellectual property.

 (Autogenerated by TLViewer, © Mark Pryor 2000-2003) Library: Std P:\other\StdLib\StdLib.dll Description: Std coclass Drives Function DriveType(ByVal sDrv As String) As String coclass Arrays Function AAdd(aToThis ,ByVal xAddThis ) As Integer Function AAdd_PostIncrement(a , ByVal X ) As Variant Function AAdd_PreIncrement(a , ByVal X ) As Variant Function AMax(aVec ) As Variant Function AMin(aVec ) As Variant Sub DeleteFirst(anArray ) Sub DeleteLast(anArray ) Sub DeleteNth(anArray , ByVal nElement As Long) Function GenerateRange(nBot As Double, nTop As Double, [nStep As Double = 1]) As Variant Function GenerateRangeFromString(sRange ) As Variant Function InArray(sItem , aList ) As Boolean Function Reverse1DArray(aInput ) As Variant Function ShowStructure(vToShow ) As String Function StrInArray(sItem , aList , [bCaseInsens As Boolean = True]) As String coclass CmdLine Property AppExeName([BaseOnly As Boolean = False]) As String [Get/o] Property AppPath As String [Get/o] Property Argument(ByVal Which As Long) As String [Get/o] Property Arguments As Long [Get/o] Property CaseSensitive As Boolean [Get/Let] Function FlaggedArg(ByVal Flag As String) As String Function FlagPresent(ByVal Flag As String) As Long Function FlagPresentFromList(Flags () As Variant) As Boolean Sub Refresh() Function ToString() As String coclass BigString Sub ClearStr() Function GetStr([ByVal vJoiner = ]) As String Function GetStrArray() As Variant Sub PutStr(ByVal vString ) coclass Config Sub Define(sKey , sValue ) Property gsFilename As String [Get/Let] Function List(sFilter ) As String Function Load(sFile ) As Boolean Function LoadW(sFile ) As Boolean Function Recall(sKey ) As Variant Function RecallElse(sKey , sDefault ) As Variant Sub Save([sFile = ], [bAsAnsi = False]) Sub SaveW([sFile = ], [bAsAnsi = False]) coclass Collections Function Add(vData , [sKey ]) As _Variable Property AddOnly As Boolean [Get/Let] Function Count() As Long Function Exists(vntIndexKey ) As Boolean Property Item(vntIndexKey ) As _Variable [Get/o] Function Items() As Variant Function Keys() As Variant Sub Modify(sValue , sKey ) Property NewEnum As stdole.IUnknown [Get/o] Sub Remove(vntIndexKey ) coclass Computers Function ComputerName() As String Function ExistsFolder(sComputer As String, sDir As String) As Boolean Function GetComputers(sDomain As String)() As Variant Function GetDomainComputers(ByVal strDomain As String)() As Variant Function GetNBT(sComputer As String) As String Function GetNBTA(sIPAddr As String) As String Function GetNetView(sDomain As String) As String Function GetOnlineComputers(sDomain As String)() As Variant Function GetRemoteEnvironment(sComputer )() As Variant Function GetSpecs(sComputer As String) As String Function GetTheComputerName() As String Function ResolveIP(sName As String) As String coclass Logic Function IIF(bCondition As Boolean, vTrue , vFalse ) As Variant coclass Decimals Property Dec As Variant [Get/Let] coclass Domains Function GetAvailableNTDomains()() As Variant coclass Database Sub CreateDatabase(sFile As String) Sub CreateIndex(ByVal oDb As ADODB.Connection, sSpec As String) Sub CreateStructure(ByVal oDb As ADODB.Connection, sSpec As String) Function OpenDatabase(theFile As String) As ADODB._Connection Function OpenRecordSet(ByVal oDb As ADODB.Connection, sQuery As String) As ADODB._Recordset coclass DateTime Function dbDate(vDate ) As String Function GetGmtTime([StartingDate ]) As Date Function GetTimeDifference() As Long Function GetTimeHere(gmtTime As Date) As Date Function InternetTimeToVbLocalTime(ByVal DateString As String) As Date coclass Wallpaper Function ActiveDesktopSetWallpaper(ByVal strFile As String) As Boolean Sub At(ByVal nX As Integer, ByVal nY As Integer) Sub AtSay(ByVal nX As Integer, ByVal nY As Integer, ByVal sText As String) Sub Attributes(ByVal sAttribList As String) Sub Colour(ByVal iFGColour As Long, ByVal iBGColour As Long) Sub Dimensions(ByVal nHeight As Integer, ByVal nWidth As Integer) Sub Font(ByVal sName As String, ByVal iSize As Integer) Function LoadPic(sFilename As String, [nDestX As Integer = ], [nDestY As Integer = ]) As Variant Property Picture As Object [Get/Set] Sub SavePic(sFilename As String, [iType As Integer = 1]) Sub Say(ByVal sText As String) Sub ScaleMode(ByVal iMode As Integer) Function TextHeight(ByVal sText As String) As Integer Function TextWidth(ByVal sText As String) As Integer coclass Excel Sub ExcelColumnNames(aHeadings () As Variant, [bBold As Boolean = True]) Sub ExcelNewSheet() Sub ExcelStart([bHidden As Boolean = False]) coclass StopWatch Sub Finish() Function FinishTime() As Date Function LapTime() As String Function Seconds() As Integer Sub Start() Function StartTime() As Date coclass Environments Function GetProcessEnv(strEnvVar As String) As String Function GetSystemEnv(strEnvVar As String) As String Function GetUserEnv(strEnvVar As String) As String Function GetVolatileEnv(strEnvVar As String) As String coclass Schedule Function AddTask(strTime , strCommand , [enDaysInWeek As ENUM_WEEKDAYS = ], [strDaysInMonth = ], [RunInteractive As Boolean = True], [ReOccuring As Boolean = True]) As Long Function DeleteTask(lngID As Long) As Boolean Function GetNameOfComputer() As String coclass SymbolTable Function Append(sName , sValue ) As String Sub Clear() Function Increment(sName ) As Integer Function IsSym(sName ) As Boolean Function Keys()() As Variant Sub Parse(sData , sSep ) Function Recall(sName ) As Variant Sub Remove(sData ) Sub Store(sName , vValue ) Sub StoreDup(sName , xValue ) Sub StoreDup2(sName , xValue ) Function SymList() As Variant Function SymListText() As String coclass Files Function CollectFiles(sDirectory , sFileType ) As Variant Sub DeleteFile(ByVal cFilename ) Function Exists(sFile ) As Boolean Function FileHasBeenModified(sFile As String, dThen As Date) As Boolean Function FileModificationDate(sFile As String) As Date Function IsUTF16LE(sFile As String) As Boolean Function RandomInputFile(sExt As String) As String Function RandomOutputFile(sRandomInputFile As String, sExt As String) As String Function ReadFileA(FileName ) As String Function ReadFileE(FileName ) As String Function ReadFileU(FileName ) As String Function ReadFirstLineA(FileName ) As Variant Function ReadFirstLineE(FileName ) As String Function ReadFirstLineU(FileName ) As String Sub WriteFileA(sFilename , sContents , nMode As Long) Sub WriteFileB(sFilename , nOffset As Long, vData ) Sub WriteFileU(sFilename , sContents , nMode As Long) coclass System Function AvailableDesktopDimensions() As Variant Function CaptureDOS(sCommand , [bSynch As Boolean = True]) As Variant Function ConsoleWrite(sText As String) As Long Function ConsoleWriteLine(sText As String) As Long Function CreateGUID() As String Function DesktopDimensions() As Variant Function DoEventsSeconds(nSeconds As Integer) As Integer Sub DoEventsSeconds2(iSeconds As Integer) Function GetTheWindowsDirectory() As String Function GetUUID(sUuid As String) As Boolean Function KillProcess(ProcessName As String) As Boolean Sub Navigate(ByVal NavTo As String) Function SetProcessPriority(sProcess As String, nPriority As EPROCESS_PRIORITY ) As Boolean Function ShellEx(ByVal sFile As String, [eShowCmd As EShellShowConstants = essSW_SHOWDEFAULT], [ByVal sParameters As String = ], [ByVal sDefaultDir As String = ], [sOperation As String = "open"], [Owner As Long = ]) As Boolean Sub Sleep(nMilli As Integer) Function SystemDefaultUILanguage() As Long Function ThreadLocale() As Long coclass Groups Function GetComputerGroups(ByVal strComputerName As String)() As Variant Function GetDefaultNamingContext() As String Function GetGroups()() As Variant coclass Help Function HHDisplayHeadTopic(ByVal lHwnd As Long) As Long Function HHDisplaySearch(ByVal lHwnd As Long, [toSearch As String = ]) As Long Function HHHelpContents(ByVal lHwnd As Long) As Long Function HHHelpIndex(ByVal lHwnd As Long, [toSearch As String = ]) As Long Sub HHInitialize() Function HHKeywordLookup(ByVal lHwnd As Long, [sKeyword As String = ]) As Long Sub HHUninitialize() Property sHelpFile As String [Get/Let] coclass Number Function IntegerToUnsigned(Value As Integer) As Long Function LongToUnsigned(Value As Long) As Double Function UnsignedToInteger(Value As Long) As Integer Function UnsignedToLong(Value As Double) As Long coclass IEDisplay Sub Display(sMsg As String, nMillisec As Integer) Sub Init(sPosition ) Property sName As String [Get/Let] coclass Temp Function GetTempFileName([sSeed As String = ]) As String Function LocGetFilePath(ByVal iCFName As String) As String Function TempDir() As String Function TempDirWide() As String Function TempFile(Create As Boolean, [lpPrefixString ], [lpszPath ]) As String Function UnicodeTempFile(ByVal iFileName As String) As String coclass INI Sub Clear() Function GetValue(sSection As String, sKey As String, strDefault As String) As String Function HasSection(sSection As String) As Boolean Function Load(sIniName As String) As Boolean Function ReadINIA(sSection , sKeyName , sINIFileName ) As String Function ReadINIU(sSection As String, sKeyName As String, sINIFileName As String) As String Function WriteINIA(sSection , sKeyName , sNewString , sINIFileName ) As Boolean Function WriteINIU(sSection As String, sKeyName As String, sNewString As String, sINIFileName As String) As Boolean coclass Variable Property Name As Variant [Get/Let/Set] Property Value As Variant [Get/Let/Set] coclass Mouse Function Between(ByVal nNumber As Integer, ByVal nLowerBound As Integer, ByVal nUpperBound As Integer) As Boolean Function MouseX([ByVal hWnd As Long = ]) As Long Function MouseY([ByVal hWnd As Long = ]) As Long coclass Traces Sub ClearTrace() Sub Trace([ByVal sTag = " !@ #$%^&*()_"]) Property TraceFile As String [Get/Let] Property Tracing As Boolean [Get/Let] coclass Registry Property ClassKey As ERegistryClassConstants [Get/Let] Sub CreateAdditionalEXEAssociations(ByVal sClassName As String, vItems () As Variant) Sub CreateEXEAssociation(ByVal sExePath As String, ByVal sClassName As String, ByVal sClassDescription As String, ByVal sAssociation As String, [ByVal sOpenMenuText As String = "&Open"], [ByVal bSupportPrint As Boolean = False], [ByVal sPrintMenuText As String = "&Print"], [ByVal bSupportNew As Boolean = False], [ByVal sNewMenuText As String = "&New"], [ByVal bSupportInstall As Boolean = False], [ByVal sInstallMenuText As String = ], [ByVal lDefaultIconIndex As Long = -1]) Function CreateKey() As Boolean Property Default As Variant [Get/Let] Function DeleteKey() As Boolean Function DeleteValue() As Boolean Function EnumerateSections(sSect () As String, iSectCount As Long) As Boolean Function EnumerateValues(sKeyNames () As String, iKeyCount As Long) As Boolean Property KeyExists As Boolean [Get/o] Property Machine As String [Get/Let] Property SectionKey As String [Get/Let] Property Value As Variant [Get/Let] Property ValueEx(ClassKey As ERegistryClassConstants , SectionKey As String, ValueKey As String, ValueType As ERegistryValueTypes , Default ) As Variant [Get/Let] Property ValueKey As String [Get/Let] Property ValueType As ERegistryValueTypes [Get/Let] coclass Users Function GetComputerUsers(ByVal strComputerName As String)() As Variant Function GetComputerUsers2(ByVal strComputerName )() As Variant Function GetDomainUser(sComputer As String) As String Function GetLoginProfiles(sComputer )() As Variant Function GetMac(sDevice ) As String Function GetNameAndDescription(spDomain As String, sUsername As String) As String Function GetOUofUser(sDomain As String, sUsername As String) As String coclass Sort Sub heapsort(aVec ) Sub quicksort(aVec ) Sub shellsort(a0 , [bAscending As Boolean = True]) Sub shellSortOnField(aVec , ByVal nField As Integer, ByVal sFieldSep , [nComparisonType As SSOF_COMPARISON = SSOF_NUMERICAL]) Function sorted()() As Variant coclass Strings Function AnyOf(sText , nOperator As AO_COMPARATORS , sChar ) As Boolean Function AnyOfList(sText , nOperator As AO_COMPARATORS , aChar ) As Boolean Function AsString(X ) As String Function BeginsWith(sText , sBeginning , [bCaseInsensitive As Boolean = True]) As Boolean Function Between(sText , sBegin , sEnd ) As String Function ByteArrayToString(aBytes () As Byte) As String Function ComprehendCSV(sText ) As Variant Function Contains(sText , sChunk , [bCaseInsensitive As Boolean = True]) As Boolean Function CountFields(strText , strDelim ) As Integer Function DQ(s ) As String Function EndsWith(sText , sEnding , [bCaseInsensitive As Boolean = True]) As Boolean Function EndsWithSet(sText , vEnding , [bCaseInsensitive As Boolean = True]) As Boolean Function FirstLineOf(sData ) As String Function FirstWord(sText ) As String Function ForceExtension(sFilename , sExtension ) As String Function HexDump(sData ) As String Function HTMLWrap(sTag , sContent ) As String Function LastLineOf(sData ) As String Function LeftFill(sText , nLen , sFill ) As String Function LeftOf(sText , sItem ) As String Function LeftOfLast(sText , sItem ) As String Function NthField(sText , sDelimiter , nReqdField ) As String Function NthLineOf(n As Integer, sData ) As String Function RemoveSpaces(sText ) As String Function Reverse(sText ) As String Function RightFill(sText , nLen , sFill ) As String Function RightOf(sText , sItem ) As String Function RightOfLast(sText , sItem ) As String Function SplitSet(ByVal sString , ByVal sSet ) As Variant Function StringConversion(s , n As Integer) As String Function StringMap(sText , aFrom , vTo ) As String Function StringToByteArray(ByVal sString )() As Byte Function Subst(sText , paArgList () As Variant) As String Function Subst2(sText , paArgList () As Variant) As String Function ZeroFill(nNum , nWidth ) As String Function Zerofill2(nNum ) As String 
+1
source

I just started working, but at the moment it contains only the general extension methods that I use all the time. Things like "ThrowIfNull ()", so I don't need to do heaps of if statements every time I want to check for zeros.

I also have a project for a playground in which there are only ideas that I play with, but I'm not 100% sure that they will even work.

0
source

I group my utilities by functionality. As a result, I don’t have one DLL utility, but rather a folder containing several such assemblies, each of which encapsulates one task (which usually includes not only one class, in fact it usually includes a whole hierarchy).

As a last resort, this means that I have a DLL containing one declaration, namely the following (plus documentation):

 namespace madrat.Common { public interface ICopyable<T> { T Copy(); } } 

Note that unlike the System.ICloneable interface, it has the well-defined semantics (deep copy) specified in the documentation.

So why do we need an extra dll for this tiny declaration? Because it facilitates the interaction between other assemblies.

0
source

Here are two classes from my personal library. It makes things a lot better :)

 public class DynamicArray<Type> { private Type[] internalArray; public DynamicArray() { internalArray = new Type[0]; } public int Length { get { return internalArray.Length; } set { if (value >= 0) Array.Resize<Type>(ref internalArray, value); else throw new ArgumentOutOfRangeException ("Length can not be less than zero!"); } } public Type[] AsNormalArray { get { return internalArray; } set { internalArray = value; } } public Type this[int index] { get { if (index >= 0 && index < internalArray.Length) return internalArray[index]; else throw new IndexOutOfRangeException ("Index was outside the bounds of the array!"); } set { //Get error handling out of the way first if (index < 0) throw new IndexOutOfRangeException ("Index must be greater than or equal to zero!"); //I decided that being able to grow by any amount can eventually lead //to lots of bugs, think about it. Just set the length manually //by assigning to .Length :) if (index > internalArray.Length) throw new IndexOutOfRangeException ("Can not dynamically grow more than one element at a time! Set length manually."); //We are left with two possibilities. A. we are indexing an existing element or //B. we are indexing one element to high (same as length, big array no no) //so grow an element if (index < internalArray.Length)//Then we dont need to grow an element { internalArray[index] = value; } else//Then grow one element, and add the value { Array.Resize<Type>(ref internalArray, internalArray.Length + 1); internalArray[index] = value; } } } public void Add(params Type[] values) { int start = internalArray.Length; //Start adding values at the end this.Length += values.Length; //Pre-set length (faster) foreach (Type val in values) { //this[start++] = val; Possibly slower internalArray[start++] = val; } } public int IndexOf(Type thisValue) { int i = 0; bool found = false; for(; i <= internalArray.Length; i++) { if(internalArray[i].Equals(thisValue)) { found = true; break; } } if(found) return i; else throw new ArgumentException (thisValue+" does not exist!"); } public bool Contains(Type thisValue) { bool found = false; foreach (Type val in internalArray) { if (val.Equals(thisValue)) { found = true; break; } } return found; } } public class AssosiativeArray<ArrayT, KeyT> { //Easy peasy lemon squeezy private DynamicArray<ArrayT> values; private DynamicArray<KeyT> keys; public AssosiativeArray() { values = new DynamicArray<ArrayT>(); keys = new DynamicArray<KeyT>(); } public int Length { get { return values.Length; } } public ArrayT[] ValuesAsNormalArray { get { return values.AsNormalArray; } } public KeyT[] KeysAsNormalArray { get { return keys.AsNormalArray; } } public ArrayT this[KeyT index] { get { if (keys.Contains(index)) { return values[keys.IndexOf(index)]; } else { throw new ArgumentException ("The key "+index+" does not exist!"); } } set { keys[keys.Length++] = index; values[values.Length++] = value; } } public bool ContainsKey(KeyT key) { bool found = false; foreach (KeyT val in keys.AsNormalArray) { if (val.Equals(key)) { found = true; break; } } return found; } } 

}

0
source

All Articles