本文整理汇总了C#中IMappingOptions类的典型用法代码示例。如果您正苦于以下问题:C# IMappingOptions类的具体用法?C# IMappingOptions怎么用?C# IMappingOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMappingOptions类属于命名空间,在下文中一共展示了IMappingOptions类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapDestinationCtorToSource
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeInfo sourceTypeInfo,
IMappingOptions options)
{
var parameters = new List<ConstructorParameterMap>();
var ctorParameters = destCtor.GetParameters();
if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
return false;
foreach (var parameter in ctorParameters)
{
var members = new LinkedList<MemberInfo>();
if (!MapDestinationPropertyToSource(members, sourceTypeInfo, parameter.Name, options))
return false;
var resolvers = members.Select(mi => mi.ToMemberGetter());
var param = new ConstructorParameterMap(parameter, resolvers.ToArray());
parameters.Add(param);
}
typeMap.AddConstructorMap(destCtor, parameters);
return true;
}
示例2: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options,
MemberList memberList)
{
var sourceTypeInfo = GetTypeInfo(sourceType, options);
var destTypeInfo = GetTypeInfo(destinationType, options.ShouldMapProperty, options.ShouldMapField, new MethodInfo[0]);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList);
foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
{
var members = new LinkedList<MemberInfo>();
if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
{
var resolvers = members.Select(mi => mi.ToMemberGetter());
var destPropertyAccessor = destProperty.ToMemberAccessor();
typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
}
}
if (!destinationType.IsAbstract() && destinationType.IsClass())
{
foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
{
if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
{
break;
}
}
}
return typeMap;
}
示例3: FindTypeMember
private static MemberInfo FindTypeMember(IEnumerable<MemberInfo> modelProperties, IEnumerable<MethodInfo> getMethods, string nameToSearch, IMappingOptions mappingOptions)
{
MemberInfo pi = modelProperties.FirstOrDefault(prop => NameMatches(prop.Name, nameToSearch));
if (pi != null)
return pi;
MethodInfo mi = getMethods.FirstOrDefault(m => NameMatches(m.Name, nameToSearch));
if (mi != null)
return mi;
pi = modelProperties.FirstOrDefault(prop => NameMatches(mappingOptions.SourceMemberNameTransformer(prop.Name), nameToSearch));
if (pi != null)
return pi;
mi = getMethods.FirstOrDefault(m => NameMatches(mappingOptions.SourceMemberNameTransformer(m.Name), nameToSearch));
if (mi != null)
return mi;
pi = modelProperties.FirstOrDefault(prop => NameMatches(prop.Name, mappingOptions.DestinationMemberNameTransformer(nameToSearch)));
if (pi != null)
return pi;
pi = getMethods.FirstOrDefault(m => NameMatches(m.Name, mappingOptions.DestinationMemberNameTransformer(nameToSearch)));
if (pi != null)
return pi;
return null;
}
示例4: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
{
var sourceTypeInfo = GetTypeInfo(sourceType);
var destTypeInfo = GetTypeInfo(destinationType);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);
foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
{
var members = new LinkedList<MemberInfo>();
if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
{
var resolvers = members.Select(mi => mi.ToMemberGetter());
var destPropertyAccessor = destProperty.ToMemberAccessor();
#if !SILVERLIGHT
typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
#else
typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
#endif
}
}
if (!destinationType.IsAbstract && destinationType.IsClass)
{
foreach (var destCtor in destTypeInfo.GetConstructors().OrderByDescending(ci => ci.GetParameters().Length))
{
if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
{
break;
}
}
}
return typeMap;
}
示例5: CreateNameSnippet
private NameSnippet CreateNameSnippet(IEnumerable<string> matches, int i, IMappingOptions mappingOptions)
{
return new NameSnippet
{
First = String.Join(mappingOptions.SourceMemberNamingConvention.SeparatorCharacter, matches.Take(i).ToArray()),
Second = String.Join(mappingOptions.SourceMemberNamingConvention.SeparatorCharacter, matches.Skip(i).ToArray())
};
}
示例6: MapDestinationPropertyToSource
private bool MapDestinationPropertyToSource(LinkedList<MemberInfo> resolvers, TypeInfo sourceType,
string nameToSearch, IMappingOptions mappingOptions)
{
if (string.IsNullOrEmpty(nameToSearch))
return true;
var sourceProperties = sourceType.GetPublicReadAccessors();
var sourceNoArgMethods = sourceType.GetPublicNoArgMethods();
var sourceNoArgExtensionMethods = sourceType.GetPublicNoArgExtensionMethods();
MemberInfo resolver = FindTypeMember(sourceProperties, sourceNoArgMethods, sourceNoArgExtensionMethods, nameToSearch, mappingOptions);
bool foundMatch = resolver != null;
if (foundMatch)
{
resolvers.AddLast(resolver);
}
else
{
string[] matches = mappingOptions.DestinationMemberNamingConvention.SplittingExpression
.Matches(nameToSearch)
.Cast<Match>()
.Select(m => m.Value)
.ToArray();
for (int i = 1; (i <= matches.Length) && (!foundMatch); i++)
{
NameSnippet snippet = CreateNameSnippet(matches, i, mappingOptions);
var valueResolver = FindTypeMember(sourceProperties, sourceNoArgMethods, sourceNoArgExtensionMethods, snippet.First,
mappingOptions);
if (valueResolver != null)
{
resolvers.AddLast(valueResolver);
foundMatch = MapDestinationPropertyToSource(resolvers,
GetTypeInfo(valueResolver.GetMemberType(), mappingOptions.SourceExtensionMethods),
snippet.Second, mappingOptions);
if (!foundMatch)
{
resolvers.RemoveLast();
}
}
}
}
return foundMatch;
}
示例7: NameMatches
private static bool NameMatches(string memberName, string nameToMatch, IMappingOptions mappingOptions)
{
var possibleSourceNames = PossibleNames(memberName, mappingOptions.Aliases, mappingOptions.Prefixes,
mappingOptions.Postfixes);
var possibleDestNames = PossibleNames(nameToMatch, mappingOptions.Aliases, mappingOptions.DestinationPrefixes,
mappingOptions.DestinationPostfixes);
var all =
from sourceName in possibleSourceNames
from destName in possibleDestNames
select new {sourceName, destName};
return all.Any(pair => String.Compare(pair.sourceName, pair.destName, StringComparison.OrdinalIgnoreCase) == 0);
}
示例8: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
{
var sourceTypeInfo = GetTypeInfo(sourceType);
var destTypeInfo = GetTypeInfo(destinationType);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);
foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
{
var members = new LinkedList<MemberInfo>();
if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
{
var resolvers = members.Select(mi => mi.ToMemberGetter()).Cast<IValueResolver>();
var destPropertyAccessor = destProperty.ToMemberAccessor();
typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
}
}
return typeMap;
}
示例9: FindTypeMember
private static MemberInfo FindTypeMember(IEnumerable<MemberInfo> modelProperties,
IEnumerable<MethodInfo> getMethods,
IEnumerable<MethodInfo> getExtensionMethods,
string nameToSearch,
IMappingOptions mappingOptions)
{
var pi = modelProperties.FirstOrDefault(prop => NameMatches(prop.Name, nameToSearch, mappingOptions));
if (pi != null)
return pi;
var mi = getMethods.FirstOrDefault(m => NameMatches(m.Name, nameToSearch, mappingOptions));
if (mi != null)
return mi;
mi = getExtensionMethods.FirstOrDefault(m => NameMatches(m.Name, nameToSearch, mappingOptions));
if (mi != null)
return mi;
return null;
}
示例10: GetTypeInfo
private TypeInfo GetTypeInfo(Type type, IMappingOptions mappingOptions)
{
return GetTypeInfo(type, mappingOptions.ShouldMapProperty, mappingOptions.ShouldMapField, mappingOptions.SourceExtensionMethods);
}
示例11: Establish_context
protected override void Establish_context()
{
INamingConvention namingConvention = CreateStub<INamingConvention>();
namingConvention.Stub(nc => nc.SeparatorCharacter).Return("__");
_mappingOptions = CreateStub<IMappingOptions>();
_mappingOptions.SourceMemberNamingConvention = namingConvention;
_mappingOptions.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
_mappingOptions.SourceMemberNameTransformer = s => s;
_mappingOptions.DestinationMemberNameTransformer = s => s;
_factory = new TypeMapFactory();
}
示例12: GetTypeInfo
private TypeInfo GetTypeInfo(Type type, IEnumerable<MethodInfo> extensionMethodsToSearch, IMappingOptions mappingOptions)
{
TypeInfo typeInfo = _typeInfos.GetOrAdd(type, t => new TypeInfo(type, mappingOptions.BindingFlags, extensionMethodsToSearch));
return typeInfo;
}
示例13: CreateNameSnippet
private NameSnippet CreateNameSnippet(IEnumerable<string> matches, int i, IMappingOptions mappingOptions)
{
return new NameSnippet
{
First =
string.Join("", matches.Take(i).ToArray()),
Second =
string.Join("", matches.Skip(i).ToArray())
};
}
示例14: Establish_context
protected override void Establish_context()
{
var namingConvention = new StubNamingConvention();
namingConvention.SplittingExpression = new Regex(@"[\p{Ll}0-9]*(?=_?)");
_mappingOptions = new StubMappingOptions();
_mappingOptions.SourceMemberNamingConvention = new PascalCaseNamingConvention();
_mappingOptions.DestinationMemberNamingConvention = namingConvention;
_factory = new TypeMapFactory();
}