Exemplo n.º 1
0
        public virtual BooleanValue GetKOSIsType(StringValue queryTypeName)
        {
            // We can't use Reflection's IsAssignableFrom because of the annoying way Generics work under Reflection.

            for (Type t = GetType(); t != null; t = t.BaseType)
            {
                // Our KOSNomenclature mapping can't store a Dictionary mapping for all
                // the new generics types that get made on the fly and weren't present when the static constructor was made.
                // So instead we ask Reflection to get the base from which it came so we can look that up instead.
                if (t.IsGenericType)
                {
                    t = t.GetGenericTypeDefinition();
                }

                if (KOSNomenclature.HasKOSName(t))
                {
                    string kOSname = KOSNomenclature.GetKOSName(t);
                    if (kOSname == queryTypeName)
                    {
                        return(true);
                    }
                    if (t == typeof(Structure))
                    {
                        break; // don't bother walking further up - there won't be any more KOS types above this.
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public virtual StringValue GetKOSInheritance()
        {
            StringBuilder sb = new StringBuilder();

            string prevKosName = "";

            for (Type t = GetType(); t != null; t = t.BaseType)
            {
                // Our KOSNomenclature mapping can't store a Dictionary mapping for all
                // the new generics types that get made on the fly and weren't present when the static constructor was made.
                // So instead we ask Reflection to get the base from which it came so we can look that up instead.
                if (t.IsGenericType)
                {
                    t = t.GetGenericTypeDefinition();
                }

                if (KOSNomenclature.HasKOSName(t))
                {
                    string kOSname = KOSNomenclature.GetKOSName(t);
                    if (kOSname != prevKosName) // skip extra iterations where we mash parent C# types and child C# types into the same KOS type.
                    {
                        if (prevKosName != "")
                        {
                            sb.Append(" derived from ");
                        }
                        sb.Append(kOSname);
                    }
                    prevKosName = kOSname;
                    if (t == typeof(Structure))
                    {
                        break; // don't bother walking further up - there won't be any more KOS types above this.
                    }
                }
            }
            return(sb.ToString());
        }