Пример #1
0
 static Action<IDbCommand, bool> GetBindByName(Type commandType)
 {
     if (commandType == null) return null; // GIGO
     Action<IDbCommand, bool> action;
     if (Link<Type, Action<IDbCommand, bool>>.TryGet(bindByNameCache, commandType, out action))
     {
         return action;
     }
     var prop = commandType.GetProperty("BindByName", BindingFlags.Public | BindingFlags.Instance);
     action = null;
     ParameterInfo[] indexers;
     MethodInfo setter;
     if (prop != null && prop.CanWrite && prop.PropertyType == typeof(bool)
         && ((indexers = prop.GetIndexParameters()) == null || indexers.Length == 0)
         && (setter = prop.GetSetMethod()) != null
         )
     {
         var method = new DynamicMethod(commandType.GetComplexTypeName() + "_BindByName", null, new Type[] { typeof(IDbCommand), typeof(bool) });
         var il = method.GetILGenerator();
         il.Emit(OpCodes.Ldarg_0);
         il.Emit(OpCodes.Castclass, commandType);
         il.Emit(OpCodes.Ldarg_1);
         il.EmitCall(OpCodes.Callvirt, setter, null);
         il.Emit(OpCodes.Ret);
         action = (Action<IDbCommand, bool>)method.CreateDelegate(typeof(Action<IDbCommand, bool>));
     }
     // cache it            
     Link<Type, Action<IDbCommand, bool>>.TryAdd(ref bindByNameCache, commandType, ref action);
     return action;
 }
Пример #2
0
        public Message EmptyResponse(Message requestMsg, Type requestType)
        {
            var responseType = AssemblyUtils.FindType(requestType.FullName + "Response");
            var response = (responseType ?? typeof(object)).CreateInstance();

            return requestMsg.Headers.Action == null
                ? Message.CreateMessage(requestMsg.Version, null, response)
                : Message.CreateMessage(requestMsg.Version, requestType.GetComplexTypeName() + "Response", response);
        }
        public static void WithMatchingPropertyNames(IServiceRoutes routes, Type requestType, string allowedVerbs)
        {
            var membersWithName = (from property in requestType.GetPublicProperties().Select(p => p.Name)
                                   from name in PropertyNamesToMatch
                                   where property.Equals(name, StringComparison.InvariantCultureIgnoreCase)
                                   select "{{{0}}}".Fmt(property)).ToList();

            if (membersWithName.Count == 0) return;

            membersWithName.Insert(0, "/{0}".Fmt(requestType.GetComplexTypeName()));

            var restPath = membersWithName.Join("/");
            routes.Add(requestType, restPath: restPath, verbs: allowedVerbs, priority: AutoGenPriority);
        }
        public static void WithMatchingAttributes(IServiceRoutes routes, Type requestType, string allowedVerbs)
        {
            var membersWithAttribute = (from p in requestType.GetPublicProperties()
                                        let attributes = p.AllAttributes<Attribute>()
                                        where attributes.Any(a => AttributeNamesToMatch.Contains(a.GetType().GetComplexTypeName()))
                                        select "{{{0}}}".Fmt(p.Name)).ToList();

            if (membersWithAttribute.Count == 0) return;

            membersWithAttribute.Insert(0, "/{0}".Fmt(requestType.GetComplexTypeName()));

            var restPath = membersWithAttribute.Join("/");
            routes.Add(requestType, restPath: restPath, verbs: allowedVerbs, priority: AutoGenPriority);
        }
		protected override string CreateMessage(Type dtoType)
		{
			try
			{
				var requestObj = AutoMappingUtils.PopulateWith(Activator.CreateInstance(dtoType));

				using (var ms = new MemoryStream())
				{
					HostContext.ContentTypes.SerializeToStream(
                        new BasicRequest { ContentType = this.ContentType }, requestObj, ms);

					return Encoding.UTF8.GetString(ms.ToArray());
				}
			}
			catch (Exception ex)
			{
				var error = string.Format("Error serializing type '{0}' with custom format '{1}'",
					dtoType.GetComplexTypeName(), this.ContentFormat);
				Log.Error(error, ex);

				return string.Format("{{Unable to show example output for type '{0}' using the custom '{1}' filter}}" + ex.Message,
					dtoType.GetComplexTypeName(), this.ContentFormat);
			}
		}
Пример #6
0
        /// <summary>
        /// Gets the name of the base most type in the heirachy tree with the same.
        /// 
        /// We get an exception when trying to create a schema with multiple types of the same name
        /// like when inheriting from a DataContract with the same name.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static Type GetBaseTypeWithTheSameName(Type type)
        {
            var typesWithSameName = new Stack<Type>();
            var baseType = type;
            do
            {
                if (baseType.GetComplexTypeName() == type.GetComplexTypeName())
                    typesWithSameName.Push(baseType);
            }
            while ((baseType = baseType.BaseType) != null);

            return typesWithSameName.Pop();
        }
 public static void WithRequestDtoName(IServiceRoutes routes, Type requestType, string allowedVerbs)
 {
     routes.Add(requestType, restPath: "/{0}".Fmt(requestType.GetComplexTypeName()), verbs: allowedVerbs, priority:AutoGenPriority);
 }
Пример #8
0
 public ExecOnceOnly(IRedisClientsManager redisManager, Type forType, Guid? correlationId)
     : this(redisManager, "hash:nx:" + forType.GetComplexTypeName(), (correlationId.HasValue ? correlationId.Value.ToString("N") : null)) { }
Пример #9
0
 public ExecOnceOnly(IRedisClientsManager redisManager, Type forType, string correlationId)
     : this(redisManager, "hash:nx:" + forType.GetComplexTypeName(), correlationId) { }