Esempio n. 1
0
        private string GetInheritText(bool linked)
        {
            var inheritedText = ImplementedInterfaces.Count > 0 ?
                                string.Join(", ", ImplementedInterfaces.Select(i => linked ? i.LinkedNameWithArguments :
                                                                               i.NameWithTypeArguments).ToList()) : string.Empty;

            var baseText = string.Empty;

            if (BaseTypes.Any())
            {
                baseText = linked ? BaseTypes.First().LinkedNameWithArguments : BaseTypes.First().NameWithTypeArguments;
            }

            if (inheritedText != string.Empty && baseText != string.Empty)
            {
                inheritedText += ", " + baseText;
                inheritedText  = " : " + inheritedText;
            }
            else if (inheritedText != string.Empty)
            {
                inheritedText = " : " + inheritedText;
            }
            else if (baseText != string.Empty)
            {
                inheritedText = " : " + baseText;
            }

            return(inheritedText);
        }
Esempio n. 2
0
        public override string ToString()
        {
            var result = $"{string.Join(", ", Modifiers)} class {Name} ";

            if (BaseTypes.Any())
            {
                result += $": {string.Join(", ", BaseTypes.Select(t => t.ToString()))}";
            }
            result += " { " + (Body?.ToString() ?? "") + " }";

            return(result);
        }
Esempio n. 3
0
        public override object GetInputVarying(Type type, string varyingName)
        {
            DebugGetError(new StackTrace(true));

            if (DrawCall == null)
            {
                return(DebugGetError(type, new StackTrace(true)));
            }

            // get current shader program pipeline
            var pipeline = GL.GetInteger(GetPName.ProgramPipelineBinding);

            if (pipeline <= 0)
            {
                return(DebugGetError(type, new StackTrace(true)));
            }

            // get vertex shader
            GL.GetProgramPipeline(pipeline, ProgramPipelineParameter.VertexShader, out int program);
            if (program <= 0)
            {
                return(DebugGetError(type, new StackTrace(true)));
            }

            // get vertex input attribute location
            var location = GL.GetAttribLocation(program, varyingName);

            if (location < 0)
            {
                return(DebugGetError(type, new StackTrace(true)));
            }

            // get vertex input data
            var data  = DrawCall?.vertin.GetVertexData(gl_VertexID, gl_InstanceID);
            var array = data?.Skip(location).First();

            if (array == null)
            {
                return(DebugGetError(type, new StackTrace(true)));
            }

            DebugGetError(new StackTrace(true));

            // return base type
            if (BaseTypes.Any(x => x == type))
            {
                return(array.To(type).GetValue(0));
            }

            // create new object from byte array
            return(type.GetConstructor(new[] { typeof(byte[]) })?.Invoke(new[] { array }));
        }
        private InterfaceDeclarationSyntax GetInterfaceSyntax()
        {
            // TODO for some reason my modifiers seems to be null for the interface. Needs further investigation
            // create interface
            var interfaceSyntax = SyntaxFactory.InterfaceDeclaration(Name).AddModifiers(MyModifiers.Values.ToArray());

            // add doc
            interfaceSyntax = interfaceSyntax.AddSummary(DocString) as InterfaceDeclarationSyntax;

            // add base types
            if (BaseTypes.Any())
            {
                interfaceSyntax = interfaceSyntax.AddBaseListTypes(BaseTypes.Values.Select(b => SyntaxFactory.SimpleBaseType(SyntaxFactory.IdentifierName(b))).ToArray());
            }

            // add properties
            var properties = Properties.Values.Select(c =>
            {
                c.MyModifiers.Clear();
                c.GetAccessorModifier = default(SyntaxToken);
                if (c.SetAccessorModifier.ToString() == "public")
                {
                    c.SetAccessorModifier = default(SyntaxToken);
                }
                else if (c.SetAccessorModifier.ToString() == "private" || c.SetAccessorModifier.ToString() == "internal")
                {
                    c.SetAccessor = false;
                }
                c.IsInterface = true;
                return(c.GetSyntax());
            }).ToArray();

            interfaceSyntax = interfaceSyntax.AddMembers(properties);

            // add methods
            var methods = Methods.Values.Select(c =>
            {
                c.MyModifiers.Clear();
                c.IsInterface = true;
                return(c.GetSyntax());
            })
                          .Select(s =>
            {
                s = s.WithBody(null);
                return(s);
            }).ToArray();

            interfaceSyntax = interfaceSyntax.AddMembers(methods);

            return(interfaceSyntax);
        }
Esempio n. 5
0
 /// <summary>
 /// True if the specified entity type is a parent somewhere in the inheritance chain for this entity type.
 /// </summary>
 /// <param name="entityType">Entity type to look for in the inheritance chain.</param>
 /// <returns>True if found, false if not.</returns>
 public bool IsSubtypeOf(ModelEntityType entityType)
 {
     try
     {
         return(BaseTypes.Any(t => t == entityType));
     }
     catch (Exception ex)
     {
         try
         {
             ExceptionTools.AddExceptionData(ex, this);
         }
         catch { }
         throw;
     }
 }
        private ClassDeclarationSyntax GetClassSyntax()
        {
            // create class
            var classSyntax = SyntaxFactory.ClassDeclaration(Name)
                              .AddModifiers(MyModifiers.Values.ToArray());

            // add base types
            if (BaseTypes.Any())
            {
                classSyntax = classSyntax.AddBaseListTypes(BaseTypes.Values.Select(b => SyntaxFactory.SimpleBaseType(SyntaxFactory.IdentifierName(b))).ToArray());
            }

            // add doc
            classSyntax = classSyntax.AddSummary(DocString) as ClassDeclarationSyntax;

            // add any constructors
            var constructors = Constructors.Values.Select(c => c.GetSyntax()).ToArray();

            classSyntax = classSyntax.AddMembers(constructors);

            // add any private fields
            var privateFields = PrivateFields.Values.Select(p => p.GetSyntax()).ToArray();

            classSyntax = classSyntax.AddMembers(privateFields);

            // add properties
            var properties = Properties.Values.Select(p => p.GetSyntax()).ToArray();

            classSyntax = classSyntax.AddMembers(properties);

            // add methods
            var methods = Methods.Values.Select(m => m.GetSyntax()).ToArray();

            classSyntax = classSyntax.AddMembers(methods);

            return(classSyntax);
        }
