예제 #1
0
        public static object ChangeToCompatibleType(object value, Type destinationType)
        {
            Enforce.ArgumentNotNull(destinationType, "destinationType");

            if (value == null)
            {
                if (destinationType.IsValueType)
                {
                    return(Activator.CreateInstance(destinationType));
                }

                return(null);
            }

            if (destinationType.IsAssignableFrom(value.GetType()))
            {
                return(value);
            }

            return(TypeDescriptor.GetConverter(destinationType).ConvertFrom(value));
        }
예제 #2
0
        public static Type FindGreatestCommonType(Type type, Type commonType)
        {
            Enforce.ArgumentNotNull <Type>(type, "type");
            Enforce.ArgumentNotNull <Type>(commonType, "commonType");

            if (type == typeof(object) || commonType == typeof(object))
            {
                return(typeof(object));
            }

            if (type == commonType || commonType.IsAssignableFrom(type))
            {
                return(commonType);
            }
            else if (type.IsAssignableFrom(commonType))
            {
                return(type);
            }
            else
            {
                Type candidate = FindGreatestCommonTypeInHierarchyUpwards(type, commonType);
                if (candidate != typeof(object) && candidate.IsAssignableFrom(commonType))
                {
                    return(candidate);
                }
                else
                {
                    Type[] commonTypeInterfaces = commonType.GetInterfaces();
                    foreach (Type typeInterface in commonTypeInterfaces)
                    {
                        if (typeInterface.IsAssignableFrom(type))
                        {
                            candidate = typeInterface;
                        }
                    }
                    return(candidate);
                }
            }
        }
 public ExtensionXmlSchema(XmlSchema schema)
     : this()
 {
     _schema = Enforce.ArgumentNotNull <XmlSchema>(schema, "schema");
 }
예제 #4
0
 protected ConstantParameter(object value, Predicate <ParameterInfo> predicate)
 {
     _value     = value;
     _predicate = Enforce.ArgumentNotNull(predicate, "predicate");
 }
예제 #5
0
 public NamedParameter(string name, object value)
     : base(value, delegate(ParameterInfo pi) { return(pi.Name == name); })
 {
     _name = Enforce.ArgumentNotNullOrEmpty(name, "name");
 }
        public static T TypedAs <T>(ICollection <IParameter> parameters)
        {
            Enforce.ArgumentNotNull(parameters, "parameters");

            return(ConstantValue <TypedParameter, T>(parameters, delegate(TypedParameter c) { return c.Type == typeof(T); }));
        }
예제 #7
0
 public ServiceAttribute(string nm, Type serviceInterface)
 {
     _name             = nm;
     _serviceInterface = Enforce.ArgumentNotNull <Type>(serviceInterface, "serviceInterface");
 }
예제 #8
0
 public ObjectMapper(object instance)
 {
     _instance     = Enforce.ArgumentNotNull(instance, "instance");
     _instanceType = _instance.GetType();
 }
예제 #9
0
 public TypedParameter(Type type, object value)
     : base(value, delegate(ParameterInfo pi){ return(pi.ParameterType == type); })
 {
     _type = Enforce.ArgumentNotNull(type, "type");
 }
 public NamedPropertyParameter(string name, object value)
     : base(value, delegate(ParameterInfo parameterInfo)
            { return(parameterInfo.Member.Name.Replace("set_", "") == name); })
 {
     _name = Enforce.ArgumentNotNullOrEmpty(name, "name");
 }
예제 #11
0
 public MicroKernel(IServiceProvider parent)
     : this()
 {
     _parent        = Enforce.ArgumentNotNull(parent, "parent");
     _getMethodInfo = _parent.GetType().GetMethod("GetService", new Type[] { typeof(string) });
 }
예제 #12
0
 public ServiceKey(Type key)
 {
     typeKey = Enforce.ArgumentNotNull(key, "key");
 }
예제 #13
0
 public ServiceKey(string key)
 {
     stringKey = Enforce.ArgumentNotNullOrEmpty(key, "key");
 }