public void Reflect()
        {
            if (reflectionData != null)
            {
                return;
            }

            reflectionData = new Dictionary <string, MyFieldInfo>();
            HashSet <string> names = new HashSet <string>();

            foreach (var fi in GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                var mfi = new MyFieldInfo();
                mfi.FieldInfo = fi;

                var lower = mfi.FieldInfo.Name.ToLowerInvariant();

                if (names.Contains(lower))
                {
                    Console.WriteLine("Duplicate field name on ConfigFile. We're working case insensitive here, so dont use `Foo` and `foo` both");
                    continue;
                }

                names.Add(lower);

                if (fi.FieldType == typeof(int))
                {
                    mfi.Type = FieldType.Int32;
                }
                if (fi.FieldType == typeof(string))
                {
                    mfi.Type = FieldType.String;
                }
                if (fi.FieldType == typeof(float))
                {
                    mfi.Type = FieldType.Float;
                }

                reflectionData[fi.Name] = mfi;
            }
        }
Exemple #2
0
        internal MetaClass FindMember(string xmlMemberId)
        {
            char memberType = xmlMemberId[0];

            xmlMemberId = xmlMemberId.Substring(2);

            switch (memberType)
            {
            case 'T':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyClassInfo myClassInfo = myAssemblyInfo.FindNamespaceMember(xmlMemberId);

                    if (myClassInfo != null)
                    {
                        return(myClassInfo);
                    }
                }

                break;
            }

            case 'M':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyInvokableMemberInfo myInvokableMemberInfo = myAssemblyInfo.FindMethodOrConstructor(xmlMemberId, true);

                    if (myInvokableMemberInfo != null)
                    {
                        return(myInvokableMemberInfo);
                    }
                }

                break;
            }

            case 'F':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyFieldInfo myFieldInfo = myAssemblyInfo.FindField(xmlMemberId, true);

                    if (myFieldInfo != null)
                    {
                        return(myFieldInfo);
                    }
                }

                break;
            }

            case 'P':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyPropertyInfo myPropertyInfo = myAssemblyInfo.FindProperty(xmlMemberId, true);

                    if (myPropertyInfo != null)
                    {
                        return(myPropertyInfo);
                    }
                }

                break;
            }

            case 'E':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyEventInfo myEventInfo = myAssemblyInfo.FindEvent(xmlMemberId, true);

                    if (myEventInfo != null)
                    {
                        return(myEventInfo);
                    }
                }

                break;
            }

            case 'N':
            {
                foreach (MyAssemblyInfo myAssemblyInfo in assemblies.Values)
                {
                    MyNamespaceInfo myNamespaceInfo = myAssemblyInfo.FindNamespace(xmlMemberId);

                    if (myNamespaceInfo != null)
                    {
                        return(myNamespaceInfo);
                    }
                }

                break;
            }
            }

            return(null);
        }
Exemple #3
0
 public RecordFieldSerializer(ObjectSerializerBase schema, MyFieldInfo info)
 {
     this.Schema     = schema;
     this.MemberInfo = info;
 }
        private MyList <MyTypeInfo> yamlTypes2CSharpTypes(string swagger_yaml)
        {
            var input = new StringReader(swagger_yaml);

            var yaml = new YamlStream();

            yaml.Load(input);

            var root = (YamlMappingNode)yaml.Documents[0].RootNode;

            var definitions = (YamlMappingNode)root.Children[new YamlScalarNode("definitions")];


            MyList <MyTypeInfo> classes = new MyList <MyTypeInfo>();



            foreach (var entry in definitions.Children)
            {
                MyTypeInfo classdef = new MyTypeInfo(entry.Key.ToString(), "RemoteTypes", new MyTypeInfo(typeof(DatabaseTable)));
                classdef.AddAttribute(new JsonObjectAttribute(MemberSerialization.Fields));
                classes.Add(classdef);
            }

            foreach (var entry in definitions.Children)
            {
                MyTypeInfo classdef = classes.Find(c => c.Name == entry.Key.ToString().Trim());


                var props = (YamlMappingNode)((YamlMappingNode)entry.Value).Children[new YamlScalarNode("properties")];

                int counter = 0;

                foreach (var prop in props.Children)
                {
                    MyTypeInfo fieldtype = null;
                    bool       ismylist  = false;

                    string fieldname = prop.Key.ToString().Trim();

                    Mapping mapping = null;

                    Details details = null;


                    if (((YamlMappingNode)prop.Value).Children.ContainsKey(new YamlScalarNode("$ref")))
                    {
                        string yamlref = ((YamlScalarNode)((YamlMappingNode)prop.Value).Children[new YamlScalarNode("$ref")]).Value;


                        fieldtype = classes.Find(c => c.Name == yamlref.getTextAfterLast("/").Trim());


                        mapping = new Mapping(fieldtype.GetFieldWithAttribute(new ID()).Name);
                    }
                    else
                    {
                        var type = (YamlScalarNode)((YamlMappingNode)prop.Value).Children[new YamlScalarNode("type")];

                        if (type.Value == "array")
                        {
                            var items = (YamlMappingNode)((YamlMappingNode)prop.Value).Children[new YamlScalarNode("items")];


                            if (items.Children.ContainsKey(new YamlScalarNode("$ref")))
                            {
                                string yamlref = ((YamlScalarNode)items.Children[new YamlScalarNode("$ref")]).Value;


                                fieldtype = classes.Find(c => c.Name == yamlref.getTextAfterLast("/"));
                                ismylist  = true;

                                var det_id = new MyFieldInfo(typeof(int), classdef.Name + "_id");
                                det_id.AddAttribute(new Details());
                                fieldtype.AddField(det_id);
                                det_id.AddAttribute(new JsonIgnoreAttribute());

                                details = new Details();
                            }
                            else
                            {
                                var type2 = (YamlScalarNode)items.Children[new YamlScalarNode("type")];


                                ismylist = true;

                                MyTypeInfo  newtable    = new MyTypeInfo(fieldname + "_table", "RemoteTypes", new MyTypeInfo(typeof(DatabaseTable)));
                                MyFieldInfo newtable_id = new MyFieldInfo(typeof(int), fieldname + "_id");
                                newtable_id.AddAttribute(new ID());
                                newtable.AddField(newtable_id);

                                MyFieldInfo newtable_ref = new MyFieldInfo(typeof(int), classdef.Name + "_id");
                                newtable.AddField(newtable_ref);
                                newtable_ref.AddAttribute(new Details());
                                newtable_ref.AddAttribute(new Mapping(classdef.GetFieldWithAttribute(new ID()).Name));


                                MyFieldInfo newtable_value = new MyFieldInfo(swaggerType2CSharpType(type2.Value), fieldname);
                                newtable.AddField(newtable_value);

                                classes.Add(newtable);

                                fieldtype = newtable;
                            }
                        }
                        else
                        {
                            fieldtype = new MyTypeInfo(swaggerType2CSharpType(type.Value));
                        }
                    }



                    MyFieldInfo fi = new MyFieldInfo(fieldtype, fieldname, ismylist);
                    counter++;

                    if (counter == 1)
                    {
                        fi.AddAttribute(new ID());
                    }

                    if (fieldtype.internalType != null && fieldtype.internalType.Equals(typeof(string)))
                    {
                        fi.AddAttribute(new NullableString());
                    }

                    if (mapping != null)
                    {
                        fi.AddAttribute(mapping);
                    }

                    if (details != null)
                    {
                        fi.AddAttribute(details);
                    }


                    classdef.AddField(fi);
                }
            }



            return(classes);
        }