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 BuildKeywordsCommand(ConnectionBase connection, IEnumerable <string> indexes, string query) : base(connection) { ArgumentAssert.IsNotNull(indexes, "indexes"); _indexNames.UnionWith(indexes); _queryText = query; }
/// <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 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; }
/// <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 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); }
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); }
/// <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); }
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); }
/// <summary> /// Validate parameters /// </summary> internal void ValidateParameters() { foreach (SearchQuery query in this) { ArgumentAssert.IsNotNull(query, "query"); query.ValidateParameters(); } }
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); }
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); }
/// <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]); }
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; }
/// <summary> /// 运行 /// </summary> public void Run() { var method = this.Type.ResolveMethod(MethodName); ArgumentAssert.IsNotNull(method, MethodName); if (!method.IsStatic) { throw new AppSettingException(string.Format(Strings.PreApplicationEndNoStatic, this.Type.FullName, this.MethodName)); } method.Invoke(null, null); }
/// <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); }
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); }
protected BinaryWriterBase(IStreamAdapter output, Encoding encoding) { ArgumentAssert.IsNotNull(output, "output"); ArgumentAssert.IsNotNull(encoding, "encoding"); if (!output.CanWrite) { throw new IOException(Messages.Exception_CantWriteToStream); } _outputStream = output; _encoding = encoding; }
/// <summary> /// 从对象扩展上获得静态方法 /// </summary> /// <param name="ownerType"></param> /// <param name="methodName"></param> private MethodInfo GetMethodFromObjectExtension() { var ownerType = this.ObjectOrExtensionType; var methodInfo = ownerType.ResolveMethod(this.MethodName); ArgumentAssert.IsNotNull(methodInfo, this.MethodName); if (!methodInfo.IsStatic) { throw new DomainDrivenException(string.Format(Strings.PropertyActionObjectExtensionNoStatic, this.MethodName)); } return(methodInfo); }
/// <summary> /// Initializes a new instance of the <see cref="BinaryReaderBase"/> class based on the supplied stream and a specific character encoding. /// </summary> /// <param name="input">Input stream</param> /// <param name="encoding">The character encoding object used to decode strings from stream</param> protected BinaryReaderBase(IStreamAdapter input, Encoding encoding) { ArgumentAssert.IsNotNull(input, "input"); ArgumentAssert.IsNotNull(encoding, "encoding"); if (!input.CanRead) { throw new IOException(Messages.Exception_CantReadFromStream); } _inputStream = input; _encoding = encoding; }
private static MethodInfo GetMethod(Type type, string methodName, Type[] genericTypes, MethodParameter[] prms, bool isGenericVersion) { ArgumentAssert.IsNotNull(type, "type"); ArgumentAssert.IsNotNull(methodName, "methodName"); genericTypes = genericTypes ?? Type.EmptyTypes; prms = prms ?? MethodParameter.EmptyParameters; MethodKey key = new MethodKey(type, methodName, genericTypes, prms, isGenericVersion); return(_getMethod(key)); }
public static Uri ReadUri(this IPrimitiveReader reader) { ArgumentAssert.IsNotNull(reader, "reader"); var stringValue = reader.ReadString(); if (stringValue == null) { return(null); } return(new Uri(stringValue)); }
public static void WriteUri(this IPrimitiveWriter writer, Uri value) { ArgumentAssert.IsNotNull(writer, "writer"); if (value == null) { writer.Write((string)null); } else { writer.Write(value.ToString()); } }
/// <summary> /// Deserializes an object of the specified type from <paramref name="input"/>. /// </summary> /// <typeparam name="T">The type of object to deserialize.</typeparam> /// <param name="input">The stream to read from.</param> /// <returns>The deserialized object. <see langword="null"/> values are possible /// if <see langword="null"/> was originally serialized into the stream.</returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="input"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para><paramref name="input.CanSeek"/> is <see langword="false"/>.</para> /// </exception> public static T Deserialize <T>(Stream input) { ArgumentAssert.IsNotNull(input, "input"); if (!input.CanSeek) { throw new ArgumentException("input.CanSeek must be true", "input"); } var serializer = BarfSerializers.Get <T>(PartFlags.None); var args = new BarfDeserializationArgs(SerializerFactory.GetReader(input)); return(serializer.Deserialize(args)); }
public static IExpression AddMember(this IExpression valueShortcut, MemberInfo member) { ArgumentAssert.IsNotNull(member, "member"); if (member is PropertyInfo) { return(valueShortcut.AddMember((PropertyInfo)member)); } if (member is FieldInfo) { return(valueShortcut.AddMember((FieldInfo)member)); } throw new ArgumentException("member is not a PropertyInfo or a MemberInfo", "member"); }
/// <summary> /// Send request to Sphinx server using underlying data stream and process server response. /// </summary> /// <param name="command">Command extending <see cref="CommandBase"/> class.</param> internal override void PerformCommand(CommandBase command) { ArgumentAssert.IsNotNull(command, "command"); Open(); try { SendHandshake(); command.Serialize(DataStream); DataStream.Flush(); command.Deserialize(DataStream); } finally { Close(); } }
/// <summary> /// Validate all command parameters. /// </summary> protected override void ValidateParameters() { ArgumentAssert.IsNotEmpty <string>(Documents, "Documents"); ArgumentAssert.IsNotEmpty <string>(Keywords, "Keywords"); ArgumentAssert.IsNotEmpty(Index, "Index"); ArgumentAssert.IsNotNull(BeforeMatch, "BeforeMatch"); ArgumentAssert.IsNotNull(AfterMatch, "AfterMatch"); ArgumentAssert.IsNotNull(SnippetsDelimiter, "SnippetsDelimiter"); ArgumentAssert.IsGreaterThan(SnippetSizeLimit, 0, "SnippetSizeLimit"); ArgumentAssert.IsGreaterOrEqual(SnippetsCountLimit, 0, "SnippetsCountLimit"); ArgumentAssert.IsGreaterOrEqual(WordsAroundKeyword, 0, "WordsAroundKeyword"); ArgumentAssert.IsGreaterOrEqual(WordsCountLimit, 0, "WordsCountLimit"); ArgumentAssert.IsDefinedInEnum(typeof(HtmlStripMode), HtmlStripMode, "HtmlStripMode"); ArgumentAssert.IsDefinedInEnum(typeof(PassageBoundary), PassageBoundary, "PassageBoundary"); ArgumentAssert.IsDefinedInEnum(typeof(BuildExcerptsOptions), Options, "Options"); }
public static Uri FillUri(this FillArgs args) { ArgumentAssert.IsNotNull(args, "args"); if (args.NextIsNull) { return(null); } var b = new UriBuilder(); b.Scheme = args.NextBoolean ? "http" : "https"; b.Host = Guid.NewGuid().ToString("N"); b.Port = args.NextByte + 20; return(b.Uri); }
private QueryAdapter <T> FillData(string dbType, string expression, Action <DynamicData> fillArgs) { ArgumentAssert.IsNotNull(expression, "expression"); if (_expressionData == null) { _expressionData = new Dictionary <string, string>(5); } _expressionData.Add(dbType, expression); if (fillArgs != null) { if (_fillArgsData == null) { _fillArgsData = new Dictionary <string, Action <DynamicData> >(5); } _fillArgsData.Add(dbType, fillArgs); } return(this); }