Ejemplo n.º 1
0
        public void Process(TypeInfoEx typeInfoEx)
        {
            string declaringTypeName = typeInfoEx.Type.DeclaringType != null ? typeInfoEx.Type.DeclaringType.Name : null;
            string interfaceName = typeInfoEx.Type.Name;
            Block.IncrementLevel();
            using (new Block("export interface " + interfaceName))
            {

                #region interface body
                var allProperties = typeInfoEx.Props.ToList();
                var alreadyProcessed = new Dictionary<string, bool>();
                foreach (var prop in allProperties)
                {
                    if (alreadyProcessed.ContainsKey(prop.PropertyInfo.Name)) continue;
                    alreadyProcessed[prop.PropertyInfo.Name] = true;
                    #region public propert
                    if (prop.Ignore != null) continue;
                    string optional = (prop.Required != null) ? string.Empty : "?";
                    Block.AppendClosingStatement(prop.PropertyInfo.Name + optional + ":" + prop.PropertyInfo.PropertyType.FullQTypeScriptName(typeInfoEx.Type.Namespace) + ";");

                    #endregion
                }

                #endregion
            }
            Block.DecrementLevel();
            typeInfoEx.OutputNamespace = typeInfoEx.Type.Namespace;
            typeInfoEx.OutputContent = Block.Text;
        }
Ejemplo n.º 2
0
        public void Process(TypeInfoEx typeInfoEx)
        {
            string className = typeInfoEx.Type.Name.SubstringAfter("NamesOf");
            Block.IncrementLevel();
            using (new Block("public class " + className))
            {
                //int i = 1;
                typeInfoEx.Type.GetConstants().ToList().ForEach(fieldInfo =>{
                    string stringClassName = fieldInfo.Name + "String";
                    using (new Block("public class " + stringClassName))
                    {
                        Block.AppendClosingStatement("public string Value{get;set;}");
                        using (new Block("public static implicit operator " + stringClassName + "(string stringConstructor)"))
                        {
                            Block.AppendStatement("return new " + stringClassName + "{Value = stringConstructor,}");
                        }
                    }
                    using (new Block("public static " + stringClassName + " " + fieldInfo.Name))
                    {
                        string fieldValue = fieldInfo.GetRawConstantValue().ToString();
                        Block.AppendClosingStatement("get{ return \"" + fieldValue + "\";}");
                    }
                });

            }
            Block.DecrementLevel();
            typeInfoEx.OutputNamespace = typeInfoEx.Type.Namespace;
            typeInfoEx.OutputContent = Block.Text;
        }
Ejemplo n.º 3
0
 public static string GetExtensionMethodsClassNS(TypeInfoEx typeInfoEx, string rootNS)
 {
     string ns = typeInfoEx.Type.Namespace;
     if (rootNS != null)
     {
         string rootNSDot = rootNS + ".";
         if (ns.StartsWith(rootNSDot)) ns = ns.SubstringAfter(rootNSDot);
     }
     return ns + "." + GetExtensionMethodsClassName(typeInfoEx) + "ns";
 }
