示例#1
0
 public void FuzzyFindTree()
 {
     FuzzyDelegate = NDomain.Random().UnsafeFunc <string, int>(BTFTemplate.GetFuzzyPointBTFScript(ScriptDict) + "return default;");
     foreach (var item in Dict)
     {
         Assert.Equal(item.Value, FuzzyDelegate(item.Key));
     }
 }
示例#2
0
 public override string ScriptKeyAction(IDictionary <string, string> dict)
 {
     return(BTFTemplate.GetFuzzyPointBTFScript(dict));
 }
示例#3
0
        public static Type InitType(Type type, FindTreeType kind = FindTreeType.Hash)
        {
            bool isStatic = (type.IsSealed && type.IsAbstract);
            Type callType = typeof(DictBase);


            StringBuilder body  = new StringBuilder();
            var           cache = NBuildInfo.GetInfos(type);

            var setByObjectCache     = new Dictionary <string, string>();
            var getByObjectCache     = new Dictionary <string, string>();
            var getByStrongTypeCache = new Dictionary <string, string>();

            foreach (var item in cache)
            {
                var    info   = item.Value;
                string caller = "Instance";
                if (info != null)
                {
                    if (info.IsStatic)
                    {
                        caller = type.GetDevelopName();
                    }


                    if (info.CanWrite)
                    {
                        setByObjectCache[info.MemberName] = $"{caller}.{info.MemberName} = ({info.MemberTypeName})value;";
                    }

                    if (info.CanRead)
                    {
                        getByObjectCache[info.MemberName]     = $"return {caller}.{info.MemberName};";
                        getByStrongTypeCache[info.MemberName] = $"return (T)(object)({caller}.{info.MemberName});";
                    }
                }
            }

            string setObjectBody     = default;
            string getObjectBody     = default;
            string getStrongTypeBody = default;

            switch (kind)
            {
            case FindTreeType.Fuzzy:
                setObjectBody     = BTFTemplate.GetFuzzyPointBTFScript(setByObjectCache, "name");
                getObjectBody     = BTFTemplate.GetFuzzyPointBTFScript(getByObjectCache, "name");
                getStrongTypeBody = BTFTemplate.GetFuzzyPointBTFScript(getByStrongTypeCache, "name");
                break;

            case FindTreeType.Hash:
                setObjectBody     = BTFTemplate.GetHashBTFScript(setByObjectCache, "name");
                getObjectBody     = BTFTemplate.GetHashBTFScript(getByObjectCache, "name");
                getStrongTypeBody = BTFTemplate.GetHashBTFScript(getByStrongTypeCache, "name");
                break;

            case FindTreeType.Precision:
                setObjectBody     = BTFTemplate.GetGroupPrecisionPointBTFScript(setByObjectCache, "name");
                getObjectBody     = BTFTemplate.GetGroupPrecisionPointBTFScript(getByObjectCache, "name");
                getStrongTypeBody = BTFTemplate.GetGroupPrecisionPointBTFScript(getByStrongTypeCache, "name");
                break;

            default:
                break;
            }


            body.AppendLine("public unsafe override void Set(string name,object value){");
            body.AppendLine(setObjectBody);
            body.Append('}');


            body.AppendLine("public unsafe override T Get<T>(string name){");
            body.AppendLine(getStrongTypeBody);
            body.Append("return default;}");


            body.AppendLine("public unsafe override object GetObject(string name){");
            body.AppendLine(getObjectBody);
            body.Append("return default;}");


            if (!isStatic)
            {
                callType = typeof(DictBase <>).With(type);
                body.Append($@"public override void New(){{ Instance = new {type.GetDevelopName()}();}}");
            }

            Type tempClass = NClass.UseDomain(type.GetDomain())
                             .Public()
                             .Using(type)
                             .Using("System")
                             .Using("NCaller")
                             .UseRandomName()
                             .Namespace("NCallerDynamic")
                             .Inheritance(callType)
                             .Body(body.ToString())
                             .GetType();


            return(tempClass);
        }
示例#4
0
 public static FDC <P, V> operator |(IDictionary <string, string> dict, FDC <P, V> template)
 {
     template.FindContent = BTFTemplate.GetFuzzyPointBTFScript(dict);
     return(template);
 }