Пример #1
0
 public UglyPrettyName GetXukName_()
 {
     if (m_XukName == null)
     {
         m_XukName = GetXukName(GetType());
     }
     return(m_XukName);
 }
        public QualifiedName(UglyPrettyName ln, string nsuri)
        {
            if (ln == null)
            {
                throw new MethodParameterIsNullException("QualifiedName(XukAble.UglyPrettyName ln)");
            }

            LocalName    = ln;
            NamespaceUri = nsuri;
        }
Пример #3
0
        public static string GetXukName(Type type, bool pretty)
        {
            UglyPrettyName xukName = GetXukName(type);

            if (xukName == null)
            {
                return(null);
            }
            return(pretty ? xukName.Pretty : xukName.Ugly);
        }
Пример #4
0
        public string GetXukName()
        {
            UglyPrettyName xukName = GetXukName_();

            if (xukName == null)
            {
                return(null);
            }
            return(PrettyFormat ? xukName.Pretty : xukName.Ugly);
        }
Пример #5
0
        public static string ReadXukAttribute(XmlReader xmlReader, UglyPrettyName name)
        {
            string attrValue = xmlReader.GetAttribute(name.Ugly);

            if (attrValue == null) //string.IsNullOrEmpty(attrValue))
            {
                attrValue = xmlReader.GetAttribute(name.Pretty);
            }
            return(attrValue);
        }
