﻿<?xml version="1.0" encoding="utf-8"?><Type Name="ProvideTryParseAlternativeRule" FullName="Gendarme.Rules.Design.ProvideTryParseAlternativeRule"><TypeSignature Language="C#" Value="public class ProvideTryParseAlternativeRule : Gendarme.Framework.Rule, Gendarme.Framework.ITypeRule" /><TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit ProvideTryParseAlternativeRule extends Gendarme.Framework.Rule implements class Gendarme.Framework.IRule, class Gendarme.Framework.ITypeRule" /><AssemblyInfo><AssemblyName>Gendarme.Rules.Design</AssemblyName><AssemblyVersion>3.10.0.0</AssemblyVersion></AssemblyInfo><Base><BaseTypeName>Gendarme.Framework.Rule</BaseTypeName></Base><Interfaces><Interface><InterfaceName>Gendarme.Framework.ITypeRule</InterfaceName></Interface></Interfaces><Attributes><Attribute><AttributeName>Gendarme.Framework.Problem("This type provides a Parse(System.String) method without an, exception-less, TryParse alternative.")</AttributeName></Attribute><Attribute><AttributeName>Gendarme.Framework.Solution("Add a TryParse alternative method that allow parsing without any exception handling from the caller.")</AttributeName></Attribute></Attributes><Docs><summary>
            This rule will warn on any type that provide <c>Parse(string...)</c>
            method(s) without supplying <c>TryParse</c> alternative method(s).
            Using a <c>TryParse</c> method is easier since it is less-error prone
            (no need to handle all possible exceptions) and remove the performance
            issue regarding throwing/catching exceptions.
            </summary><remarks>This rule is available since Gendarme 2.8</remarks><example>
            Bad example:
            <code>
            public struct Int32Tuple {
            	private int first;
            	private int second;
            	public Int32Tuple (int a, int b)
            	{
            		first = a;
            		second = b;
            	}
            	// documented to throw only Argument[Null]Exception or FormatException
            	static Int32Tuple Parse (string s)
            	{
            		if (s == null) {
            			throw new ArgumentNullException ("s");
            		} else if (s.Length == 0) {
            			throw new ArgumentException ("s");
            		} else {
            			string [] items = s.Split (':');
            			// without the try/catch it would be much harder to
            			// be 100% certain of all possible exceptions - like
            			// IndexOfOfRangeException and what Int32.Parse can throw
            			try {
            				int a = Int32.Parse (items [0]);
            				int b = Int32.Parse (items [1]);
            				return new Int32Tuple (a, b);
            			}
            			catch (Exception e) {
            				throw new FormatException ("Invalid data", e);
            			}
            		}
            	}
            }
            </code></example><example>
            Good example:
            <code>
            public struct Int32Tuple {
            	private int first;
            	private int second;
            	public Int32Tuple (int a, int b)
            	{
            		first = a;
            		second = b;
            	}
            	// documented to throw only Argument[Null]Exception or FormatException
            	static Int32Tuple Parse (string s)
            	{
            		if (s == null) {
            			throw new ArgumentNullException ("s");
            		} else if (s.Length == 0) {
            			throw new ArgumentException ("s");
            		} else {
            			// re-implemented using the exception-less TryParse
            			Int32Tuple tuple;
            			if (!TryParse (s, out tuple))
            				throw new FormatException ("Invalid data");
            			return tuple;
            		}
            	}
            	static bool TryParse (string s, out Int32Tuple tuple)
            	{
            		tuple = new Int32Tuple ();
            		if (String.IsNullOrEmpty (s))
            			return false;
            		string [] items = s.Split (':');
            		if (items.Length != 2)
            			return false;
            		int a;
            		if (!Int32.TryParse (s, out a))
            			return false;
            		int b;
            		if (!Int32.TryParse (s, out b))
            			return false;
            		tuple.first = a;
            		tuple.second = b;
            		return true;
            	}
            }
            </code></example></Docs><Members><Member MemberName=".ctor"><MemberSignature Language="C#" Value="public ProvideTryParseAlternativeRule ();" /><MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" /><MemberType>Constructor</MemberType><AssemblyInfo><AssemblyVersion>3.10.0.0</AssemblyVersion></AssemblyInfo><Parameters /><Docs><summary>To be added.</summary><remarks>To be added.</remarks></Docs></Member><Member MemberName="CheckType"><MemberSignature Language="C#" Value="public Gendarme.Framework.RuleResult CheckType (Mono.Cecil.TypeDefinition type);" /><MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance valuetype Gendarme.Framework.RuleResult CheckType(class Mono.Cecil.TypeDefinition type) cil managed" /><MemberType>Method</MemberType><AssemblyInfo><AssemblyVersion>3.10.0.0</AssemblyVersion></AssemblyInfo><ReturnValue><ReturnType>Gendarme.Framework.RuleResult</ReturnType></ReturnValue><Parameters><Parameter Name="type" Type="Mono.Cecil.TypeDefinition" /></Parameters><Docs><param name="type">To be added.</param><summary>To be added.</summary><returns>To be added.</returns><remarks>To be added.</remarks></Docs></Member></Members></Type>