Beispiel #1
0
        public Define(MethodInfo method, string name = null)
            : base(name ?? method.Name, method.ReturnType)
        {
            IsStatic = method.IsStatic;
            var pars = method.GetParameters();

            foreach (var p in pars)
            {
                Params.Add(new Param(p));
            }
            if (IsStatic && method.IsDefined(typeof(ExtensionAttribute)))
            {
                var    type    = TypeIndex.FromSystemType(pars[0].ParameterType);
                var    ns      = Namespace.FromString(type.Namespace);
                var    etype   = ns.GetExtype(type.Name, true);
                Method emethod = null;
                if (etype.Methods.ContainsKey(Name))
                {
                    emethod = etype.Methods[Name];
                }
                else
                {
                    emethod = new Method(Name);
                    etype.Methods.Add(emethod);
                }

                var define =
                    new Define
                {
                    Name          = Name,
                    TypeIndex     = TypeIndex.FromSystemType(method.ReturnType),
                    IsExtension   = true,
                    DeclaringType = method.DeclaringType.FullName,
                };

                for (int i = 1; i < pars.Length; i++)
                {
                    define.Params.Add(new Param(pars[i]));
                }
                emethod.AddDefine(define);
            }
        }
Beispiel #2
0
        public void AddDefine(Define define)
        {
            int i   = 0;
            int num = define.Params.Count;

            foreach (var cdefine in Defines.Where(d => d.Params.Count == num))
            {
                bool b = true;
                for (int j = 0; j < num; j++)
                {
                    if (!define.Params[j].TypeIndex.Equals(cdefine.Params[j].TypeIndex))
                    {
                        b = false;
                        break;
                    }
                }
                //找到定义相同的扩展就直接退出
                if (b)
                {
                    return;
                }
            }
            Defines.Insert(i, define);
        }