Ejemplo n.º 4
0
        public void Process(TypeInfoEx typeInfoEx)
        {
            string declaringTypeName = typeInfoEx.Type.DeclaringType != null ? typeInfoEx.Type.DeclaringType.Name : null;
            string originalInterfaceName = typeInfoEx.Type.Name;
            bool isStandardInterfaceName = originalInterfaceName.StartsWith("I")
                && originalInterfaceName.Length > 1
                && originalInterfaceName.Substring(1, 1) == originalInterfaceName.Substring(1, 1).ToUpper();
            string shortClassName = isStandardInterfaceName ? originalInterfaceName.Substring(1) : originalInterfaceName;
            string className = typeInfoEx.ProcessorAttribute.ClassImplementorName ??
                shortClassName + (declaringTypeName == null ?
                    string.Empty : "_" + declaringTypeName);
            if (!isStandardInterfaceName) className += "_defaultImpl";
            Block.IncrementLevel();
            using (new Block("public partial class " + className + " : " + typeInfoEx.Type.FullQCSharpName(typeInfoEx.Type.Namespace)))
            {
                #region look for pass throughs
                var passThroughs = typeInfoEx.Props.Where(prop => prop.PassThrough != null);
                //var passThroughs =  typeInfoEx.Props.Where(prop => prop.PropertyInfo.GetCustomAttribute<PassThroughComponentAttribute>() != null);
                var passThroughLookup = new Dictionary<string, PassThroughInfo>();
                var passThroughsList = passThroughs.ToList();
                passThroughsList.Sort();
                passThroughsList.Reverse();
                passThroughsList.ForEach(propInfoEx =>
                {
                    var passThroughProps = propInfoEx.PropertyInfo.PropertyType.GetPublicProperties();
                    foreach (var passThroughProp in passThroughProps)
                    {
                        if(passThroughs.Any(propInfoEx2 => propInfoEx2.PropertyInfo.Name == passThroughProp.Name)) continue;
                        passThroughLookup[passThroughProp.Name] = new PassThroughInfo
                        {
                            ComponentPassThroughProperty = propInfoEx.PropertyInfo.Name,
                            SubPropertyTypeString = passThroughProp.PropertyType.FullQCSharpName(typeInfoEx.Type.Namespace),
                            PropInfoEx = new PropertyInfoEx
                            {
                                PropertyInfo = passThroughProp,
                            },
                        };
                    }
                });
                #endregion
                #region public partial class
                var allProperties = typeInfoEx.Props.ToList();
                var propertiesWithDefaultValues = new List<PropertyInfoEx>();
                var requiredProperties = new List<PropertyInfoEx>();
                var optionalPropertiesWithNoDefaultValues = new List<PropertyInfoEx>();
                var optionalOrRequiredProperties = new List<PropertyInfoEx>();
                foreach (var kvp in passThroughLookup)
                {
                    using (new Block("public " + kvp.Value.SubPropertyTypeString + " " + kvp.Key))
                    {
                        var propInfo = kvp.Value.PropInfoEx.PropertyInfo;
                        if (propInfo.CanRead)
                        {
                            Block.AppendClosingStatement("get {return this." + kvp.Value.ComponentPassThroughProperty + "." + kvp.Key + ";}");
                        }
                        if (propInfo.CanWrite)
                        {
                            Block.AppendClosingStatement("set{this." + kvp.Value.ComponentPassThroughProperty + "." + kvp.Key + " = this." + kvp.Value.ComponentPassThroughProperty + "." + kvp.Key + ";}");
                        }
                    }
                }
                var alreadyProcessed = new Dictionary<string, bool>();
                foreach (var prop in allProperties)
                {
                    if(passThroughLookup.ContainsKey(prop.PropertyInfo.Name)) continue;
                    if (alreadyProcessed.ContainsKey(prop.PropertyInfo.Name)) continue;
                    alreadyProcessed[prop.PropertyInfo.Name] = true;
                    #region public propert
                    if (prop.Ignore != null) continue;
                    string accessors = "{";
                    if (prop.PropertyInfo.CanRead)
                    {
                        accessors += "get;";
                    }
                    if (prop.PropertyInfo.CanWrite)
                    {
                        accessors += "set;";
                    }
                    accessors += "}";
                    Block.AppendClosingStatement("public " + prop.PropertyInfo.PropertyType.FullQCSharpName(typeInfoEx.Type.Namespace) + " " + prop.PropertyInfo.Name + accessors);
                    if (prop.DefaultValue != null)
                    {
                        propertiesWithDefaultValues.Add(prop);
                    }
                    else if (prop.Required != null)
                    {
                        requiredProperties.Add(prop);
                    }
                    else
                    {
                        optionalPropertiesWithNoDefaultValues.Add(prop);
                    }
                    optionalOrRequiredProperties.Add(prop);
                    #endregion
                }

                var reqParams = requiredProperties.Select(p => p.PropertyInfo.PropertyType.FullQCSharpName(typeInfoEx.Type.Namespace) + " " + p.PropertyInfo.Name);

                var defParams = propertiesWithDefaultValues.Select(p => p.PropertyInfo.PropertyType.FullQCSharpName(typeInfoEx.Type.Namespace) + " " + p.PropertyInfo.Name + " = " +
                    p.DefaultValue.Value.ToCharpValue());
                var optionalParams = optionalPropertiesWithNoDefaultValues.Select(p => p.PropertyInfo.PropertyType.FullQCSharpName(typeInfoEx.Type.Namespace) + " " + p.PropertyInfo.Name + " = " +
                    p.PropertyInfo.PropertyType.ToDefaultCSharpValue());
                var allParams = reqParams.Union(defParams).Union(optionalParams);
                using (new Block("public " + className + "(" + string.Join(", ", allParams.ToArray()) + ")"))
                {
                    foreach (var prop in optionalOrRequiredProperties)
                    {
                        Block.AppendClosingStatement("this." + prop.PropertyInfo.Name + " = " + prop.PropertyInfo.Name + ";");
                    }
                }
                #endregion
            }
            Block.DecrementLevel();
            typeInfoEx.OutputNamespace = typeInfoEx.Type.Namespace;
            typeInfoEx.OutputContent = Block.Text;
        }
