c# Programming Glossary: throw
Simple 2 way encryption for C# http://stackoverflow.com/questions/165808/simple-2-way-encryption-for-c-sharp . public byte StrToByteArray string str if str.Length 0 throw new Exception Invalid string value in StrToByteArray byte val..
Encrypt/Decrypt string in .NET http://stackoverflow.com/questions/202011/encrypt-decrypt-string-in-net string sharedSecret if string.IsNullOrEmpty plainText throw new ArgumentNullException plainText if string.IsNullOrEmpty.. plainText if string.IsNullOrEmpty sharedSecret throw new ArgumentNullException sharedSecret string outStr null Encrypted.. string sharedSecret if string.IsNullOrEmpty cipherText throw new ArgumentNullException cipherText if string.IsNullOrEmpty..
Dependency Inject (DI) “friendly” library http://stackoverflow.com/questions/2045904/dependency-inject-di-friendly-library dep public Service ISomeDependency dep if dep null throw new ArgumentNullException dep this.dep dep public ISomeDependency..
Deserialize JSON into C# dynamic object? http://stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object type JavaScriptSerializer serializer if dictionary null throw new ArgumentNullException dictionary return type typeof object.. Serialize object obj JavaScriptSerializer serializer throw new NotImplementedException public override IEnumerable Type.. IDictionary string object dictionary if dictionary null throw new ArgumentNullException dictionary _dictionary dictionary..
Casting vs using the 'as' keyword in the CLR http://stackoverflow.com/questions/496096/casting-vs-using-the-as-keyword-in-the-clr there's a bug then casting is the right solution. That throws an exception immediately which means that no more work is done.. the exception correctly shows the type of bug. This will throw an exception if randomObject is non null and refers to an object..
What is the best workaround for the WCF client `using` block issue? http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue when Dispose is called the client's Close method fires but throws an error because it's in a faulted state. The original exception.. e ... client.Abort catch Exception e ... client.Abort throw Compared to the using block I think that's ugly. And a lot of..
Retrieving Property name from lambda expression http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression lambda method as LambdaExpression if lambda null throw new ArgumentNullException method MemberExpression memberExpr.. lambda.Body as MemberExpression if memberExpr null throw new ArgumentException method return memberExpr c# linq lambda.. return the PropertyInfo object for the expression. It throws an exception if the expression is not a property. public PropertyInfo..
Deep cloning objects in C# http://stackoverflow.com/questions/78536/deep-cloning-objects-in-c-sharp static T Clone T T source if typeof T .IsSerializable throw new ArgumentException The type must be serializable. source..
Is there a way to check if a file is in use? http://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use the file before it's been saved back to the filesystem and throw an error File in use by another process . I would like to find..
guid to base64, for URL http://stackoverflow.com/questions/1032376/guid-to-base64-for-url Guid Convert.FromBase64String base64 Catch ex As Exception Throw New Exception Bad Base64 conversion to GUID ex End Try Return..
How do I access ARP-protocol information through .NET? http://stackoverflow.com/questions/1148778/how-do-i-access-arp-protocol-information-through-net insufficient buffer. if result ERROR_INSUFFICIENT_BUFFER Throw an exception. throw new Win32Exception result Allocate the.. is not 0 no error then throw an exception. if result 0 Throw an exception. throw new Win32Exception result Now we have..
In C#, sign an xml with a x.509 certificate and check the signature http://stackoverflow.com/questions/1195728/in-c-sign-an-xml-with-a-x-509-certificate-and-check-the-signature XmlNodeList nodeList Doc.GetElementsByTagName Signature Throw an exception if no signature was found. if nodeList.Count 0.. only supports one signature for the entire XML document. Throw an exception if more than one signature was found. if nodeList.Count..
C# Object Pooling Pattern implementation http://stackoverflow.com/questions/2510975/c-sharp-object-pooling-pattern-implementation error checking the pool itself restricts access to them. Throw in an enumeration and a factory method and we're done with this..
How to write Asynchronous LINQ query? http://stackoverflow.com/questions/252355/how-to-write-asynchronous-linq-query of how dynamic could be used. Some may call it abuse. Throw this in your utilities library public static class AsynchronousQueryExecutor..
ASP.NET How to get List of Groups in Active Directory http://stackoverflow.com/questions/323536/asp-net-how-to-get-list-of-groups-in-active-directory strPath objADAM.RefreshCache Catch e As Exception Throw e End Try ' Get search object specify filter and scope ' perform.. objSearchADAM.FindAll Catch e As Exception Throw e End Try ' Enumerate groups Try If objSearchResults.Count 0.. result.Add objGroupEntry.Name Next objResult Else Throw New Exception No groups found End If Catch e As Exception Throw..
How do I generate a Friendly URL in C#? http://stackoverflow.com/questions/37809/how-do-i-generate-a-friendly-url-in-c an empty string something went seriously wrong anyway. Throw an error or don't react at all. remove any leading or trailing..
Signing SOAP messages using X.509 certificate from WCF service to Java webservice http://stackoverflow.com/questions/4666970/signing-soap-messages-using-x-509-certificate-from-wcf-service-to-java-webservic X509FindType.FindBySubjectName CertificateSubject false 0 Throw an exception of the certificate was not found. if cert null..
What can you do in MSIL that you cannot do in C# or VB.NET? [closed] http://stackoverflow.com/questions/541936/what-can-you-do-in-msil-that-you-cannot-do-in-c-sharp-or-vb-net pointers 17. emitbyte directive in MethodBodyItem 18. Throw and catch non System.Exception types 19. Inherit Enums Unverified..
In C#, how can I rethrow InnerException without losing stack trace? http://stackoverflow.com/questions/57383/in-c-how-can-i-rethrow-innerexception-without-losing-stack-trace destroys the stack trace. Example code public void test1 Throw an exception for testing purposes throw new ArgumentException.. mi.Invoke this null catch TargetInvocationException tiex Throw the new exception throw tiex.InnerException c# .net exception.. ex ExceptionDispatchInfo.Capture ex.InnerException .Throw This works on any exception not just AggregateException . It..
Why doesn't C# have support for first pass exception filtering? http://stackoverflow.com/questions/602066/why-doesnt-c-sharp-have-support-for-first-pass-exception-filtering especially if we're talking about calls into native code. Throw another exception adding to the general confusion and misery...
Why does casting int to invalid enum value NOT throw exception? http://stackoverflow.com/questions/6413804/why-does-casting-int-to-invalid-enum-value-not-throw-exception when the type is statically invoked. static EnumUtil Throw Exception on static initialization if the given type isn't an.. same time. Cast the given value as the given enum type. Throw an exception if the value is not defined for the given enum..
Beats per minute from real-time audio input http://stackoverflow.com/questions/79445/beats-per-minute-from-real-time-audio-input out imag You will get a real part and an imaginary part. Throw away the imaginary part. It is the phase and you do not need..
|