Beispiel #1
0
 public override IEnumerable <string> GetUsedNamespaces(bool includeSelf = false)
 {
     return(base.GetUsedNamespaces(includeSelf)
            .Union(Properties.SelectMany(p => p.GetUsedNamespaces()))
            .Union(Inherits.SelectMany(t => t.GetUsedNamespaces(true)))
            .Union(TypeArguments.SelectMany(t => t.GetUsedNamespaces(true))));
 }
Beispiel #2
0
 protected override void CheckInherits(TypeUsageInfo info)
 {
     if (info.IsClass && Inherits.Any(t => t.IsClass))
     {
         throw new ArgumentOutOfRangeException("info", "Trying inherits from multiply classes");
     }
 }
Beispiel #3
0
        public static bool TryGetScript(string typeName, string scriptName, out TsDelegate del)
        {
            if (typeName == null)
            {
                del = null;
                return(false);
            }
            var origin = typeName;

            do
            {
                if (InstanceScripts.TryGetValue(typeName, scriptName, out del))
                {
                    //If the script is inherited, cache it in the child's script lookup.
                    if (typeName != origin)
                    {
                        InstanceScripts.Add(origin, scriptName, del);
                    }
                    return(true);
                }
            }while (Inherits.TryGetValue(typeName, out typeName));

            del = null;
            return(false);
        }
Beispiel #4
0
 public static string ObjectGetParent(ITsInstance inst)
 {
     if (Inherits.TryGetValue(inst.ObjectType, out var parent))
     {
         return(parent);
     }
     return("");
 }
    public static void Main(string[] args)
    {
        Console.WriteLine("==== Callbase ====\n");

        var hi = new Inherits();

        hi.Metho();
    }
Beispiel #6
0
        public Entity?InheritedUnidentifiedProperties()
        {
            if (!string.IsNullOrEmpty(UnidentifiedProperties))
            {
                return(this);
            }

            return(Inherits?.InheritedUnidentifiedProperties());
        }
Beispiel #7
0
 public static void ProcessObjectDefinition(ObjectDefinition definition)
 {
     Types.Add(definition.Name);
     if (definition.Parent != null)
     {
         Inherits.Add(definition.Name, definition.Parent);
     }
     InstanceScripts.AddRow(definition.Name, definition.Scripts);
 }
Beispiel #8
0
 public static bool ObjectIs(string type, string expectedType)
 {
     do
     {
         if (type == expectedType)
         {
             return(true);
         }
     }while (Inherits.TryGetValue(type, out type));
     return(false);
 }