Ejemplo n.º 5
0
        public void Process(TypeInfoEx typeInfoEx)
        {
            string className = GetExtensionMethodsClassName(typeInfoEx);
            string ns = GetExtensionMethodsClassNS(typeInfoEx, null);
            Block.IncrementLevel();
            using (new Block("public static class " + className))
            {
                #region static extension class
                Block.AppendStatement("private static " + typeInfoEx.Type.Name + " _this");
                using (new Block("static " + className + "()"))
                {
                    Block.AppendStatement("_this = new " + typeInfoEx.Type.Name + "()");
                }
                var methods = typeInfoEx.Type.GetMethods().Where(method =>{
                    switch(method.Name){
                        case "ToString":
                        case "Equals":
                        case "GetHashCode":
                        case "GetType":
                            return false;
                        default:
                            return true;
                    }

                });
                foreach (var method in methods)
                {
                    var methodParams = method.GetParameters();
                    var incomingArgs =methodParams
                        .Select(pi => pi.ParameterType.FullQCSharpName(ns) + " " + pi.Name
                            //+ (pi.HasDefaultValue ? "=" + pi.DefaultValue : null)
                        )
                        .ToList();

                    var callingArgs = method.GetParameters()
                        .Select(pi => pi.Name)
                        .ToList();
                    int indxOfTargetType = methodParams.Select(pi => pi.ParameterType).ToList().FindIndex(t => t == typeInfoEx.ProcessorAttribute.AssociatedType);
                    if (indxOfTargetType > 0)
                    {
                        incomingArgs.MoveItem(indxOfTargetType, 0);
                        //callingArgs.MoveItem(indxOfTargetType, 0);
                    }
                    else if (indxOfTargetType < 0)
                    {
                        continue;
                    }
                    if (incomingArgs.Count > 0)
                    {
                        incomingArgs[0] = "this " + incomingArgs[0];
                    }
                    string returnTypeString = method.ReturnType.FullQCSharpName(ns);
                    using (new Block("public static " + returnTypeString + " " + method.Name + "(" + string.Join(", ", incomingArgs.ToArray()) + ")"))
                    {
                        Block.AppendStatement((returnTypeString == "void" ? string.Empty : "return ") +  "_this." + method.Name + "(" + string.Join(", ", callingArgs.ToArray()) + ")");
                    }
                }
                #endregion
            }
            Block.AppendClosingStatement("public class " + typeInfoEx.Type.Name + "_Ref{}");
            Block.DecrementLevel();
            typeInfoEx.OutputNamespace = ns;
            typeInfoEx.OutputContent = Block.Text;
        }
Ejemplo n.º 6
0
 public static string GetExtensionMethodsClassName(TypeInfoEx typeInfoEx)
 {
     return typeInfoEx.Type.Name + "_ext";
 }
Ejemplo n.º 7
0
        public void Process(TypeInfoEx typeInfoEx)
        {
            string className = typeInfoEx.Type.Name;
            Block.IncrementLevel();
            var typeToImplement = typeInfoEx.ProcessorAttribute.AssociatedType;
            using (new Block("public partial class " + className + " : " + typeToImplement.FullQCSharpName(typeInfoEx.Type.Namespace)))
            {
                #region public partial class
                var allProperties = typeInfoEx.Props.ToList();
                foreach (var prop in allProperties)
                {
                    #region public property
                    Block.AppendClosingStatement("public " + prop.PropertyInfo.PropertyType.FullName + " " + prop.PropertyInfo.Name + "{get;set;}");
                    #endregion
                }

                #endregion
            }
            Block.DecrementLevel();
            typeInfoEx.OutputNamespace = typeInfoEx.Type.Namespace;
            typeInfoEx.OutputContent = Block.Text;
        }
Ejemplo n.º 8
0
        public void Process(TypeInfoEx typeInfoEx)
        {
            var extType = typeInfoEx.ProcessorAttribute.AssociatedType;
            using (new Block("namespace " + extType.Namespace))
            {
                using (new Block("public static class " + typeInfoEx.Type.Namespace.Replace(".", "_") + typeInfoEx.Type.Name + "Extension"))
                {
                    Block.AppendClosingStatement("public static void Extend(this " + extType.FullQCSharpName(extType.Namespace) + " _this, "
                        + ExtensionMethodsImplementor.GetExtensionMethodsClassNS(typeInfoEx, extType.Namespace) + "." + typeInfoEx.Type.Name + "_Ref" + " Extender){}");

                }
            }
            typeInfoEx.SubProcessorContent += Block.Text;
        }