Esempio n. 7
0
        public override string WriteTypeScript(CodeConversionOptions options, Context context)
        {
            context = context.Clone();
            context.GenericTypeParameters = GenericTypeParameters;

            // keywords
            return("export ".If(options.Export) + "interface "
                   // name
                   + Name.TransformIf(options.RemoveInterfacePrefix, StringUtilities.RemoveInterfacePrefix)
                   // generic type parameters
                   + ("<" + GenericTypeParameters.ToCommaSepratedList() + ">").If(GenericTypeParameters.Any())
                   // base types
                   + (" extends " + BaseTypes.WriteTypeScript(options, context).ToCommaSepratedList()).If(BaseTypes.Any())
                   // body
                   + " {" + NewLine
                   // fields
                   + Fields.WriteTypeScript(options, context).Indent(options.UseTabs, options.TabSize).LineByLine() + NewLine
                   + "}");
        }
Esempio n. 8
0
 public bool IsOfType(string type)
 {
     return(Classification.Equals(type, StringComparison.OrdinalIgnoreCase) || BaseTypes.Any(b => b.IsOfType(type)));
 }
        protected BaseTypeDeclaration(TypeDesc type, TextBlock container, AccessModifierType accessModifier)
            : base(container, 1)
        {
            Type           = type;
            AccessModifier = accessModifier;

            foreach (string attribute in Attributes)
            {
                WriteBaseLine(() => attribute);
            }
            WriteBaseLine(() => AccessModifier + " " + DeclarationType + " " + TypeName + (BaseTypes.Any() ? " : " + string.Join(", ", BaseTypes) : string.Empty));
        }
Esempio n. 10
0
 /// <summary>
 /// AddBaseTypes
 /// </summary>
 /// <param name="statementSource"></param>
 private string AddBaseTypes(string statementSource)
 {
     //add baseTypes
     if (BaseTypes.Any())
     {
         //check if there are only interfaces and classes in the basetype list
         if (BaseTypes.Any(el => el.ElementType == TsElementTypes.Enumerations))
         {
             throw new Exception(string.Format("Type ({0}) contains baseTypes which are not interface/class", Name));
         }
         //if this element is a class, we need to add the baseType
         if (ElementType == TsElementTypes.Class)
         {
             //if there is more than one baseType which is not an interface, throw exeption, bec we can only extend a single class
             if (BaseTypes.Count(el => el.ElementType == TsElementTypes.Class) > 1)
             {
                 throw new Exception(string.Format("Type ({0}) can only only extend one baseclass", Name));
             }
             //Get baseType
             var baseType = BaseTypes.FirstOrDefault(el => el.ElementType == TsElementTypes.Class);
             if (baseType != null)
             {
                 statementSource = string.Format(TsDomConstants.TS_BASETYPE_EXTENDS_FORMAT, statementSource, baseType.TsTypeName);
             }
             //a class can only implement interfaces
             List <TsCodeTypeReference> implementTypes = BaseTypes.Where(el => el.ElementType == TsElementTypes.Interface).ToList();
             if (implementTypes.Count > 0)
             {
                 var typeStringList = implementTypes.Select(el => el.TsTypeName);
                 //combine types
                 var implementsString = string.Join(TsDomConstants.TS_BASETYPE_SEPERATOR, typeStringList);
                 //combine type
                 statementSource = string.Format(TsDomConstants.TS_BASETYPE_IMPLEMENTS_FORMAT, statementSource,
                                                 implementsString);
             }
         }
         else if (ElementType == TsElementTypes.Interface)
         {
             //interface impelments everything including types and baseTypes
             List <TsCodeTypeReference> implementTypes = BaseTypes.ToList();
             if (implementTypes.Count > 0)
             {
                 var typeStringList = implementTypes.Select(el => el.TsTypeName);
                 //combine types
                 var implementsString = string.Join(TsDomConstants.TS_BASETYPE_SEPERATOR, typeStringList);
                 //combine type
                 statementSource = string.Format(TsDomConstants.TS_BASETYPE_EXTENDS_FORMAT, statementSource, implementsString);
             }
         }
         //if we are using constants add all interface types
         else if (ElementType == TsElementTypes.Constant)
         {
             List <TsCodeTypeReference> implementTypes = BaseTypes.ToList();
             if (implementTypes.Count > 0)
             {
                 var implementsString = string.Join(TsDomConstants.MULTIPLETYPE_SEPERATOR, implementTypes.Select(el => el.Name));
                 //combine type
                 statementSource = string.Format(TsDomConstants.TS_ELEMENT_TYPE_FORMAT, statementSource, implementsString);
             }
         }
     }
     return(statementSource);
 }