Beispiel #1
0
        public static NameType TryGetName(TotemType dt, EventInfo ei, MethodInfo eventMethod, out string name)
        {
            name = ei.Name;
            NameType res = dt.IsTotemType ? NameType.TotemEvent : NameType.Event;

            return GetNameFromMethod(dt, eventMethod, res, ref name);
        }
Beispiel #2
0
        public TotemObject(TotemType/*!*/ type)
        {
            Assert.NotNull(type);
            Debug.Assert(type.Handles(GetType()));

            _type = type;
            _context = type.Context;
        }
Beispiel #3
0
        public static NameType TryGetName(TotemType dt, PropertyInfo pi, MethodInfo prop, out string name)
        {
            //if (pi.IsDefined(typeof(TotemHiddenAttribute), false))
            //{
            //    name = null;
            //    return NameType.None;
            //}

            name = pi.Name;

            return GetNameFromMethod(dt, prop, NameType.Property, ref name);
        }
Beispiel #4
0
        internal static NameType GetNameFromMethod(TotemType dt, MethodInfo mi, NameType res, ref string name)
        {
            string namePrefix = null;

            if (mi.IsPrivate || (mi.IsAssembly && !mi.IsFamilyOrAssembly))
            {
                // allow explicitly implemented interface
                if (!(mi.IsPrivate && mi.IsFinal && mi.IsHideBySig && mi.IsVirtual))
                {
                    // mangle protectes to private
                    namePrefix = "_" + dt.Name + "__";
                }
                else
                {
                    // explicitly implemented interface

                    // drop the namespace, leave the interface name, and replace 
                    // the dot with an underscore.  Eg System.IConvertible.ToBoolean
                    // becomes IConvertible_ToBoolean
                    int lastDot = name.LastIndexOf('.');
                    if (lastDot != -1)
                        name = name.Substring(lastDot + 1);
                }
            }

            if (namePrefix != null) name = namePrefix + name;

            if (mi.DeclaringType.GetTypeInfo().IsDefined(typeof(TotemTypeAttribute), false) ||
                !mi.DeclaringType.IsAssignableFrom(dt.UnderlyingSystemType))
            {
                // extension types are all totem names
                res |= NameType.Totem;
            }

            //if (mi.IsDefined(typeof(TotemMethodAttribute), false))
            //{
            //    res = NameType(res & ~NameType.BaseTypeMask) | NameType.Property;
            //}

            return res;
        }
 private static OverloadInfo CreateOverloadInfo(TotemType.MethodOrFunction methodOrFunction)
 {
     if (methodOrFunction.Method != null)
         return new ReflectionOverloadInfo(methodOrFunction.Method);
     else
         throw new NotImplementedException();
 }
Beispiel #6
0
        private Dictionary<string, DynamicProperty> EnsureProperties(TotemType type, Type totemType)
        {
            var ret = EnsureProperties(totemType);
            var staticProps = _staticProperties[totemType];
            foreach (var t in type.ParentTypes)
            {
                Debug.Assert(typeof(TotemType).IsAssignableFrom(t));
                var seed = EnsureProperties(t);
                foreach (var s in seed)
                {
                    if (s.Value.Methods == null || s.Value.Methods.Count == 0)
                        continue;

                    DynamicProperty dp;
                    if (!ret.TryGetValue(s.Key, out dp))
                        dp = ret[s.Key] = new DynamicProperty();

                    dp.CompiledMethods = null;
                    if (dp.Methods == null)
                        dp.Methods = new List<Tuple<MethodInfo, DynamicFlags>>(s.Value.Methods);
                    else
                        dp.Methods = new List<Tuple<MethodInfo, DynamicFlags>>(dp.Methods.Union(s.Value.Methods));

                    if (!staticProps.TryGetValue(s.Key, out dp))
                        dp = staticProps[s.Key] = new DynamicProperty();

                    dp.CompiledMethods = null;
                    if (dp.Methods == null)
                        dp.Methods = new List<Tuple<MethodInfo, DynamicFlags>>(s.Value.Methods);
                    else
                        dp.Methods = new List<Tuple<MethodInfo, DynamicFlags>>(dp.Methods.Union(s.Value.Methods));
                }
            }
            return ret;
        }
