protected virtual void AssertProperties(TRpcException target, ConstructorKind kind, IDictionary <string, object> properties) { Assert.That(target.Message, Is.EqualTo(GetMessage(properties)), "Message"); if (kind != ConstructorKind.WithoutDebugInformation) { Assert.That(target.DebugInformation, Is.EqualTo(GetDebugInformation(properties)), "DebugInformation"); } Assert.That(target.RpcError, Is.EqualTo(GetRpcError(properties)), "RpcError"); switch (kind) { case ConstructorKind.WithInnerException: { Assert.That(target.InnerException, Is.SameAs(GetInnerException(properties)), "InnerException"); break; } case ConstructorKind.Serialization: { if (GetInnerException(properties) == null) { Assert.That(target.InnerException, Is.Null); } else { Assert.That(target.InnerException, Is.Not.Null, "InnerException"); Assert.That(target.InnerException.ToString(), Is.EqualTo(GetInnerException(properties).ToString()), "InnerException"); } break; } } }
private static bool DetermineCanDeserialize(ConstructorKind kind, SerializationContext context, Type targetType, IEnumerable <string> correspondingMemberNames, bool allowDefault) { if (HasUnpackableInterface(targetType, context)) { return(true); } switch (kind) { case ConstructorKind.Marked: { return(true); } case ConstructorKind.Parameterful: { return(HasAnyCorrespondingMembers(correspondingMemberNames)); } case ConstructorKind.Default: { return(allowDefault); } default: { Contract.Assert(kind == ConstructorKind.None || kind == ConstructorKind.Ambiguous, "kind == ConstructorKind.None || kind == ConstructorKind.Ambiguous : " + kind); return(false); } } }
internal ScriptFunctionObject([NotNull] Realm realm, [NotNull] ScriptObject prototype, bool extensible, FunctionKind functionKind, ConstructorKind constructorKind, bool strict) : base(realm, prototype, extensible, SpecialObjectType.None) { FunctionKind = functionKind; ConstructorKind = constructorKind; Strict = strict; }
internal ScriptFunctionObject([NotNull] Realm realm, [CanBeNull] ScriptObject prototype, bool extensible, [NotNull] Func <ScriptArguments, ScriptValue> callback, ConstructorKind constructorKind = ConstructorKind.None) : base(realm, prototype, extensible, SpecialObjectType.None) { this.callback = callback; FunctionKind = FunctionKind.Normal; ConstructorKind = constructorKind; }
private bool MatchTestClassConstructor(ConstructorKind kind, MethodBase method, string[] testMethodAttributes) { var constructorKindBit = method.IsStatic ? ConstructorKind.Static : ConstructorKind.Instance; if (!(method is ConstructorInfo) || (kind & constructorKindBit) == 0) { return(false); } return(IsDeclaredInTestFixture(method, testMethodAttributes)); }
public T NewRpcException(ConstructorKind kind, IDictionary <string, object> properties) { const string kindKey = "kind"; this._remoteDomain.SetData(dlsKeyPrefix + kindKey, kind); foreach (var property in properties) { this._remoteDomain.SetData(dlsKeyPrefix + property.Key, property.Value); } string resultKey = this._remoteProxy.RemoteNewRpcException("kind", properties.Keys.ToArray()); return(( T )this._remoteDomain.GetData(resultKey)); }
protected override RpcMissingMethodException NewRpcException(ConstructorKind kind, System.Collections.Generic.IDictionary <string, object> properties) { switch (kind) { case ConstructorKind.Serialization: case ConstructorKind.WithInnerException: { return(new RpcMissingMethodException(( string )properties["MethodName"], GetMessage(properties), GetDebugInformation(properties), GetInnerException(properties))); } default: { return(new RpcMissingMethodException(( string )properties["MethodName"], GetMessage(properties), GetDebugInformation(properties))); } } }
protected override RpcTimeoutException NewRpcException(ConstructorKind kind, System.Collections.Generic.IDictionary <string, object> properties) { switch (kind) { case ConstructorKind.Serialization: case ConstructorKind.WithInnerException: { return(new RpcTimeoutException(( TimeSpan )(properties["ClientTimeout"] ?? TimeSpan.Zero), GetMessage(properties), GetDebugInformation(properties), GetInnerException(properties))); } default: { return(new RpcTimeoutException(( TimeSpan )(properties["ClientTimeout"] ?? TimeSpan.Zero), GetMessage(properties), GetDebugInformation(properties))); } } }
protected override RpcTransportException NewRpcException(ConstructorKind kind, System.Collections.Generic.IDictionary <string, object> properties) { switch (kind) { case ConstructorKind.Serialization: case ConstructorKind.WithInnerException: { return(new RpcTransportException(GetRpcError(properties), GetMessage(properties), GetDebugInformation(properties), GetInnerException(properties))); } case ConstructorKind.Default: default: { return(new RpcTransportException(GetRpcError(properties), GetMessage(properties), GetDebugInformation(properties))); } } }
protected virtual TRpcException NewRpcException(ConstructorKind kind, IDictionary <string, object> properties) { switch (kind) { case ConstructorKind.Serialization: case ConstructorKind.WithInnerException: { return(( TRpcException )Activator.CreateInstance(typeof(TRpcException), GetRpcError(properties), GetMessage(properties), GetDebugInformation(properties), GetInnerException(properties))); } case ConstructorKind.Default: default: { return(( TRpcException )Activator.CreateInstance(typeof(TRpcException), GetRpcError(properties), GetMessage(properties), GetDebugInformation(properties))); } } }
private bool MatchTestClassConstructor(ConstructorKind kind, MethodBase method, string[] testMethodAttributes) { var constructorKindBit = method.IsStatic ? ConstructorKind.Static : ConstructorKind.Instance; if (!(method is ConstructorInfo) || (kind & constructorKindBit) == 0) return false; return IsDeclaredInTestFixture(method, testMethodAttributes); }
protected override UnexpcetedRpcException NewRpcException(ConstructorKind kind, System.Collections.Generic.IDictionary <string, object> properties) { return(new UnexpcetedRpcException(( MessagePackObject )properties["Error"], ( MessagePackObject )properties["ErrorDetail"])); }
protected override void AssertProperties(UnexpcetedRpcException target, ConstructorKind kind, System.Collections.Generic.IDictionary <string, object> properties) { // Not call base.AssertProperties bevause UnexpcetedRpcException does not use general properties. Assert.That(target.Error, Is.EqualTo(( MessagePackObject )properties["Error"])); Assert.That(target.ErrorDetail, Is.EqualTo(( MessagePackObject )properties["ErrorDetail"])); }
private static ConstructorInfo FindDeserializationConstructor(SerializationContext context, Type targetType, out ConstructorKind constructorKind) { var constructors = targetType.GetConstructors().ToArray(); if (constructors.Length == 0) { if (context.CompatibilityOptions.AllowAsymmetricSerializer) { constructorKind = ConstructorKind.None; return(null); } else { throw NewTypeCannotBeSerializedException(targetType); } } // The marked construtor is always preferred. var markedConstructors = FindExplicitDeserializationConstructors(constructors); switch (markedConstructors.Count) { case 0: { break; } case 1: { // OK use it for deserialization. constructorKind = ConstructorKind.Marked; return(markedConstructors[0]); } default: { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "There are multiple constructors marked with MessagePackDeserializationConstrutorAttribute in type '{0}'.", targetType ) ); } } // A constructor which has most parameters will be used. var mostRichConstructors = constructors.GroupBy(ctor => ctor.GetParameters().Length).OrderByDescending(g => g.Key).First().ToArray(); #if DEBUG Trace("SerializationTarget::FindDeserializationConstructor.MostRich({0}) -> {1}", targetType, String.Join(";", mostRichConstructors.Select(x => x.ToString()).ToArray())); #endif // DEBUG switch (mostRichConstructors.Length) { case 1: { if (mostRichConstructors[0].GetParameters().Length == 0) { if (context.CompatibilityOptions.AllowAsymmetricSerializer) { constructorKind = ConstructorKind.Default; return(mostRichConstructors[0]); } else { throw NewTypeCannotBeSerializedException(targetType); } } // OK try use it but it may not handle deserialization correctly. constructorKind = ConstructorKind.Parameterful; return(mostRichConstructors[0]); } default: { if (context.CompatibilityOptions.AllowAsymmetricSerializer) { constructorKind = ConstructorKind.Ambiguous; return(null); } else { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Cannot serialize type '{0}' because it does not have any serializable fields nor properties, and serializer generator failed to determine constructor to deserialize among({1}).", targetType, String.Join(", ", mostRichConstructors.Select(ctor => ctor.ToString()).ToArray()) ) ); } } } }
public void AssertProperties(T target, ConstructorKind kind, IDictionary <string, object> properties) { this._localInstance.AssertProperties(target, kind, properties); }
public static ScriptFunctionObject CreateBuiltinFunction([NotNull] Realm realm, [NotNull] Func <ScriptArguments, ScriptValue> callback, ScriptObject prototype, int length, string name, ConstructorKind constructorKind = ConstructorKind.None) { var function = new ScriptFunctionObject(realm, prototype, true, callback, constructorKind); function.DefineOwnProperty("length", new PropertyDescriptor(length, false, false, true)); function.DefineOwnProperty("name", new PropertyDescriptor(name, false, false, true)); return(function); }