示例#1
0
        public static string MemberNameOf(this Je.ISysExpander e, LambdaExpression memberSelector)
        {
            if (memberSelector == null)
            {
                return(null);
            }
            var currentExpression = memberSelector.Body;

            while (true)
            {
                switch (currentExpression.NodeType)
                {
                case ExpressionType.ArrayLength: return("Length");

                case ExpressionType.Parameter: return(((ParameterExpression)currentExpression).Name);

                case ExpressionType.Call: return(((MethodCallExpression)currentExpression).Method.Name);

                case ExpressionType.MemberAccess: return(((MemberExpression)currentExpression).Member.Name);

                case ExpressionType.Convert:
                case ExpressionType.ConvertChecked: currentExpression = ((UnaryExpression)currentExpression).Operand; break;

                case ExpressionType.Invoke: currentExpression = ((InvocationExpression)currentExpression).Expression; break;

                default: return(null);
                }
            }
        }
示例#2
0
        public static Type TypeOf(this Je.ISysExpander e, string name)
        {
            string assemblyName, typeName, value;

            ParseMetaName(e, name, out assemblyName, out typeName, out value);
            return(TypeOf(e, assemblyName, typeName));
        }
示例#3
0
        public static void ParseMetaName(this Je.ISysExpander e, string metaName, out string assemblyName, out string typeName, out string value)
        {
            var names = (metaName ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            assemblyName = names.Length > 0 ? names[0] : string.Empty;
            typeName     = names.Length > 1 ? names[1] : string.Empty;
            value        = names.Length > 2 ? names[2] : string.Empty;
        }
示例#4
0
        public static Type GenericOf(this Je.ISysExpander e, Type type)
        {
            var types = type.GetGenericArguments();

            if (types.Length > 0)
            {
                return(types[0]);
            }
            return(type.HasElementType ? type.GetElementType() : null);
        }
示例#5
0
        public static bool IsList(this Je.ISysExpander e, Type type)
        {
            if (type == null)
            {
                return(false);
            }
            var genericType = GenericOf(e, type);

            return(genericType != null && type.GetGenericTypeDefinition() == typeof(List <>) && genericType.IsClass && !typeof(IEnumerable).IsAssignableFrom(genericType));
        }
示例#6
0
 public static string GetResourceValue(this Je.ISysExpander e, ResourceManager resourceManager, string resourceKey)
 {
     try
     {
         return(resourceManager.GetString(resourceKey) ?? string.Empty);
     }
     catch
     {
         return(null);
     }
 }
示例#7
0
        public static string BuildMetaName(this Je.ISysExpander e, object value)
        {
            if (value == null)
            {
                return(string.Empty);
            }
            var type        = value.GetType();
            var stringValue = IsSimple(e, type) ? $", {value.As<string>()}" : string.Empty;

            return($"{BuildMetaName(e, type)}{stringValue}");
        }
示例#8
0
        public static void ParseMetaName(this Je.ISysExpander e, string metaName, out string assemblyName, out string typeName)
        {
            assemblyName = null;
            typeName     = null;
            if (string.IsNullOrWhiteSpace(metaName))
            {
                return;
            }
            var names = metaName.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            assemblyName = names.Length > 0 ? names[0] : null;
            typeName     = names.Length > 1 ? names[1] : null;
        }
示例#9
0
 public static ResourceManager GetResourceManager(this Je.ISysExpander e, string resourceName, string assemblyName)
 {
     try
     {
         var assembly = GetAssembly(e, assemblyName);
         var baseName = $"{assemblyName}.Bases.{resourceName}";
         return(new ResourceManager(baseName, assembly));
     }
     catch
     {
         return(null);
     }
 }
示例#10
0
        public static object InstanceOf(this Je.ISysExpander e, string metaName, object[] args = null)
        {
            string assemblyName, typeName, value;

            ParseMetaName(e, metaName, out assemblyName, out typeName, out value);
            if (string.IsNullOrWhiteSpace(value))
            {
                return(InstanceOf(e, assemblyName, typeName, args));
            }
            var type = TypeOf(e, assemblyName, typeName);

            return(IsSimple(e, type) ? value.As(type) : InstanceOf(e, assemblyName, typeName, args));
        }
示例#11
0
        public static void ParseMetaName(this Je.ISysExpander e, object value, out string assemblyName, out string typeName, out string valueName)
        {
            assemblyName = null;
            typeName     = null;
            valueName    = null;
            if (value == null)
            {
                return;
            }
            var type = value.GetType();

            valueName = value.As <string>();
            ParseMetaName(e, type, out assemblyName, out typeName);
        }
示例#12
0
 public static object InstanceOf(this Je.ISysExpander e, Type type, object[] args = null)
 {
     if (type == null)
     {
         return(null);
     }
     if (type == typeof(string))
     {
         return(Activator.CreateInstance(type, new char[0]));
     }
     if (args == null || args.Length == 0)
     {
         return(Activator.CreateInstance(type, true));
     }
     return(Activator.CreateInstance(type, args));
 }
示例#13
0
 public static void ParseMetaName(this Je.ISysExpander e, Type type, out string assemblyName, out string typeName)
 {
     assemblyName = null;
     typeName     = null;
     if (type == null)
     {
         return;
     }
     if (type.ToString().ToLower().Contains("dynamicmodule"))
     {
         type = type.BaseType;
     }
     if (type == null)
     {
         return;
     }
     assemblyName = Path.GetFileNameWithoutExtension(type.Assembly.Location);
     typeName     = type.ToString();
 }
示例#14
0
 public static T InstanceOf <T>(this Je.ISysExpander e, object[] args = null)
 {
     return((T)InstanceOf(e, typeof(T), args));
 }
示例#15
0
 public static object InstanceOf(this Je.ISysExpander e, string assemblyName, string typeName, object[] args = null)
 {
     return(InstanceOf(e, TypeOf(e, assemblyName, typeName), args));
 }
示例#16
0
 public static T InstanceOf <T>(this Je.ISysExpander e, string assemblyName, string typeName, object[] args = null)
 {
     return((T)InstanceOf(e, assemblyName, typeName, args));
 }
示例#17
0
 public static T InstanceOf <T>(this Je.ISysExpander e, string metaName, object[] args = null)
 {
     return((T)InstanceOf(e, metaName, args));
 }
示例#18
0
 public static bool IsSimple(this Je.ISysExpander e, Type type)
 {
     return(type != null && (type.IsEnum || SimpleTypes.Contains(type)));
 }
示例#19
0
 public static void ParseMetaName <T>(this Je.ISysExpander e, out string assemblyName, out string typeName)
 {
     ParseMetaName(e, typeof(T), out assemblyName, out typeName);
 }
示例#20
0
 public static bool IsTypeOf(this Je.ISysExpander e, Type type, Type sample)
 {
     return(type == sample || type.IsSubclassOf(sample) || type.GetInterfaces().Any(x => x == sample));
 }
示例#21
0
 public static object DefaultOf(this Je.ISysExpander e, Type type)
 {
     return(type.IsValueType ? Activator.CreateInstance(type) : null);
 }
示例#22
0
 public static T DefaultOf <T>(this Je.ISysExpander e)
 {
     return((T)DefaultOf(e, typeof(T)));
 }
示例#23
0
 public static string BuildMetaName(this Je.ISysExpander e, string assemblyName, string typeName)
 {
     return($"{assemblyName}, {typeName}");
 }
示例#24
0
 public static string BuildMetaName(this Je.ISysExpander e, Type type)
 {
     return(type != null ? $"{Path.GetFileNameWithoutExtension(type.Assembly.Location)}, {type}" : string.Empty);
 }
示例#25
0
 public static string BuildMetaName <T>(this Je.ISysExpander e)
 {
     return(BuildMetaName(e, typeof(T)));
 }
示例#26
0
        public static Type TypeOf(this Je.ISysExpander e, string assemblyName, string typeName)
        {
            if (string.IsNullOrWhiteSpace(typeName))
            {
                return(null);
            }
            assemblyName = assemblyName ?? string.Empty;
            typeName     = typeName ?? string.Empty;
            Assembly assembly;
            Type     type;

            if (!string.IsNullOrWhiteSpace(assemblyName))
            {
                assembly = GetAssembly(e, assemblyName);
                if (assembly != null)
                {
                    type = assembly.GetType(typeName, false, true);
                    if (type != null)
                    {
                        return(type);
                    }
                }
            }
            type = Type.GetType(typeName, false, true);
            if (type != null)
            {
                return(type);
            }
            var pos = typeName.Length;

            while (true)
            {
                try
                {
                    pos = typeName.LastIndexOf(".", pos - 1, StringComparison.Ordinal);
                    if (pos < 1)
                    {
                        return(null);
                    }
                    assemblyName = typeName.Substring(0, pos);
                    assembly     = GetAssembly(e, assemblyName);
                    if (assembly == null)
                    {
                        continue;
                    }
                    type = assembly.GetType(typeName);
                    if (type != null)
                    {
                        return(type);
                    }
                    var libraryName = assemblyName + (!assemblyName.EndsWith(".dll") ? ".dll" : string.Empty) + ", ";
                    type = assembly.GetType(typeName.Replace(libraryName, string.Empty));
                    if (type != null)
                    {
                        return(type);
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
示例#27
0
 public static Assembly GetAssembly(this Je.ISysExpander e, string assemblyName)
 {
     return(assemblyName != string.Empty ? LoadAssembly(assemblyName) : null);
 }