Beispiel #7
0
 static void Implement(TotemType target, string name, ITotemCallable callable)
 {
     target.Implement(name, callable);
 }
Beispiel #8
0
        static string ConvertString(TotemType type, object obj)
        {
            ContractUtils.RequiresNotNull(obj, "obj");
            Debug.Assert(type.Handles(obj.GetType()));

            return type.ToString(obj);
        }
Beispiel #9
0
 public MetaObject(TotemType type, Expression expression, BindingRestrictions restrictions, object value)
     : base(expression, restrictions, value)
 {
     _type = type;
 }
Beispiel #10
0
        internal TotemOverload(TotemContext context, TotemType type, string name, Tuple<MethodInfo, TotemType.DynamicFlags>/*!*/[]/*!*/ methodInfos)
            : base(context.GetType<Overloaded>())
        {
            ContractUtils.RequiresNotNull(methodInfos, "methodInfos");
            ContractUtils.RequiresNotNull(name, "name");
            ContractUtils.RequiresNotNull(type, "type");

            _methodInfos = methodInfos;
            _name = name;
            _typeDefinition = type;
        }
Beispiel #11
0
 private int PreArgsCount(TotemType.DynamicFlags flags)
 {
     int count = 0;
     if ((flags & TotemType.DynamicFlags.RequiresType) != 0)
         count++;
     if ((flags & TotemType.DynamicFlags.RequiresContext) != 0)
         count++;
     return count;
 }
Beispiel #12
0
 internal static TotemOverload Create(TotemContext/*!*/ context, TotemType/*!*/ type, string name, Tuple<MethodInfo, TotemType.DynamicFlags>/*!*/[]/*!*/ methodInfos)
 {
     return new TotemOverload(context, type, name, methodInfos);
 }
Beispiel #13
0
        private static ReadOnlyDictionary<TotemOperationKind, ReadOnlyCollection<MethodOrFunction>> GetOperators(TotemType type)
        {
            Debug.Assert(type.IsSystemType, "Should only be called for system types as totem types should populate operators by themselves");
            if(!type.IsTotemType)
                return new ReadOnlyDictionary<TotemOperationKind, ReadOnlyCollection<MethodOrFunction>>(
                    new Dictionary<TotemOperationKind, ReadOnlyCollection<MethodOrFunction>>());

            Dictionary<TotemOperationKind, ReadOnlyCollection<MethodOrFunction>> ops = new Dictionary<TotemOperationKind, ReadOnlyCollection<MethodOrFunction>>();
            var t = TotemBinder.GetProxyType(type.UnderlyingSystemType) ?? type.UnderlyingSystemType;

            var methods = t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly)
                .GroupBy(m => m.Name);
            var names = Enum.GetNames(typeof(TotemOperationKind));

            foreach (var methodGroup in methods)
            {
                var builder = new ReadOnlyCollectionBuilder<MethodOrFunction>();
                foreach (var method in methodGroup)
                {
                    if(method.IsSpecialName)
                        builder.Add(new MethodOrFunction(method));
                }

                if (builder.Count > 0)
                {
                    TotemOperationKind kind;
                    if (Enum.TryParse<TotemOperationKind>(methodGroup.Key, out kind))
                        ops.Add(kind, builder.ToReadOnlyCollection());
                }
            }

            return new ReadOnlyDictionary<TotemOperationKind, ReadOnlyCollection<MethodOrFunction>>(ops);
        }
Beispiel #14
0
        internal static TotemType/*!*/ GetTotemType(Type type)
        {
            object res;

            if (!_totemTypes.TryGetValue(type, out res))
            {
                lock (_totemTypes)
                {
                    if (!_totemTypes.TryGetValue(type, out res))
                    {
                        res = new TotemType(type);

                        _totemTypes.Add(type, res);
                    }
                }
            }

            return (TotemType)res;
        }
Beispiel #15
0
        public static NameType TryGetName(TotemType dt, MethodInfo mi, out string name)
        {
            name = mi.Name;

            return GetNameFromMethod(dt, mi, NameType.Method, ref name);
        }