Пример #6
0
        static XukAble()
        {
            Debugger.Break();

            try
            {
                PropertyInfo[] properties = typeof(XukStrings).GetProperties(BindingFlags.Public | BindingFlags.Static);


                DebugFix.Assert(!string.IsNullOrEmpty(XUK_NS));

                List <string> list = new List <string>();

                foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
                {
                    Console.WriteLine(ass.FullName);

                    foreach (Type type in ass.GetTypes())
                    {
                        if (type == typeof(XukAble) || typeof(XukAble).IsAssignableFrom(type))
                        {
                            Console.WriteLine("-----------");
                            Console.WriteLine(type.FullName);


                            Type typeConcrete = type;
                            if (type.ContainsGenericParameters)
                            {
                                DebugFix.Assert(type.IsAbstract);

                                Type[] types = type.GetGenericArguments();
                                DebugFix.Assert(types.Length == 1);

                                typeConcrete = type.MakeGenericType(types[0].BaseType);
                            }

                            FieldInfo[] fields = typeConcrete.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                            foreach (FieldInfo field in fields)
                            {
                                if (field.FieldType != typeof(UglyPrettyName))
                                {
                                    continue;
                                }

                                const string NAME = "_NAME";
                                bool         okay = field.Name.EndsWith(NAME);
                                DebugFix.Assert(okay);
                                if (okay)
                                {
                                    Console.WriteLine(".....");
                                    Console.WriteLine(field.Name);

                                    UglyPrettyName name      = (UglyPrettyName)field.GetValue(typeConcrete);
                                    string         fieldName = field.Name.Substring(0, field.Name.Length - NAME.Length);

                                    Console.WriteLine(fieldName);

                                    PropertyInfo found_ = null;
                                    foreach (PropertyInfo property in properties)
                                    {
                                        if (property.PropertyType == typeof(string) &&
                                            property.Name == fieldName)
                                        {
                                            found_ = property;
                                            break;
                                        }
                                    }

                                    DebugFix.Assert(found_ != null);
                                    if (found_ != null)
                                    {
                                        XukStrings.IsPrettyFormat = false;
                                        string uglyCheck = (string)found_.GetValue(typeof(XukStrings), null);
                                        DebugFix.Assert(name.Ugly == uglyCheck);

                                        Console.WriteLine(uglyCheck);


                                        XukStrings.IsPrettyFormat = true;
                                        string prettyCheck = (string)found_.GetValue(typeof(XukStrings), null);
                                        DebugFix.Assert(name.Pretty == prettyCheck);

                                        Console.WriteLine(prettyCheck);
                                    }
                                    Console.WriteLine(".....");
                                }
                            }

                            string ns = GetXukNamespace(type);
                            DebugFix.Assert(!string.IsNullOrEmpty(ns));

                            if (type == typeof(XukAble))
                            {
                                Console.WriteLine(ns);
                            }

                            if (type.FullName.StartsWith("Obi."))
                            {
                                DebugFix.Assert(ns == "http://www.daisy.org/urakawa/obi");
                            }
                            else
                            {
                                DebugFix.Assert(ns == "http://www.daisy.org/urakawa/xuk/2.0");
                            }

                            if (type.IsAbstract)
                            {
                                Console.WriteLine("abstract");
                                continue;
                            }

                            if (type.FullName.StartsWith("Obi."))
                            {
                                if (!type.FullName.StartsWith("Obi.Commands"))
                                {
                                    string pretty_ = GetXukName(type, true);
                                    string ugly_   = GetXukName(type, false);

                                    DebugFix.Assert(!string.IsNullOrEmpty(pretty_));
                                    DebugFix.Assert(!string.IsNullOrEmpty(ugly_));

                                    DebugFix.Assert(pretty_ == ugly_);

                                    Console.WriteLine(pretty_);

                                    if (type.Name == "ObiPresentation")
                                    {
                                        DebugFix.Assert(pretty_ == type.Name);
                                    }
                                    else if (type.Name == "ObiNode")
                                    {
                                        DebugFix.Assert(pretty_ == type.Name);
                                    }
                                    else if (type.Name == "PhraseNode")
                                    {
                                        DebugFix.Assert(pretty_ == "phrase");
                                    }
                                    else if (type.Name == "SectionNode")
                                    {
                                        DebugFix.Assert(pretty_ == "section");
                                    }
                                    else if (type.Name == "ObiRootNode")
                                    {
                                        DebugFix.Assert(pretty_ == "root");
                                    }
                                    else if (type.Name == "EmptyNode")
                                    {
                                        DebugFix.Assert(pretty_ == "empty");
                                    }
                                    else
                                    {
                                        Debugger.Break();
                                    }
                                }

                                continue;
                            }

                            if (type.Name == "DummyCommand")
                            {
                                continue;
                            }

                            string pretty = GetXukName(type, true);
                            if (!string.IsNullOrEmpty(pretty))
                            {
                                Console.WriteLine(pretty);

                                if (list.Contains(pretty))
                                {
                                    Debugger.Break();
                                }
                                else
                                {
                                    list.Add(pretty);
                                }

                                if (type.Name == "CSSExternalFileData")
                                {
                                    DebugFix.Assert(pretty == "CssExternalFileData");
                                }
                                else if (type.Name == "XSLTExternalFileData")
                                {
                                    DebugFix.Assert(pretty == "XsltExternalFileData");
                                }
                                else if (type.Name == "ExternalFilesDataManager")
                                {
                                    DebugFix.Assert(pretty == "ExternalFileDataManager");
                                }
                                else
                                {
                                    DebugFix.Assert(type.Name == pretty);
                                }
                            }
                            else
                            {
                                Debugger.Break();
                            }


                            string ugly = GetXukName(type, false);
                            if (!string.IsNullOrEmpty(ugly))
                            {
                                Console.WriteLine(ugly);

                                if (list.Contains(ugly))
                                {
                                    Debugger.Break();
                                }
                                else
                                {
                                    list.Add(ugly);
                                }
                            }
                            else
                            {
                                Debugger.Break();
                            }


                            PropertyInfo found = null;
                            foreach (PropertyInfo property in properties)
                            {
                                if (property.PropertyType == typeof(string) &&
                                    (property.Name == type.Name
                                     ||
                                     (type.Name == "ExternalFilesDataManager" &&
                                      property.Name == "ExternalFileDataManager")
                                    ))
                                {
                                    found = property;
                                    break;
                                }
                            }

                            DebugFix.Assert(found != null);
                            if (found != null)
                            {
                                XukStrings.IsPrettyFormat = false;
                                string uglyCheck = (string)found.GetValue(typeof(XukStrings), null);
                                DebugFix.Assert(ugly == uglyCheck);

                                XukStrings.IsPrettyFormat = true;
                                string prettyCheck = (string)found.GetValue(typeof(XukStrings), null);
                                DebugFix.Assert(pretty == prettyCheck);
                            }
                        }
                    }
                }

                // Make sure default is false, to at least open exising projects whilst testing.
                // (for as long as the refactoring goes on to remove dependency on static XukStrings)
                XukStrings.IsPrettyFormat = false;
            }
            catch (Exception ex)
            {
                Debugger.Break();
            }

            Debugger.Break();
        }
Пример #7
0
 public XukNameUglyPrettyAttribute(string ugly, string pretty)
 {
     Name = new UglyPrettyName(ugly, pretty);
 }