internal SqlCallInfo(AssemblyInventory inventory, ISerializationTypeInfoProvider serializationTypeInfoProvider, Type interfaceType, ISerializationTypeMappingProvider typeMappingProvider) { if (inventory == null) { throw new ArgumentNullException("inventory"); } if (serializationTypeInfoProvider == null) { throw new ArgumentNullException("serializationTypeInfoProvider"); } Debug.Assert(interfaceType != null); if ((!interfaceType.IsInterface) || (interfaceType.IsGenericTypeDefinition) || (!typeof(IStoredProcedures).IsAssignableFrom(interfaceType))) { throw new ArgumentException("The interface must inherit from IStoredProcedures", "interfaceType"); } this.interfaceType = interfaceType; foreach (Type innerInterface in interfaceType.GetInterfaces()) { if (innerInterface != typeof(IStoredProcedures)) { throw new ArgumentException("The interface cannot inherit from other interfaces then IStoredProcedures", "interfaceType"); } } foreach (MemberInfo memberInfo in interfaceType.GetMembers(BindingFlags.Instance|BindingFlags.Public|BindingFlags.DeclaredOnly)) { MethodInfo methodInfo = memberInfo as MethodInfo; if (methodInfo == null) { throw new ArgumentException("Only methods are supported on the IStoredProcedures interfaces", "interfaceType"); } methods.Add(methodInfo, new SqlCallProcedureInfo(inventory, serializationTypeInfoProvider, methodInfo, typeMappingProvider)); } }
private ModuleAssemblyInfo(Assembly assembly) { this.assembly = assembly; inventory = AssemblyInventory.Get(assembly); using (IEnumerator<GuidAttribute> guidAttributeEnumerator = assembly.GetCustomAttributes(typeof(GuidAttribute), true).Cast<GuidAttribute>().GetEnumerator()) { if (guidAttributeEnumerator.MoveNext()) { GuidAttribute guidAttribute = guidAttributeEnumerator.Current; Debug.Assert(guidAttribute != null); assemblyGuid = new Guid(guidAttribute.Value); } else { Debug.WriteLine(string.Format("Inferring GUID from assembly short name for assembly {0}", assembly.FullName)); using (MD5 md5 = MD5.Create()) { assemblyGuid = new Guid(md5.ComputeHash(Encoding.Unicode.GetBytes(assembly.GetName().Name))); } } } }
public static AssemblyInventory Get(Assembly assembly) { if (assembly == null) { throw new ArgumentNullException("assembly"); } lock (cachedInventories) { AssemblyInventory result; if (!cachedInventories.TryGetValue(assembly, out result)) { result = new AssemblyInventory(new AssemblyHandle(assembly)); cachedInventories.Add(assembly, result); } return result; } }