private void SetType(JsNode node, IJsTypeInfo type, JsPropertyInfo prop = null, JsMethodSignature sig = null) { var a = node.Annotation<JsNodeTypeAnnotation>() ?? node.AddAnnotation(new JsNodeTypeAnnotation()); if (a.Type != null) a.Type = type; if (a.Property != null) a.Property = prop; if (a.FunctionSignature != null) a.FunctionSignature = sig; }
//private static Dictionary<Type, Func<IJsTypeInfo, IJsTypeInfo, bool>> interfaceMatchers = new Dictionary<Type, Func<IJsTypeInfo, IJsTypeInfo, bool>> //{ // [typeof(IJsMemberAccessType)] = (a, b) => // { // } //}; public static bool MatchType(this IJsTypeInfo a, IJsTypeInfo b, MatchAntiCycle antiCycle = null) { if (a == null | b == null) { return(false); } if (a == b) { return(true); } if (a.Typeof != b.Typeof || a.Typeof == "object" && b.Typeof == "function") { return(false); } antiCycle = antiCycle ?? new MatchAntiCycle(); antiCycle.Add((a, b)); if (!a.CanBeNull && b.CanBeNull) { return(false); } if (a is IJsMemberAccessType aMember && (!(b is IJsMemberAccessType bMember) || !aMember.ListProperties().All( p => bMember.GetProperty(p.Name) is var p2 && p2.Exists && p.Type.MatchType(p2.Type, antiCycle)))) { return(false); } if (a is IJsInvocableType aInvokable && (!(b is IJsInvocableType bInvokable) || !(bInvokable.GetSignatures().ToArray() is var bSignatures && aInvokable.GetSignatures().All(sig => bSignatures.Any(sigB => sigB.MatchSig(sig, antiCycle)))))) { return(false); } return(true); //foreach (var im in interfaceMatchers) //{ // var (ai, bi) = (im.Key.IsInstanceOfType(a), im.Key.IsInstanceOfType(b)); // if (ai && !bi) return false; //} }
public static JsIndexableType CreateArray(IJsTypeInfo elementType, params JsPropertyInfo[] properties) => new JsIndexableType(elementType, true, properties);
public JsIndexableType(IJsTypeInfo elementType, bool integerOnly, IEnumerable <JsPropertyInfo> properties = null, string type = "object") : base(properties, type) { this.ElementType = elementType; this.IntegerOnly = integerOnly; }
public JsMethodSignature(IJsTypeInfo[] arguments, IJsTypeInfo resultType, IJsTypeInfo moreArgs = null) { this.ArgumentTypes = arguments; this.ResultType = resultType; this.MoreArgsType = moreArgs; }
public JsPropertyInfo(string name, IJsTypeInfo type) { this.Name = name; this.Type = type; }