public BinaryFormatterFactory(BinaryFormatType formatType, Encoding encoding) { ArgumentAssert.IsDefinedInEnum(typeof(BinaryFormatType), formatType, "formatType"); ArgumentAssert.IsNotNull(encoding, "encoding"); _formatType = formatType; _encoding = encoding; }
public GenDeserializeContext( MethodGenerator generator, PartDefinition part, IExpression instance, IExpression args, IVariable header) : base(generator) { ArgumentAssert.IsNotNull(generator, "generator"); ArgumentAssert.IsNotNull(part, "part"); ArgumentAssert.IsNotNull(instance, "instance"); ArgumentAssert.IsNotNull(args, "args"); ArgumentAssert.IsNotNull(header, "header"); DeserializationArgs = args; Reader = args.Copy().AddMember("Reader"); Instance = instance; Member = part.IsBaseType ? instance .MakeReadOnly() : instance .Copy() .AddMember(part.Member); IsBaseType = part.IsBaseType; Header = header; }
private static object[] GetArguments(XmlNode section) { var nodes = section.SelectNodes("arguments/add"); if (nodes.Count == 0) { return(Array.Empty <object>()); } object[] arguments = new object[nodes.Count]; for (var i = 0; i < nodes.Count; i++) { var value = nodes[i].Attributes["value"].Value; ArgumentAssert.IsNotNull(value, "value"); var type = nodes[i].Attributes["type"].Value; if (string.IsNullOrEmpty(type)) { type = "string"; } object arg = DataUtil.ToValue(value, type); if (arg == null) { throw new InvalidCastException(string.Format(Strings.OnlySupportedTypes, DataUtil.PrimitiveTypes)); } arguments[i] = arg; } return(arguments); }
/// <summary> /// Read requested bytes from response stream. The implementation will block until all requested bytes readed from source stream, or <see cref="TimeoutException"/> will be thrown. /// </summary> /// <param name="buffer">An array of type Byte that is the location in memory to store data read from the NetworkStream.</param> /// <param name="length">Number of bytes to be read from the source stream.</param> /// <exception cref="TimeoutException">Thrown when the time allotted for data read operation has expired.</exception> public override int ReadBytes(byte[] buffer, int length) { ArgumentAssert.IsNotNull(buffer, "buffer"); ArgumentAssert.IsGreaterThan(length, 0, "length"); NetworkReadState state = new NetworkReadState(); state.DataStream = Stream; state.BytesLeft = length; _resetEvent = new ManualResetEvent(false); while (state.BytesLeft > 0) { _resetEvent.Reset(); Stream.BeginRead(buffer, length - state.BytesLeft, state.BytesLeft, ReadDataCallback, state); WaitForNetworkData(); if (state.Exception != null) { throw state.Exception; } } return(length); }
public void IsDefinedInEnumTest() { string argumentName = string.Empty; Type enumType = typeof(DayOfWeek); object value = DayOfWeek.Friday; try { ArgumentAssert.IsDefinedInEnum(enumType, value, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } // incorrect value = 128; try { ArgumentAssert.IsDefinedInEnum(enumType, value, argumentName); Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception."); } catch (InvalidEnumArgumentException) { // test passed } }
public static IEnumerable <PartDefinition> CreateInheritedParts(Type type) { ArgumentAssert.IsNotNull(type, "type"); foreach (SerializableInheritedPropertyAttribute attribute in Attribute .GetCustomAttributes(type, typeof(SerializableInheritedPropertyAttribute), false)) { const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly; const MemberTypes memberTypes = MemberTypes.Property | MemberTypes.Field; var member = attribute.BaseClass.GetMember(attribute.BasePropertyName, memberTypes, flags).FirstOrDefault <MemberInfo>(); if (member == null) { throw new MissingMemberException(attribute.BaseClass.FullName, attribute.BasePropertyName); } var prop = member as PropertyInfo; var memberType = prop != null ? prop.PropertyType : ((FieldInfo)member).FieldType; yield return(new PartDefinition { Member = member, MemberName = member.Name, Version = attribute.Version, ObsoleteVersion = attribute.ObsoleteVersion, Flags = attribute.Dynamic ? PartFlags.Dynamic : PartFlags.None, ReadMethod = attribute.ReadMethod, WriteMethod = attribute.WriteMethod, Type = memberType }); } }
public void IsLessThanTestDouble() { string argumentName = string.Empty; // correct double value = 1; try { ArgumentAssert.IsLessThan(value, 2, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } // incorrect value = 2; try { ArgumentAssert.IsLessThan(value, 1, argumentName); Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception."); } catch (ArgumentOutOfRangeException) { // test passed } }
public void IsNotEmptyTestCollectionGeneric() { ICollection argumentValue = new byte[] { 1, 2, 3 }; string argumentName = string.Empty; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } argumentValue = null; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); Assert.Fail("Assert method must throw ArgumentException exception."); } catch (ArgumentException) { // test passed } }
public void IsNotEmptyTestIn32() { int argumentValue = 1; string argumentName = string.Empty; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } argumentValue = 0; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); Assert.Fail("Assert method must throw ArgumentException exception."); } catch (ArgumentException) { // test passed } }
/// <summary> ///A test for IsNotEmpty with generic array param. ///</summary> public void IsNotEmptyTestGenericArrayHelper <T>() where T : class, new() { T[] argumentValue = new T[] { new T() }; string argumentName = string.Empty; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } argumentValue = null; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); Assert.Fail("Assert method must throw ArgumentException exception."); } catch (ArgumentException) { // test passed } }
/// <summary> ///A test for IsNotEmpty with generic dictionary param. ///</summary> public void IsNotEmptyTestGenericDictionaryHelper <TKey, TValue>() where TKey : class, new() where TValue : class, new() { IDictionary <TKey, TValue> argumentValue = new Dictionary <TKey, TValue>(); argumentValue.Add(new TKey(), new TValue()); string argumentName = string.Empty; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } argumentValue = null; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); Assert.Fail("Assert method must throw ArgumentException exception."); } catch (ArgumentException) { // test passed } }
/// <summary> ///A test for IsNotEmpty with generic <T> param. ///</summary> public void IsNotEmptyTestGerericHelper <T>() where T : class, new() { ICollection <T> argumentValue = new Collection <T>(); argumentValue.Add(new T()); string argumentName = string.Empty; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } argumentValue = null; try { ArgumentAssert.IsNotEmpty(argumentValue, argumentName); Assert.Fail("Assert method must throw ArgumentException exception."); } catch (ArgumentException) { // test passed } }
/// <summary> ///A test for IsNotNull ///</summary> public void IsNotNullTestHelper <T>() where T : class, new() { string argumentName = string.Empty; T argumentValue = new T(); try { ArgumentAssert.IsNotNull <T>(argumentValue, argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } argumentValue = null; try { ArgumentAssert.IsNotNull <T>(argumentValue, argumentName); Assert.Fail("Assert method must throw ArgumentException exception."); } catch (ArgumentException) { // test passed } }
private static string GetServerCode(string userId, string markedCode, Func <IEnumerable <UIMenuItem> > getServerCode) { ArgumentAssert.IsNotNullOrEmpty(markedCode, "markedCode"); string fileName = GetMenuFileName(userId, markedCode); if (File.Exists(fileName)) { return(File.ReadAllText(fileName)); } UIMenu menu = new UIMenu(getServerCode()); var code = menu.ToJSON(); try { WriteText(fileName, code); } catch (Exception ex) { throw ex; } finally { } return(code); }
public static InterfaceMapper Create(XmlNode section) { if (section == null) { return(null); } InterfaceMapper mapper = new InterfaceMapper(); var implements = section.SelectNodes("implement"); foreach (XmlNode implement in implements) { string contractTypeName = section.GetAttributeValue("contractType"); ArgumentAssert.IsNotNull(contractTypeName, "contractTypeName"); Type contractType = Type.GetType(contractTypeName); if (contractType == null) { throw new NoTypeDefinedException(contractTypeName); } var imp = InterfaceImplementer.Create(implement); if (imp != null) { mapper.AddImplement(contractType, imp); } } return(mapper); }
public void IsGreaterThanTestDateTime() { string argumentName = string.Empty; // correct DateTime value = new DateTime(2000, 1, 1); try { ArgumentAssert.IsGreaterThan(value, new DateTime(1999, 1, 1), argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } // incorrect value = new DateTime(2000, 1, 1); try { ArgumentAssert.IsGreaterThan(value, new DateTime(2001, 1, 1), argumentName); Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception."); } catch (ArgumentOutOfRangeException) { // test passed } }
public BuildKeywordsCommand(ConnectionBase connection, IEnumerable <string> indexes, string query) : base(connection) { ArgumentAssert.IsNotNull(indexes, "indexes"); _indexNames.UnionWith(indexes); _queryText = query; }
public void IsLessThanTestDateTime() { string argumentName = string.Empty; // correct DateTime value = new DateTime(2009, 12, 31, 23, 59, 59); try { ArgumentAssert.IsLessThan(value, new DateTime(2010, 1, 1, 0, 0, 0), argumentName); } catch (Exception ex) { Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message); } // incorrect value = new DateTime(1993, 6, 6, 6, 6, 6); try { ArgumentAssert.IsLessThan(value, new DateTime(1992, 6, 6, 6, 6, 6), argumentName); Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception."); } catch (ArgumentOutOfRangeException) { // test passed } }
/// <summary> /// 从领域对象上获得方法 /// </summary> /// <param name="ownerType"></param> /// <param name="methodName"></param> /// <returns></returns> private MethodInfo GetMethodFromObject() { var ownerType = this.ObjectOrExtensionType; var methodInfo = ownerType.ResolveMethod(this.MethodName); ArgumentAssert.IsNotNull(methodInfo, this.MethodName); return(methodInfo); }
/// <summary> /// Validate parameters /// </summary> internal void ValidateParameters() { foreach (SearchQuery query in this) { ArgumentAssert.IsNotNull(query, "query"); query.ValidateParameters(); } }
public UpdateAttributesCommand(ConnectionBase connection, IEnumerable <string> indexes, IEnumerable <AttributeUpdateBase> attributesValues) : base(connection) { ArgumentAssert.IsNotNull(indexes, "indexes"); ArgumentAssert.IsNotNull(attributesValues, "attributesValues"); _indexNames.UnionWith(indexes); _attributesValues.UnionWith(attributesValues); }
public override void Write(byte[] data) { ArgumentAssert.IsNotNull(data, "bytes"); if (OutputStream == null) { throw new ObjectDisposedException(null, Messages.Exception_IOStreamDisposed); } OutputStream.WriteBytes(data, data.Length); }
protected override void ValidateParameters() { ArgumentAssert.IsNotEmpty <SearchQuery>(QueryList, "QueryList"); if (MaxQueries > 0) { ArgumentAssert.IsInRange(QueryList, 1, MaxQueries, "QueryList"); } QueryList.ValidateParameters(); }
protected override void WriteBody(IBinaryWriter writer, int maxCount) { ArgumentAssert.IsInRange(Values.Count, 0, maxCount, "Values.Count"); writer.Write(Values.Count); foreach (T value in Values) { writer.Write(ConvertToInt64(value)); } }
/// <summary> /// Gets the size of the primitive type. /// </summary> /// <param name="type">The primitive type.</param> /// <returns>The size of the primitive type.</returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="type"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para><paramref name="type"/> is not primitive.</para> /// </exception> public static int GetPrimitiveSize(this Type type) { ArgumentAssert.IsNotNull(type, "type"); if (!type.IsPrimitive) { throw new ArgumentException("type must be a primitive.", "type"); } return(_primitiveSizes[type]); }
internal static bool ShouldLoadAddress(this LoadOptions loadOptions, Type targetType) { ArgumentAssert.IsNotNull(targetType, "targetType"); if (targetType.IsValueType) { return((loadOptions & LoadOptions.ValueAsAddress) == LoadOptions.ValueAsAddress); } return((loadOptions & LoadOptions.ReferenceAsAddress) == LoadOptions.ReferenceAsAddress); }
public XmlnsDefinitionAttribute(string xamlNamespace, string clrNamespace, string assemblyName) { ArgumentAssert.IsNotNullOrEmpty(xamlNamespace, "xamlNamespace"); ArgumentAssert.IsNotNullOrEmpty(clrNamespace, "clrNamespace"); ArgumentAssert.IsNotNullOrEmpty(assemblyName, "assemblyName"); this.XamlNamespace = xamlNamespace; this.ClrNamespace = clrNamespace; this.AssemblyName = assemblyName; }
private object CreateInstance() { ArgumentAssert.IsNotNull(this.ImplementType, "ImplementType"); var instance = Activator.CreateInstance(this.ImplementType, this.Arguments); if (instance == null) { throw new NoTypeDefinedException(this.ImplementType); } return(instance); }
/// <summary> /// Send request to Sphinx server using underlying data stream and process server response. /// Connection behaviour is changed - underlying network connection will not closed until <see cref="PersistentTcpConnection.Close()"/> method is called or object is disposed. /// </summary> /// <param name="command">Command to execute</param> internal override void PerformCommand(CommandBase command) { ArgumentAssert.IsNotNull(command, "command"); if (!IsConnected) { Open(); } command.Serialize(DataStream); DataStream.Flush(); command.Deserialize(DataStream); }
protected SimpleVariable(ICILWriter writer, int index, Type type, string name, bool isPinned) { ArgumentAssert.IsNotNull(writer, "writer"); ArgumentAssert.IsNotNull(type, "type"); Writer = writer; Index = index; Type = type; Name = name; IsPinned = isPinned; }