Beispiel #9
0
        public static bool ObjectIsAncestor(string parent, string type)
        {
            while (Inherits.TryGetValue(type, out type))
            {
                if (type == parent)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #10
0
 public virtual void InheritsFrom(TypeUsageInfo info)
 {
     if (Inherits.Any(t => t.Equals(info)))
     {
         throw new ArgumentOutOfRangeException("info", string.Format("Type already inherits from this type {0}", info));
     }
     if (IsGeneric && info.IsGeneric)
     {
         if (info.TypeArguments.Where(t => t.IsTypeArgument).Any(t => !TypeArguments.Contains(t)))
         {
             throw new ArgumentOutOfRangeException("info", string.Format("Trying inherit from type {0} with unknown type argument", info));
         }
     }
     CheckInherits(info);
     _inherits.Add(info);
 }
Beispiel #11
0
        public bool IfRedefineMethod(IMethod method)
        {
            var methodR = Methods.SingleOrDefault(m => m.ID == method.ID);

            if (methodR != null)
            {
                //Encontro el metodo por tanto este se redefiine
                if (methodR.Equals(method))
                {
                    methodR.IsRedefined = true;
                    return(true);
                }
                return(false);
            }
            return(Inherits?.IfRedefineMethod(method) ?? true);
        }
Beispiel #12
0
        public override IEnumerable <INotation> GetMembers()
        {
            yield return(CustomAttributes.InsertBlank().Combine());

            yield return(Accessibility.ToDisplayString().ToNotation());

            yield return(ConstNotations.Blank);

            yield return(ConstNotations.Class);

            yield return(ConstNotations.Blank);

            yield return(Name.ToNotation());

            if (TypeParameters.Count > 0)
            {
                yield return(ConstNotations.OpenAngleBracket);

                yield return(TypeParameters.Select(i => i.ToOnlyTypeDefinitionNotation()).InsertComma().Combine());

                yield return(ConstNotations.CloseAngleBracket);
            }
            if (Inherits.Count > 0)
            {
                yield return(ConstNotations.Colon);

                yield return(Inherits.InsertComma().Combine());
            }
            if (TypeParameters.Count > 0)
            {
                yield return(ConstNotations.Blank);
            }
            yield return(TypeParameters.Select(i => i.ToConstantNotation(false)).InsertBlank().Combine());

            yield return(ConstNotations.Blank);

            yield return(ConstNotations.OpenBrace);

            yield return(Members.Combine());

            yield return(ConstNotations.CloseBrace);
        }
Beispiel #13
0
            /// <summary>
            /// Outputs a list of the relations that this class has toward other classes.
            /// </summary>
            /// <param name="builder">the stringbuilder to render to</param>
            /// <returns></returns>
            public StringBuilder OutputRelations(StringBuilder builder)
            {
                foreach (var use in Uses.Where(u => u.Relevant))
                {
                    //Do not pretend to be 'using' a type that is equal to the inheriting types.
                    if (Inherits.Any(i => i.TypeName == use.TypeName))
                    {
                        continue; //don't output if using superclass, this is not a useful notation.
                    }


                    //Todo: any reference to a complex type (i.e. class) tends to get displayed as a compound reference when it is a member in\
                    //the class; this is not a correct logic; needs to be expanded for example by checking the contents of the 'refid' in question (if it is nested, it
                    //could probably be assumed to be a more than one relationship; i.e. composition)
                    use.Compound = false;

                    string arrowhead;
                    if (use.Compound)
                    {
                        arrowhead = "arrowhead=odiamond";
                        builder.AppendLine($@"""{ use.TypeName.NoNameSpaces()}""->""{Name.NoNameSpaces()}"" [{arrowhead}  {(use.node is InterfaceNode ? "style =dashed" : "")}  label=""{use.DeclaredName.NoNameSpaces()}"" ]");
                    }
                    else
                    {
                        arrowhead = "arrowhead = normal";
                        builder.AppendLine($@"""{ Name.NoNameSpaces()}""->""{use.TypeName.NoNameSpaces()}"" [{arrowhead}  {(use.node is InterfaceNode ? "style =dashed" : "")}  label=""{use.DeclaredName.NoNameSpaces()}"" ]");
                    }

                    //Create the actual arrow from this node to the used one, if the used node is an interface, make the line dashed to indicate dependency
                }


                foreach (var inheritee in Inherits)
                {
                    builder.AppendLine(@" edge [arrowtail = ""empty"" ]");
                    builder.AppendLine($"\"{inheritee.TypeName.NoNameSpaces()}\"->\"{Name.NoNameSpaces()}\" [{ (inheritee.node is InterfaceNode ? "style=dashed" : "style=solid")} { (inheritee == null ? ", label=\"??\"" : " ") } dir=back ]");
                }

                return(builder);
            }
Beispiel #14
0
        //Esto no analiza los casos que los tipos sea undefined
        private bool ConformPrivate(IType a)
        {
            //Significa que no encontre a n en los ancestros

            if (Equals(a))
            {
                return(true);
            }
            else if (Inherits == null)
            {
                if (a.Equals(Parent.Object))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(Inherits.Conform(a));
            }
        }
Beispiel #15
0
 public void AddInherits(string tableName) => Inherits.Add(tableName);
Beispiel #16
0
        /// <summary>RenderAny as EPL. </summary>
        /// <param name="writer">to output to</param>
        public void ToEPL(TextWriter writer)
        {
            writer.Write("create");
            if (TypeDefinition != null)
            {
                TypeDefinition.Value.Write(writer);
            }

            writer.Write(" schema ");
            writer.Write(SchemaName);
            writer.Write(" as ");
            if ((Types != null) && (Types.IsNotEmpty()))
            {
                string delimiter = "";
                foreach (string type in Types)
                {
                    writer.Write(delimiter);
                    writer.Write(type);
                    delimiter = ", ";
                }
            }
            else
            {
                writer.Write("(");
                string delimiter = "";
                foreach (SchemaColumnDesc col in Columns)
                {
                    writer.Write(delimiter);
                    col.ToEPL(writer);
                    delimiter = ", ";
                }

                writer.Write(")");
            }

            if ((Inherits != null) && (Inherits.IsNotEmpty()))
            {
                writer.Write(" inherits ");
                string delimiter = "";
                foreach (string name in Inherits)
                {
                    writer.Write(delimiter);
                    writer.Write(name);
                    delimiter = ", ";
                }
            }

            if (StartTimestampPropertyName != null)
            {
                writer.Write(" starttimestamp ");
                writer.Write(StartTimestampPropertyName);
            }

            if (EndTimestampPropertyName != null)
            {
                writer.Write(" endtimestamp ");
                writer.Write(EndTimestampPropertyName);
            }

            if ((CopyFrom != null) && (CopyFrom.IsNotEmpty()))
            {
                writer.Write(" copyFrom ");
                string delimiter = "";
                foreach (string name in CopyFrom)
                {
                    writer.Write(delimiter);
                    writer.Write(name);
                    delimiter = ", ";
                }
            }
        }
Beispiel #17
0
 //Se busca el atributo en la lista de atributos en el caso de que sea null
 //devolvemos el del tipo heredado
 //si el tipo heredado es null entonces retorno null
 public IAttribute GetVar(string Name)
 {
     return(Attributes.FirstOrDefault(a => a.ID == Name) ?? Inherits?.GetVar(Name));
 }
Beispiel #18
0
        protected override void BuildBlock(CodeBlock clss)
        {
            base.BuildBlock(clss);
            if (Comment != null)
            {
                Comment.Alignment = Alignment.Top;
                clss.AppendFormat($"{Comment}");
            }

            clss.AppendFormat("{0} class {1}", new ModifierString(Modifier), base.Name);
            if (Inherits.Length > 0)
            {
                clss.AppendFormat("\t: {0}", string.Join(", ", Inherits.Select(inherit => inherit.ToString())));
            }

            var body = new CodeBlock();

            if (Sorted)
            {
                var flds = fields.Where(fld => (fld.Modifier & Modifier.Const) != Modifier.Const);
                foreach (Field field in flds.OrderBy(fld => fld.Modifier))
                {
                    body.Add(field);
                }

                foreach (Constructor constructor in constructors)
                {
                    body.Add(constructor);
                    body.AppendLine();
                }

                foreach (Property property in properties)
                {
                    body.Add(property);

                    if (property.GetBlock().Count > 1)
                    {
                        body.AppendLine();
                    }
                }

                foreach (Method method in methods)
                {
                    body.Add(method);
                    body.AppendLine();
                }

                flds = fields.Where(fld => (fld.Modifier & Modifier.Const) == Modifier.Const);
                if (flds.Count() > 0)
                {
                    body.AppendLine();
                    foreach (Field field in flds)
                    {
                        body.Add(field);
                    }
                }

                foreach (Class _class in classes)
                {
                    body.Add(_class);
                    body.AppendLine();
                }
            }
            else
            {
                list.ForEach(
                    item => body.Add(item),
                    item =>
                {
                    if (item.Count == 1 && (item is Field || item is Property))
                    {
                        return;
                    }

                    //if (item.Count == 1 && (item is Member))
                    //    return;

                    body.AppendLine();
                }
                    );
            }

            clss.AddWithBeginEnd(body);
        }
        public override Element Build()
        {
            var @class = new Class(SourceType.Name.SanitizeTypeName())
            {
                Modifiers = { Modifier.Export }
            };

            WriteLine(ConsoleColor.Green, "class", @class.Name);

            if (Inherits != null)
            {
                @class.Extends = Inherits.TypescriptName();
            }

            var classDocumentation = Documentation?.ForClass(SourceType);

            if (classDocumentation != null)
            {
                @class.Comment = classDocumentation.Summary;
            }

            if (SourceType.IsAbstract)
            {
                @class.Modifiers.Add(Modifier.Abstract);
            }

            foreach (var @interface in _interfaces)
            {
                @class.Implements.Add(@interface.TypescriptName());
            }

            foreach (var typeArgument in _typeArguments)
            {
                @class.TypeArguments.Add(typeArgument.TypescriptName());
            }

            if (!SourceType.IsAbstract)
            {
                foreach (var attribute in _attributes)
                {
                    var name      = attribute.GetType().ClassDecoratorName();
                    var arguments = new ObjectLiteral(attribute);
                    @class.Decorators.Add(new Decorator(name, new[] { arguments }));
                }
            }

            foreach (var source in _properties)
            {
                var getMethod  = source.GetMethod;
                var target     = new Property(source.Name.CamelCase(), source.PropertyType.TypescriptName());
                var attributes = source.GetCustomAttributes(false).Where(t => t.GetType().IsPublic);

                if (getMethod.IsAbstract)
                {
                    target.Modifiers.Add(Modifier.Abstract);
                }

                if (getMethod.IsFamily)
                {
                    target.Modifiers.Add(Modifier.Protected);
                }
                else
                {
                    target.Modifiers.Add(Modifier.Public);
                }

                var propertyDocumentation = Documentation?.ForMember(source);

                if (propertyDocumentation != null)
                {
                    target.Comment = propertyDocumentation.Summary;
                }

                if (OutputContext.Properties?.Initialize ?? false)
                {
                    SetDefaultValue(source, target);
                }

                foreach (var attribute in attributes)
                {
                    var name      = attribute.GetType().PropertyDecoratorName();
                    var arguments = new ObjectLiteral(attribute);
                    target.Decorators.Add(new Decorator(name, new[] { arguments }));
                }

                @class.Members.Add(target);
            }

            var illegalProp = @class.Properties.SingleOrDefault(p => p.Name == "constructor");

            {
                if (illegalProp != null)
                {
                    const string prefix  = "_";
                    var          newName = prefix + illegalProp.Name;
                    while (@class.Properties.Any(p => p.Name == newName))
                    {
                        newName = prefix + newName;
                    }

                    illegalProp.Name = newName;
                }
            }
            return(@class);
        }
Beispiel #20
0
 //Lo mismo que el metodo anterior
 public IMethod GetMethod(string Name)
 {
     return(Methods.FirstOrDefault(m => m.ID == Name) ?? Inherits?.GetMethod(Name));
 }
Beispiel #21
0
			public void SomeNewMethod() {
				var result = new Inherits() + new Inherits();
				var a = result.GetHashCode() * 7;
			}